Skip to content

Commit

Permalink
Improve tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Nov 21, 2024
1 parent 9574a28 commit db936fa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions test/aes.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/arx.test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 };
Expand Down
2 changes: 0 additions & 2 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion test/polyval.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down

0 comments on commit db936fa

Please sign in to comment.