From 3190fe97f91e78a0e6200c7be03944615ea87286 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 20 Jul 2014 16:31:47 -0400 Subject: [PATCH] HMAC Update for Protov3 --- js/crypto.js | 4 ++-- js/test.js | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/js/crypto.js b/js/crypto.js index 25a5e0b5..0034f407 100644 --- a/js/crypto.js +++ b/js/crypto.js @@ -315,11 +315,11 @@ window.textsecure.crypto = function() { var infoBuffer = new ArrayBuffer(info.byteLength + 1 + 32); var infoArray = new Uint8Array(infoBuffer); infoArray.set(new Uint8Array(info), 32); - infoArray[infoArray.length - 1] = 0; + infoArray[infoArray.length - 1] = 1; // TextSecure implements a slightly tweaked version of RFC 5869: the 0 and 1 should be 1 and 2 here return HmacSHA256(PRK, infoBuffer.slice(32)).then(function(T1) { infoArray.set(new Uint8Array(T1)); - infoArray[infoArray.length - 1] = 1; + infoArray[infoArray.length - 1] = 2; return HmacSHA256(PRK, infoBuffer).then(function(T2) { return [ T1, T2 ]; }); diff --git a/js/test.js b/js/test.js index 8d7d45c7..39f19531 100644 --- a/js/test.js +++ b/js/test.js @@ -218,9 +218,7 @@ textsecure.registerOnLoadFunction(function() { }); }, "Simple Ed25519 tests"); - // TextSecure implements a slightly tweaked version of RFC 5869 and thus this test fails - // If you tweak the HKDF as noted in the comment there, this test passes - /*TEST(function() { + TEST(function() { var IKM = new Uint8Array(new ArrayBuffer(22)); for (var i = 0; i < 22; i++) IKM[i] = 11; @@ -233,12 +231,12 @@ textsecure.registerOnLoadFunction(function() { for (var i = 0; i < 10; i++) info[i] = 240 + i; - return textsecure.crypto.testing_only.HKDF(IKM, salt, info).then(function(OKM){ + return textsecure.crypto.testing_only.HKDF(IKM.buffer, salt.buffer, info.buffer).then(function(OKM){ var T1 = hexToArrayBuffer("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf"); var T2 = hexToArrayBuffer("34007208d5b887185865"); return (getString(OKM[0]) == getString(T1) && getString(OKM[1]).substring(0, 10) == getString(T2)); }); - }, "HMAC RFC5869 Test vectors");*/ + }, "HMAC RFC5869 Test vectors"); var axolotlTwoPartyTestVectorsAlice = [ ["sendMessage",