mirror of
https://github.com/nodejs/node.git
synced 2025-05-18 13:11:42 +00:00

Use stronger crypto (larger keys, etc.) for arbitrary tests so they will pass in both FIPS and non-FIPS mode without altering the original intent of the test cases. PR-URL: https://github.com/nodejs/node/pull/3758 Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp> Reviewed-By: James M Snell <jasnell@gmail.com>
34 lines
956 B
JavaScript
34 lines
956 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
console.log('1..0 # Skipped: missing crypto');
|
|
return;
|
|
}
|
|
if (common.hasFipsCrypto) {
|
|
console.log('1..0 # Skipped: BF-ECB is not FIPS 140-2 compatible');
|
|
return;
|
|
}
|
|
var crypto = require('crypto');
|
|
|
|
crypto.DEFAULT_ENCODING = 'buffer';
|
|
|
|
// Testing whether EVP_CipherInit_ex is functioning correctly.
|
|
// Reference: bug#1997
|
|
|
|
(function() {
|
|
var encrypt = crypto.createCipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', '');
|
|
var hex = encrypt.update('Hello World!', 'ascii', 'hex');
|
|
hex += encrypt.final('hex');
|
|
assert.equal(hex.toUpperCase(), '6D385F424AAB0CFBF0BB86E07FFB7D71');
|
|
}());
|
|
|
|
(function() {
|
|
var decrypt = crypto.createDecipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR',
|
|
'');
|
|
var msg = decrypt.update('6D385F424AAB0CFBF0BB86E07FFB7D71', 'hex', 'ascii');
|
|
msg += decrypt.final('ascii');
|
|
assert.equal(msg, 'Hello World!');
|
|
}());
|