@stablelib/ctr
Advanced tools
Comparing version 1.0.2 to 2.0.0
// Copyright (C) 2016 Dmitry Chestnykh | ||
// MIT License. See LICENSE file for details. | ||
import { describe, expect, it } from 'vitest'; | ||
import { AES } from "@stablelib/aes"; | ||
@@ -5,0 +6,0 @@ import { encode, decode } from "@stablelib/hex"; |
@@ -8,3 +8,3 @@ // Copyright (C) 2016 Dmitry Chestnykh | ||
import { BlockCipher } from "@stablelib/blockcipher"; | ||
import type { BlockCipher } from "@stablelib/blockcipher"; | ||
import { wipe } from "@stablelib/wipe"; | ||
@@ -11,0 +11,0 @@ |
@@ -1,16 +0,14 @@ | ||
"use strict"; | ||
// Copyright (C) 2016 Dmitry Chestnykh | ||
// MIT License. See LICENSE file for details. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const aes_1 = require("@stablelib/aes"); | ||
const benchmark_1 = require("@stablelib/benchmark"); | ||
const ctr_1 = require("./ctr"); | ||
const buf8192 = (0, benchmark_1.byteSeq)(8192); | ||
const buf1111 = (0, benchmark_1.byteSeq)(1111); | ||
const key = (0, benchmark_1.byteSeq)(32); | ||
import { AES } from "@stablelib/aes"; | ||
import { benchmark, report, byteSeq } from "@stablelib/benchmark"; | ||
import { CTR } from "./ctr"; | ||
const buf8192 = byteSeq(8192); | ||
const buf1111 = byteSeq(1111); | ||
const key = byteSeq(32); | ||
const iv = new Uint8Array(16); | ||
const cipher = new aes_1.AES(key); | ||
const ctr = new ctr_1.CTR(cipher, iv); | ||
(0, benchmark_1.report)("AES-CTR 8K", (0, benchmark_1.benchmark)(() => ctr.streamXOR(buf8192, buf8192), buf8192.length)); | ||
(0, benchmark_1.report)("AES-CTR 1111", (0, benchmark_1.benchmark)(() => ctr.streamXOR(buf1111, buf1111), buf1111.length)); | ||
const cipher = new AES(key); | ||
const ctr = new CTR(cipher, iv); | ||
report("AES-CTR 8K", benchmark(() => ctr.streamXOR(buf8192, buf8192), buf8192.length)); | ||
report("AES-CTR 1111", benchmark(() => ctr.streamXOR(buf1111, buf1111), buf1111.length)); | ||
//# sourceMappingURL=ctr.bench.js.map |
/** | ||
* Package ctr implements counter cipher mode for block ciphers. | ||
*/ | ||
import { BlockCipher } from "@stablelib/blockcipher"; | ||
import type { BlockCipher } from "@stablelib/blockcipher"; | ||
/** | ||
@@ -6,0 +6,0 @@ * CTR implements counter cipher mode. |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
// Copyright (C) 2016 Dmitry Chestnykh | ||
// MIT License. See LICENSE file for details. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CTR = void 0; | ||
const wipe_1 = require("@stablelib/wipe"); | ||
import { wipe } from "@stablelib/wipe"; | ||
/** | ||
@@ -13,5 +10,8 @@ * CTR implements counter cipher mode. | ||
*/ | ||
class CTR { | ||
export class CTR { | ||
_counter; | ||
_buffer; | ||
_bufpos = 0; | ||
_cipher; | ||
constructor(cipher, iv) { | ||
this._bufpos = 0; | ||
// Allocate space for counter. | ||
@@ -42,4 +42,4 @@ this._counter = new Uint8Array(cipher.blockSize); | ||
clean() { | ||
(0, wipe_1.wipe)(this._buffer); | ||
(0, wipe_1.wipe)(this._counter); | ||
wipe(this._buffer); | ||
wipe(this._counter); | ||
this._bufpos = this._buffer.length; | ||
@@ -73,3 +73,2 @@ // Cleaning cipher is caller's responsibility, | ||
} | ||
exports.CTR = CTR; | ||
function incrementCounter(counter) { | ||
@@ -76,0 +75,0 @@ let carry = 1; |
@@ -1,8 +0,7 @@ | ||
"use strict"; | ||
// Copyright (C) 2016 Dmitry Chestnykh | ||
// MIT License. See LICENSE file for details. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const aes_1 = require("@stablelib/aes"); | ||
const hex_1 = require("@stablelib/hex"); | ||
const ctr_1 = require("./ctr"); | ||
import { describe, expect, it } from 'vitest'; | ||
import { AES } from "@stablelib/aes"; | ||
import { encode, decode } from "@stablelib/hex"; | ||
import { CTR } from "./ctr"; | ||
describe("AES-CTR", () => { | ||
@@ -18,17 +17,17 @@ const v = { | ||
it("should correctly encrypt", () => { | ||
const cipher = new aes_1.AES((0, hex_1.decode)(v.key)); | ||
const ctr = new ctr_1.CTR(cipher, (0, hex_1.decode)(v.iv)); | ||
const dst1 = new Uint8Array((0, hex_1.decode)(v.dst1).length); | ||
ctr.streamXOR((0, hex_1.decode)(v.src1), dst1); | ||
expect((0, hex_1.encode)(dst1)).toBe(v.dst1); | ||
const cipher = new AES(decode(v.key)); | ||
const ctr = new CTR(cipher, decode(v.iv)); | ||
const dst1 = new Uint8Array(decode(v.dst1).length); | ||
ctr.streamXOR(decode(v.src1), dst1); | ||
expect(encode(dst1)).toBe(v.dst1); | ||
// Continue the same stream. | ||
const dst2 = new Uint8Array((0, hex_1.decode)(v.dst2).length); | ||
ctr.streamXOR((0, hex_1.decode)(v.src2), dst2); | ||
expect((0, hex_1.encode)(dst2)).toBe(v.dst2); | ||
const dst2 = new Uint8Array(decode(v.dst2).length); | ||
ctr.streamXOR(decode(v.src2), dst2); | ||
expect(encode(dst2)).toBe(v.dst2); | ||
}); | ||
it("should produce correct stream", () => { | ||
const cipher = new aes_1.AES((0, hex_1.decode)(v.key)); | ||
const ctr = new ctr_1.CTR(cipher, (0, hex_1.decode)(v.iv)); | ||
const dst1 = new Uint8Array((0, hex_1.decode)(v.dst1).length); | ||
const src1 = (0, hex_1.decode)(v.src1); | ||
const cipher = new AES(decode(v.key)); | ||
const ctr = new CTR(cipher, decode(v.iv)); | ||
const dst1 = new Uint8Array(decode(v.dst1).length); | ||
const src1 = decode(v.src1); | ||
ctr.stream(dst1); | ||
@@ -38,6 +37,6 @@ for (let i = 0; i < dst1.length; i++) { | ||
} | ||
expect((0, hex_1.encode)(dst1)).toBe(v.dst1); | ||
expect(encode(dst1)).toBe(v.dst1); | ||
// Continue the same stream. | ||
const dst2 = new Uint8Array((0, hex_1.decode)(v.dst2).length); | ||
const src2 = (0, hex_1.decode)(v.src2); | ||
const dst2 = new Uint8Array(decode(v.dst2).length); | ||
const src2 = decode(v.src2); | ||
ctr.stream(dst2); | ||
@@ -47,18 +46,18 @@ for (let i = 0; i < dst2.length; i++) { | ||
} | ||
expect((0, hex_1.encode)(dst2)).toBe(v.dst2); | ||
expect(encode(dst2)).toBe(v.dst2); | ||
}); | ||
it("should generate succession when calling multiple times", () => { | ||
const cipher = new aes_1.AES((0, hex_1.decode)(v.key)); | ||
const cipher = new AES(decode(v.key)); | ||
const dst1 = new Uint8Array(100); | ||
const dst2 = new Uint8Array(dst1.length); | ||
// full-length | ||
const ctr1 = new ctr_1.CTR(cipher, (0, hex_1.decode)(v.iv)); | ||
const ctr1 = new CTR(cipher, decode(v.iv)); | ||
ctr1.stream(dst1); | ||
// partial | ||
const ctr2 = new ctr_1.CTR(cipher, (0, hex_1.decode)(v.iv)); | ||
const ctr2 = new CTR(cipher, decode(v.iv)); | ||
ctr2.stream(dst2.subarray(0, 50)); | ||
ctr2.stream(dst2.subarray(50)); | ||
expect((0, hex_1.encode)(dst2)).toEqual((0, hex_1.encode)(dst1)); | ||
expect(encode(dst2)).toEqual(encode(dst1)); | ||
}); | ||
}); | ||
//# sourceMappingURL=ctr.test.js.map |
{ | ||
"name": "@stablelib/ctr", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Counter block cipher mode (CTR)", | ||
"main": "./lib/ctr.js", | ||
"type": "module", | ||
"typings": "./lib/ctr.d.ts", | ||
@@ -18,15 +19,15 @@ "author": "Dmitry Chestnykh", | ||
"build": "tsc", | ||
"test": "jasmine JASMINE_CONFIG_PATH=../../configs/jasmine.json", | ||
"test": "vitest run", | ||
"bench": "node ./lib/ctr.bench.js" | ||
}, | ||
"dependencies": { | ||
"@stablelib/blockcipher": "^1.0.1", | ||
"@stablelib/wipe": "^1.0.1" | ||
"@stablelib/blockcipher": "^2.0.0", | ||
"@stablelib/wipe": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@stablelib/aes": "^1.0.1", | ||
"@stablelib/benchmark": "^1.0.1", | ||
"@stablelib/hex": "^1.0.1" | ||
"@stablelib/aes": "^2.0.0", | ||
"@stablelib/benchmark": "^2.0.0", | ||
"@stablelib/hex": "^2.0.0" | ||
}, | ||
"gitHead": "a402dc74f45c6a93a777a0e2840ce50ba68c3010" | ||
"gitHead": "ecfe9109b3c05419fd3ffc16da6c8255b08ad64f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
348
Yes
20930
+ Added@stablelib/blockcipher@2.0.0(transitive)
+ Added@stablelib/wipe@2.0.0(transitive)
- Removed@stablelib/blockcipher@1.0.1(transitive)
- Removed@stablelib/wipe@1.0.1(transitive)
Updated@stablelib/wipe@^2.0.0