Skip to content

Commit 53e3975

Browse files
committed
Correcting info for input
1 parent 7bb4c28 commit 53e3975

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

nodejs/ece.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ function HKDF(salt, ikm, info, len) {
5454
}
5555

5656
function info(base, context) {
57-
return Buffer.concat([
57+
var result = Buffer.concat([
5858
new Buffer('Content-Encoding: ' + base + '\0', 'ascii'),
5959
context
6060
]);
61+
keylog('info ' + base, result);
62+
return result;
6163
}
6264

6365
function extractSalt(salt) {
@@ -136,8 +138,14 @@ function deriveKeyAndNonce(params, mode) {
136138
var salt = extractSalt(params.salt);
137139
var s = extractSecretAndContext(params, mode);
138140
var prk = HKDF_extract(salt, s.secret);
141+
var keyinfo = 'aesgcm';
142+
if (params.padSize === 2) {
143+
keyinfo = 'aesgcm128';
144+
} else if (params.padSize && params.padSize !== 1) {
145+
throw new Error('Unable to set context for padSize ' + params.padSize);
146+
}
139147
var result = {
140-
key: HKDF_expand(prk, info('aesgcm128', s.context), KEY_LENGTH),
148+
key: HKDF_expand(prk, info(keyinfo, s.context), KEY_LENGTH),
141149
nonce: HKDF_expand(prk, info('nonce', s.context), NONCE_LENGTH)
142150
};
143151
keylog('key', result.key);

python/http_ece/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,17 @@ def lengthPrefix(key):
6363
)
6464
secret = hkdf_auth.derive(secret)
6565

66+
keyinfo = b"aesgcm"
67+
if padSize == 2:
68+
keyinfo = b"aesgcm128"
69+
elif padSize != 1:
70+
raise Exception(u"unable to set context for padSize=" + str(padSize))
71+
6672
hkdf_key = HKDF(
6773
algorithm=hashes.SHA256(),
6874
length=16,
6975
salt=salt,
70-
info=buildInfo(b"aesgcm128", context),
76+
info=buildInfo(keyinfo, context),
7177
backend=default_backend()
7278
)
7379
hkdf_nonce = HKDF(

0 commit comments

Comments
 (0)