From db936fa82f4e58f5162e341ff2f3d31da1ff73fa Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 21 Nov 2024 10:33:46 +0000 Subject: [PATCH] Improve tests a bit --- test/aes.test.js | 10 +++++----- test/arx.test.js | 3 ++- test/basic.test.js | 2 -- test/polyval.test.js | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/test/aes.test.js b/test/aes.test.js index 1949dcf..6f08da8 100644 --- a/test/aes.test.js +++ b/test/aes.test.js @@ -1,8 +1,7 @@ const { deepStrictEqual, throws } = require('assert'); const { should, describe } = require('micro-should'); -const crypto = require('node:crypto'); -const { hex } = require('@scure/base'); -const { concatBytes } = require('../utils.js'); +const { createCipheriv, createDecipheriv } = require('node:crypto'); +const { bytesToHex, concatBytes, hexToBytes } = require('../utils.js'); const { ecb, cbc, ctr, siv, gcm, aeskw, aeskwp } = require('../aes.js'); // https://datatracker.ietf.org/doc/html/rfc8452#appendix-C const NIST_VECTORS = require('./vectors/nist_800_38a.json'); @@ -12,6 +11,7 @@ const aes_gcm_siv_test = require('./wycheproof/aes_gcm_siv_test.json'); const aes_cbc_test = require('./wycheproof/aes_cbc_pkcs5_test.json'); const aes_kw_test = require('./wycheproof/aes_wrap_test.json'); const aes_kwp_test = require('./wycheproof/aes_kwp_test.json'); +const hex = { decode: hexToBytes, encode: bytesToHex }; // https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf @@ -21,9 +21,9 @@ describe('AES', () => { should('CTR', () => { const nodeAES = (name) => ({ encrypt: (buf, opts) => - Uint8Array.from(crypto.createCipheriv(name, opts.key, opts.nonce).update(buf)), + Uint8Array.from(createCipheriv(name, opts.key, opts.nonce).update(buf)), decrypt: (buf, opts) => - Uint8Array.from(crypto.createDecipheriv(name, opts.key, opts.nonce).update(buf)), + Uint8Array.from(createDecipheriv(name, opts.key, opts.nonce).update(buf)), }); // MDN says counter should be 64 bit // https://developer.mozilla.org/en-US/docs/Web/API/AesCtrParams diff --git a/test/arx.test.js b/test/arx.test.js index ce1b395..59dea88 100644 --- a/test/arx.test.js +++ b/test/arx.test.js @@ -1,6 +1,6 @@ const { deepStrictEqual, throws } = require('assert'); const { should, describe } = require('micro-should'); -const { hex, base64 } = require('@scure/base'); +const { base64 } = require('@scure/base'); const { salsa20, hsalsa, xsalsa20, xsalsa20poly1305 } = require('../salsa.js'); const { chacha20orig, @@ -29,6 +29,7 @@ const sigma32 = utils.utf8ToBytes('expand 32-byte k'); const sigma16_32 = utils.u32(sigma16); const sigma32_32 = utils.u32(sigma32); const { u32 } = utils; +const hex = { decode: utils.hexToBytes, encode: utils.bytesToHex }; const getKey = (key) => { if (key.length === 32) return { key, sigma: sigma32_32 }; diff --git a/test/basic.test.js b/test/basic.test.js index 9453fa5..74966ab 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1,12 +1,10 @@ const { deepStrictEqual, throws } = require('assert'); const { should, describe } = require('micro-should'); -const { hex } = require('@scure/base'); const { managedNonce, randomBytes } = require('../webcrypto.js'); const { siv, gcm, ctr, ecb, cbc, cfb, aeskw, aeskwp } = require('../aes.js'); const { xsalsa20poly1305 } = require('../salsa.js'); const { chacha20poly1305, xchacha20poly1305 } = require('../chacha.js'); const { unalign, TYPE_TEST } = require('./utils.js'); -const { BinaryFF1 } = require('../ff1.js'); const micro = require('../_micro.js'); const CIPHERS = { diff --git a/test/polyval.test.js b/test/polyval.test.js index 9c46b01..fd0099c 100644 --- a/test/polyval.test.js +++ b/test/polyval.test.js @@ -1,8 +1,8 @@ const { deepStrictEqual } = require('assert'); const { should, describe } = require('micro-should'); -const { hex } = require('@scure/base'); const utils = require('../utils.js'); const { ghash, polyval, _toGHASHKey } = require('../_polyval.js'); +const hex = { decode: utils.hexToBytes, encode: utils.bytesToHex }; // https://datatracker.ietf.org/doc/html/rfc8452#appendix-C const VECTORS = require('./vectors/siv.json');