Lilia's Webcrypto branch rebased and a few very tiny tweaks

This commit is contained in:
lilia 2014-04-03 23:33:02 -07:00 committed by Matt Corallo
parent ab6ebbab16
commit 41d50d7480
7 changed files with 270 additions and 143 deletions

View file

@ -192,10 +192,11 @@ registerOnLoadFunction(function() {
for (var i = 0; i < 10; i++)
info[i] = 240 + i;
var OKM = crypto_tests.HKDF(IKM, salt, info);
var T1 = hexToArrayBuffer("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf");
var T2 = hexToArrayBuffer("34007208d5b887185865");
callback(getString(OKM[0]) == getString(T1) && getString(OKM[1]).substring(0, 10) == getString(T2));
crypto_tests.HKDF(IKM, salt, info).then(function(OKM){
var T1 = hexToArrayBuffer("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf");
var T2 = hexToArrayBuffer("34007208d5b887185865");
callback(getString(OKM[0]) == getString(T1) && getString(OKM[1]).substring(0, 10) == getString(T2));
}, console.log);
}, "HMAC RFC5869 Test vectors");*/
var axolotlTwoPartyTestVectorsAlice = [
@ -429,6 +430,45 @@ registerOnLoadFunction(function() {
axolotlTestVectors(axolotlTwoPartyTestVectorsBob, { encodedNumber: "ALICE" }, callback);
}, "Shuffled Axolotl Test Vectors as Bob", true);
TEST(function(callback) {
var key = getString(hexToArrayBuffer('6f35628d65813435534b5d67fbdb54cb33403d04e843103e6399f806cb5df95febbdd61236f33245'));
var input = getString(hexToArrayBuffer('752cff52e4b90768558e5369e75d97c69643509a5e5904e0a386cbe4d0970ef73f918f675945a9aefe26daea27587e8dc909dd56fd0468805f834039b345f855cfe19c44b55af241fff3ffcd8045cd5c288e6c4e284c3720570b58e4d47b8feeedc52fd1401f698a209fccfa3b4c0d9a797b046a2759f82a54c41ccd7b5f592b'));
var mac = getString(hexToArrayBuffer('05d1243e6465ed9620c9aec1c351a186'));
HmacSHA256(key, input).then(function(result) {
callback(result.substring(0, mac.length) === mac)
});
}, "HMAC SHA-256", true);
TEST(function(callback) {
var key = getString(hexToArrayBuffer('2b7e151628aed2a6abf7158809cf4f3c'));
var counter = getString(hexToArrayBuffer('f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'));
var plaintext = getString(hexToArrayBuffer('6bc1bee22e409f96e93d7e117393172a'));
var ciphertext = getString(hexToArrayBuffer('874d6191b620e3261bef6864990db6ce'));
encryptAESCTR(plaintext, key, counter).then(function(result) {
callback(result === ciphertext);
});
}, "Encrypt AES-CTR", true);
TEST(function(callback) {
var key = getString(hexToArrayBuffer('2b7e151628aed2a6abf7158809cf4f3c'));
var counter = getString(hexToArrayBuffer('f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'));
var plaintext = getString(hexToArrayBuffer('6bc1bee22e409f96e93d7e117393172a'));
var ciphertext = getString(hexToArrayBuffer('874d6191b620e3261bef6864990db6ce'));
decryptAESCTR(ciphertext, key, counter).then(function(result) {
callback(result === plaintext);
});
}, "Decrypt AES-CTR", true);
TEST(function(callback) {
var key = getString(hexToArrayBuffer('603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4'));
var iv = getString(hexToArrayBuffer('000102030405060708090a0b0c0d0e0f'));
var plaintext = getString(hexToArrayBuffer('6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710'));
var ciphertext = getString(hexToArrayBuffer('f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644'));
decryptAESCBC(ciphertext, key, iv).then(function(result) {
callback(result === plaintext);
});
}, "Decrypt AES-CBC", true);
// Setup test timeouts (note that this will only work if things are actually
// being run async, ie in the case of NaCL)
window.setInterval(function() {