Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very long zero vector tests for SHA1, SHA256, SHA512 added, #299
- Loading branch information
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
new sjcl.test.TestCase("SHA1 huge zero vector test", function (cb) { | ||
if (!sjcl.hash.sha1) { | ||
this.unimplemented(); | ||
cb && cb(); | ||
return; | ||
} | ||
|
||
var base = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; // 128B | ||
var w = sjcl.bitArray, i, mx, hasher = new sjcl.hash.sha1(), tmpHasher, hash, bl; | ||
var kat = sjcl.test.vector.sha1huge; | ||
|
||
base = w.concat(base, base); // 256 B | ||
base = w.concat(base, base); // 512 B | ||
base = w.concat(base, base); // 1024 B | ||
|
||
bl = w.bitLength(base)/8; | ||
mx = 312*1024*1024/bl; | ||
|
||
for(i=0; i<=mx; ++i){ | ||
if ((i*bl) in kat){ | ||
tmpHasher = new sjcl.hash.sha1(hasher); | ||
hash = tmpHasher.finalize(); | ||
this.require(sjcl.codec.hex.fromBits(hash) == kat[i*bl], i*bl); | ||
} | ||
|
||
hasher.update(base); | ||
} | ||
|
||
cb && cb(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// dd if=/dev/zero bs=1024 count=$((327155712/1024)) | shasum | ||
sjcl.test.vector.sha1huge = | ||
{ | ||
8388608: "5fde1cce603e6566d20da811c9c8bcccb044d4ae", // 8 MB | ||
16777216: "3b4417fc421cee30a9ad0fd9319220a8dae32da2", // 16 MB | ||
33554432: "57b587e1bf2d09335bdac6db18902d43dfe76449", // 32 MB | ||
67108864: "44fac4bedde4df04b9572ac665d3ac2c5cd00c7d", // 64 MB | ||
134217728: "ba713b819c1202dcb0d178df9d2b3222ba1bba44", // 128 MB | ||
268435456: "7b91dbdc56c5781edf6c8847b4aa6965566c5c75", // 256 MB | ||
327155712: "ba799079bf8151d47045f3715bd4c7bfab0bba09" // 312 MB | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
new sjcl.test.TestCase("SHA-256 huge zero vector test", function (cb) { | ||
if (!sjcl.hash.sha256) { | ||
this.unimplemented(); | ||
cb && cb(); | ||
return; | ||
} | ||
|
||
var base = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; // 128B | ||
var w = sjcl.bitArray, i, mx, hasher = new sjcl.hash.sha256(), tmpHasher, hash, bl; | ||
var kat = sjcl.test.vector.sha256huge; | ||
|
||
base = w.concat(base, base); // 256 B | ||
base = w.concat(base, base); // 512 B | ||
base = w.concat(base, base); // 1024 B | ||
|
||
bl = w.bitLength(base)/8; | ||
mx = 312*1024*1024/bl; | ||
|
||
for(i=0; i<=mx; ++i){ | ||
if ((i*bl) in kat){ | ||
tmpHasher = new sjcl.hash.sha256(hasher); | ||
hash = tmpHasher.finalize(); | ||
this.require(sjcl.codec.hex.fromBits(hash) == kat[i*bl], i*bl); | ||
} | ||
|
||
hasher.update(base); | ||
} | ||
|
||
cb && cb(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// dd if=/dev/zero bs=1024 count=$((327155712/1024)) | shasum -a 256 | ||
sjcl.test.vector.sha256huge = | ||
{ | ||
8388608: "2daeb1f36095b44b318410b3f4e8b5d989dcc7bb023d1426c492dab0a3053e74", // 8 MB | ||
16777216: "080acf35a507ac9849cfcba47dc2ad83e01b75663a516279c8b9d243b719643e", // 16 MB | ||
33554432: "83ee47245398adee79bd9c0a8bc57b821e92aba10f5f9ade8a5d1fae4d8c4302", // 32 MB | ||
67108864: "3b6a07d0d404fab4e23b6d34bc6696a6a312dd92821332385e5af7c01c421351", // 64 MB | ||
134217728: "254bcc3fc4f27172636df4bf32de9f107f620d559b20d760197e452b97453917", // 128 MB | ||
268435456: "a6d72ac7690f53be6ae46ba88506bd97302a093f7108472bd9efc3cefda06484", // 256 MB | ||
327155712: "365bb7e64d36c629580c71cc026715f4456825db5dbb63ab65688a1fc8613b38" // 312 MB | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
new sjcl.test.TestCase("SHA-512 huge zero vector test", function (cb) { | ||
if (!sjcl.hash.sha512) { | ||
this.unimplemented(); | ||
cb && cb(); | ||
return; | ||
} | ||
|
||
var base = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; // 128B | ||
var w = sjcl.bitArray, i, mx, hasher = new sjcl.hash.sha512(), tmpHasher, hash, bl; | ||
var kat = sjcl.test.vector.sha512huge; | ||
|
||
base = w.concat(base, base); // 256 B | ||
base = w.concat(base, base); // 512 B | ||
base = w.concat(base, base); // 1024 B | ||
|
||
bl = w.bitLength(base)/8; | ||
mx = 312*1024*1024/bl; | ||
|
||
for(i=0; i<=mx; ++i){ | ||
if ((i*bl) in kat){ | ||
tmpHasher = new sjcl.hash.sha512(hasher); | ||
hash = tmpHasher.finalize(); | ||
this.require(sjcl.codec.hex.fromBits(hash) == kat[i*bl], i*bl); | ||
} | ||
|
||
hasher.update(base); | ||
} | ||
|
||
cb && cb(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// dd if=/dev/zero bs=1024 count=$((327155712/1024)) | shasum -a 512 | ||
sjcl.test.vector.sha512huge = | ||
{ | ||
8388608: "cf76cca4e0f874d508f7e40fb84abc5789ca5f96c1e54e064f3be302766a59fc15a2efb7ffcc9692d13b906b2fe5a0215520d5e232ac69c754f2addb069580de", // 8 MB | ||
16777216: "7e208b53e5c541b23906ef8ed8f5e12e4f1b470fbd0d3e907b1fc0c0b8d78eb1bbfb5a77dcfd9535acf6fa47f4ab956d188b770352c13b0ab7e0160690bae896", // 16 MB | ||
33554432: "1aeae269f4eb7c373e3b9af7cb8eece0ada42fcd1a74ac053fc505168f9caa568cf7ccb5622b7e8ab35fad44603797be4f44efe948a7cfa3ad0381f3f875e662", // 32 MB | ||
67108864: "450766d07ea8acdba4e42a47e3de22ddb35678d62ae5446832b6e3e51780ab92f365ab982152d4d63be9954770997a5438b4fb7f4db5927b9973e82dd1ce0346", // 64 MB | ||
134217728: "0ff7859005e5debb631f55b7dcf4fb3a1293ff937b488d8bf5a8e173d758917ccf9e835403c16db1b33d406b9b40438f88d184d95c81baece136bc68fa0ae5d2", // 128 MB | ||
268435456: "24078827a9a954d8be723eb76b658bf484146d67a47d6f660c72bc641e19a83e6c38099559e7ce76a9640d25f242d89f69e54fc235e1532804395aaf3fb3d671", // 256 MB | ||
327155712: "19042b28bdef6fa8e1894f5315fff9e1ca6f66ca80a1aff477461b62c1e31074a74c76cd619304c049a63b5a6d3784ee1c0549c36ef1618eb8210e68cc418cd1" // 312 MB | ||
}; |