Lines Matching defs:const
23 const common = require('../common');
27 const assert = require('assert');
28 const crypto = require('crypto');
29 const { inspect } = require('util');
30 const fixtures = require('../common/fixtures');
40 const TEST_CASES = require(fixtures.path('aead-vectors.js'));
42 const errMessages = {
50 const ciphers = crypto.getCiphers();
52 const expectedWarnings = common.hasFipsCrypto ?
76 const expectedDeprecationWarnings = [
86 for (const test of TEST_CASES) {
97 const isCCM = /^aes-(128|192|256)-ccm$/.test(test.algo);
98 const isOCB = /^aes-(128|192|256)-ocb$/.test(test.algo);
104 const inputEncoding = test.plainIsHex ? 'hex' : 'ascii';
114 const encrypt = crypto.createCipheriv(test.algo,
125 const auth_tag = encrypt.getAuthTag();
142 const decrypt = crypto.createDecipheriv(test.algo,
150 const outputEncoding = test.plainIsHex ? 'hex' : 'ascii';
168 const encrypt = crypto.createCipher(test.algo, test.password, options);
173 const auth_tag = encrypt.getAuthTag();
187 const decrypt = crypto.createDecipher(test.algo, test.password, options);
204 const encrypt = crypto.createCipheriv(test.algo,
226 const encrypt =
240 for (const length of [0, 1, 2, 6, 9, 10, 11, 17]) {
242 const decrypt = crypto.createDecipheriv('aes-128-gcm',
279 const fullTag = '1debb47b2c91ba2cea16fad021703070';
280 for (const [authTagLength, e] of [[undefined, 16], [12, 12], [4, 4]]) {
281 const cipher = crypto.createCipheriv('aes-256-gcm',
289 const tag = cipher.getAuthTag();
296 const decipher = crypto.createDecipheriv('aes-256-gcm',
312 const text = Buffer.concat([
322 for (const authTagLength of [-1, true, false, NaN, 5.5]) {
374 for (const authTagLength of [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 17, 18]) {
408 for (const mode of ['ccm', 'ocb']) {
444 const cipher = crypto.createCipheriv('aes-256-ccm',
451 for (const plaintextLength of [-1, true, false, NaN, 5.5]) {
465 for (const ivLength of [13, 12]) {
466 const maxMessageSize = (1 << (8 * (15 - ivLength))) - 1;
467 const key = 'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8';
468 const cipher = () => crypto.createCipheriv('aes-256-ccm', key,
480 const msg = Buffer.alloc(maxMessageSize + 1);
485 const c = cipher();
497 const cipher = crypto.createCipheriv('aes-256-ccm',
508 const cipher = crypto.createDecipheriv('aes-256-ccm',
522 const key = Buffer.from('1ed2233fa2223ef5d7df08546049406c', 'hex');
523 const iv = Buffer.from('7305220bca40d4c90e1791e9', 'hex');
524 const ct = Buffer.from('8beba09d4d4d861f957d51c0794f4abf8030848e', 'hex');
525 const decrypt = crypto.createDecipheriv('aes-128-ccm', key, iv, {
542 const key = Buffer.from('1ed2233fa2223ef5d7df08546049406c', 'hex');
543 const iv = Buffer.from('579d9dfde9cd93d743da1ceaeebb86e4', 'hex');
544 const decrypt = crypto.createDecipheriv('aes-128-gcm', key, iv);
553 const key = 'x'.repeat(16);
554 const iv = Buffer.from('112233445566778899aabb', 'hex');
555 const options = { authTagLength: 8 };
556 const encrypt = crypto.createCipheriv('aes-128-ccm', key, iv, options);
564 const plain = Buffer.from('Hello world', 'utf8');
565 const key = Buffer.from('0123456789abcdef', 'utf8');
566 const iv = Buffer.from('0123456789ab', 'utf8');
568 for (const mode of ['gcm', 'ocb']) {
569 for (const authTagLength of mode === 'gcm' ? [undefined, 8] : [8]) {
570 const cipher = crypto.createCipheriv(`aes-128-${mode}`, key, iv, {
573 const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]);
574 const authTag = cipher.getAuthTag();
576 for (const authTagBeforeUpdate of [true, false]) {
577 const decipher = crypto.createDecipheriv(`aes-128-${mode}`, key, iv, {
583 const resultUpdate = decipher.update(ciphertext);
587 const resultFinal = decipher.final();
588 const result = Buffer.concat([resultUpdate, resultFinal]);
597 const plain = Buffer.from('Hello world', 'utf8');
598 const key = Buffer.from('0123456789abcdef', 'utf8');
599 const iv = Buffer.from('0123456789ab', 'utf8');
600 const opts = { authTagLength: 8 };
602 for (const mode of ['gcm', 'ccm', 'ocb']) {
603 const cipher = crypto.createCipheriv(`aes-128-${mode}`, key, iv, opts);
604 const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]);
605 const tag = cipher.getAuthTag();
607 const decipher = crypto.createDecipheriv(`aes-128-${mode}`, key, iv, opts);
613 const plaintext = Buffer.concat([
627 const valid = {
657 const prefix = ivLength - valid.iv.length / 2;
670 const algo = 'aes-128-ccm';
671 const key = Buffer.alloc(16);
672 const iv = Buffer.alloc(12);
673 const opts = { authTagLength: 10 };
675 for (const cipher of [
690 const key = Buffer.alloc(32);
691 const iv = Buffer.alloc(12);
693 for (const authTagLength of [0, 17]) {
706 const key = Buffer.alloc(32);
707 const iv = Buffer.alloc(12);
710 const cipher =
712 const ciphertext = Buffer.concat([cipher.update('foo'), cipher.final()]);
713 const authTag = cipher.getAuthTag();
719 const decipher = crypto.createDecipheriv('chacha20-poly1305', key, iv, {
724 const plaintext = decipher.update(ciphertext);
755 const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
760 const [testCase] = rfcTestCases;
761 const key = Buffer.from(testCase.key, 'hex');
762 const iv = Buffer.from(testCase.iv, 'hex');
763 const aad = Buffer.from(testCase.aad, 'hex');
765 for (const opt of [
770 const cipher = crypto.createCipheriv('chacha20-poly1305', key, iv, opt);
771 const ciphertext = Buffer.concat([
775 const authTag = cipher.getAuthTag();
780 const decipher = crypto.createDecipheriv('chacha20-poly1305', key, iv, opt);
781 const plaintext = Buffer.concat([
792 const rfcTestCases = TEST_CASES.filter(({ algo, tampered }) => {
797 const [testCase] = rfcTestCases;
798 const key = Buffer.from(testCase.key, 'hex');
799 const iv = Buffer.from(testCase.iv, 'hex');
800 const aad = Buffer.from(testCase.aad, 'hex');
801 const opt = { authTagLength: 16 };
803 const cipher = crypto.createCipheriv('chacha20-poly1305', key, iv, opt);
804 const ciphertext = Buffer.concat([
808 const authTag = cipher.getAuthTag();
813 const decipher = crypto.createDecipheriv('chacha20-poly1305', key, iv, opt);