[njs] Fixed crypto.createHmac() for keys with size >= alg size and < 64.
Dmitry Volyntsev
xeioex at nginx.com
Fri May 4 16:28:36 UTC 2018
details: http://hg.nginx.org/njs/rev/ed4721d09f60
branches:
changeset: 517:ed4721d09f60
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri May 04 19:25:15 2018 +0300
description:
Fixed crypto.createHmac() for keys with size >= alg size and < 64.
diffstat:
njs/njs_crypto.c | 6 +-----
njs/test/njs_unit_test.c | 4 ++++
2 files changed, 5 insertions(+), 5 deletions(-)
diffs (32 lines):
diff -r 4ab51298e1fe -r ed4721d09f60 njs/njs_crypto.c
--- a/njs/njs_crypto.c Thu May 03 18:29:28 2018 +0300
+++ b/njs/njs_crypto.c Fri May 04 19:25:15 2018 +0300
@@ -425,13 +425,9 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs
memcpy(key_buf, digest, alg->size);
memset(key_buf + alg->size, 0, sizeof(key_buf) - alg->size);
- } else if (key.length < alg->size) {
-
- memcpy(key_buf, key.start, key.length);
- memset(key_buf + key.length, 0, sizeof(key_buf) - key.length);
-
} else {
memcpy(key_buf, key.start, sizeof(key_buf));
+ memset(key_buf + key.length, 0, sizeof(key_buf) - key.length);
}
for (i = 0; i < 64; i++) {
diff -r 4ab51298e1fe -r ed4721d09f60 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu May 03 18:29:28 2018 +0300
+++ b/njs/test/njs_unit_test.c Fri May 04 19:25:15 2018 +0300
@@ -9256,6 +9256,10 @@ static njs_unit_test_t njs_test[] =
"h.update('abc'.repeat(100)).digest('hex')"),
nxt_string("b105ad6921e4c54d3fa0a9ec3f7f0ee9bd2c659d") },
+ { nxt_string("var h = require('crypto').createHmac('sha1', 'A'.repeat(40));"
+ "h.update('AB').digest('hex')"),
+ nxt_string("0b84f78ca5275d76d4b7dafb5845ee2b6a79c4c2") },
+
{ nxt_string("var h = require('crypto').createHmac('sha1', 'A'.repeat(64));"
"h.update('AB').digest('hex')"),
nxt_string("400ce530816c6b3247e2959f3982a12aaf58c0c9") },
More information about the nginx-devel
mailing list