Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cecec46

Browse filesBrowse files
yhwangaddaleax
authored andcommitted
crypto: add test case for AES key wrapping
Add test cases for AES key wrapping and only detect output length in cipher case. The reason being is the returned output length is insufficient in AES key unwrapping case. Backport-PR-URL: #20706 PR-URL: #20587 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 40fb885 commit cecec46
Copy full SHA for cecec46

File tree

Expand file treeCollapse file tree

2 files changed

+63
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+63
-1
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3007,7 +3007,7 @@ CipherBase::UpdateResult CipherBase::Update(const char* data,
30073007
int buff_len = len + EVP_CIPHER_CTX_block_size(ctx_.get());
30083008
// For key wrapping algorithms, get output size by calling
30093009
// EVP_CipherUpdate() with null output.
3010-
if (mode == EVP_CIPH_WRAP_MODE &&
3010+
if (kind_ == kCipher && mode == EVP_CIPH_WRAP_MODE &&
30113011
EVP_CipherUpdate(ctx_.get(),
30123012
nullptr,
30133013
&buff_len,
Collapse file
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
const assert = require('assert');
7+
const crypto = require('crypto');
8+
9+
const test = [
10+
{
11+
algorithm: 'aes128-wrap',
12+
key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
13+
iv: '3fd838af4093d749',
14+
text: '12345678123456781234567812345678'
15+
},
16+
{
17+
algorithm: 'id-aes128-wrap-pad',
18+
key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
19+
iv: '3fd838af',
20+
text: '12345678123456781234567812345678123'
21+
},
22+
{
23+
algorithm: 'aes192-wrap',
24+
key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
25+
iv: '3fd838af4093d749',
26+
text: '12345678123456781234567812345678'
27+
},
28+
{
29+
algorithm: 'id-aes192-wrap-pad',
30+
key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
31+
iv: '3fd838af',
32+
text: '12345678123456781234567812345678123'
33+
},
34+
{
35+
algorithm: 'aes256-wrap',
36+
key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
37+
iv: '3fd838af4093d749',
38+
text: '12345678123456781234567812345678'
39+
},
40+
{
41+
algorithm: 'id-aes256-wrap-pad',
42+
key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
43+
iv: '3fd838af',
44+
text: '12345678123456781234567812345678123'
45+
},
46+
];
47+
48+
test.forEach((data) => {
49+
const cipher = crypto.createCipheriv(
50+
data.algorithm,
51+
Buffer.from(data.key, 'hex'),
52+
Buffer.from(data.iv, 'hex'));
53+
const ciphertext = cipher.update(data.text, 'utf8');
54+
55+
const decipher = crypto.createDecipheriv(
56+
data.algorithm,
57+
Buffer.from(data.key, 'hex'),
58+
Buffer.from(data.iv, 'hex'));
59+
const msg = decipher.update(ciphertext, 'buffer', 'utf8');
60+
61+
assert.strictEqual(msg, data.text, `${data.algorithm} test case failed`);
62+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.