crypto: improve ccmp.
This commit is contained in:
parent
104458a483
commit
1d971b0de0
@ -400,8 +400,7 @@ crypto.hkdfExpand = function hkdfExpand(prk, info, len, alg) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
crypto.ccmp = function ccmp(a, b) {
|
crypto.ccmp = function ccmp(a, b) {
|
||||||
var res = 0;
|
var i, res;
|
||||||
var i;
|
|
||||||
|
|
||||||
if (!Buffer.isBuffer(a))
|
if (!Buffer.isBuffer(a))
|
||||||
return false;
|
return false;
|
||||||
@ -409,13 +408,13 @@ crypto.ccmp = function ccmp(a, b) {
|
|||||||
if (!Buffer.isBuffer(b))
|
if (!Buffer.isBuffer(b))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// It's assumed the target length
|
if (b.length === 0)
|
||||||
// would be known to an attacker anyway.
|
return a.length === 0;
|
||||||
if (a.length !== b.length)
|
|
||||||
return false;
|
res = a.length ^ b.length;
|
||||||
|
|
||||||
for (i = 0; i < a.length; i++)
|
for (i = 0; i < a.length; i++)
|
||||||
res |= a[i] ^ b[i];
|
res |= a[i] ^ b[i % b.length];
|
||||||
|
|
||||||
return res === 0;
|
return res === 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user