Skip to content
Browse files

Add tests

  • Loading branch information...
1 parent 418a76c commit 7702b5338c6711a64f8568dbbe55b5c82ff74c3a @FooBarWidget FooBarWidget committed Oct 6, 2012
Showing with 34,382 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +9 −0 README.md
  3. +1,543 −0 test/data/LongMsgKAT_224.txt
  4. +3 −0 test/data/README
  5. +8,195 −0 test/data/ShortMsgKAT_224.txt
  6. +8,195 −0 test/data/ShortMsgKAT_256.txt
  7. +8,195 −0 test/data/ShortMsgKAT_384.txt
  8. +8,195 −0 test/data/ShortMsgKAT_512.txt
  9. +46 −0 test/generate_tests.py
View
1 .gitignore
@@ -1,2 +1,3 @@
.DS_Store
build
+test/test_vectors.js
View
9 README.md
@@ -36,6 +36,15 @@ Calculates the digest of all of the passed data to be hashed. The encoding can b
Note: unlike `crypto.Hash`, a `SHA3Hash` object _can_ still be used after the `digest()` method been called.
+## Running the test suite
+
+Run the test suite as follows:
+
+ python test/generate_tests.py > test/test_vectors.js
+ node test/test_vectors.js
+
+The test suite is automatically generated from Keccak's reference test suite.
+
## Warning
Do not use SHA-3 for hashing passwords. Do not even use SHA-3 + salt for hashing passowords. Use a [slow hash](http://codahale.com/how-to-safely-store-a-password/) instead.
View
1,543 test/data/LongMsgKAT_224.txt
1,543 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
3 test/data/README
@@ -0,0 +1,3 @@
+From KeccakKAT-3.zip
+
+http://keccak.noekeon.org/KeccakKAT-3.zip
View
8,195 test/data/ShortMsgKAT_224.txt
8,195 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
8,195 test/data/ShortMsgKAT_256.txt
8,195 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
8,195 test/data/ShortMsgKAT_384.txt
8,195 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
8,195 test/data/ShortMsgKAT_512.txt
8,195 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
46 test/generate_tests.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+# This will generate a test suite.
+# Based on code from python-sha3.
+
+def generate():
+ FILES = [
+ ('test/data/ShortMsgKAT_224.txt', 224),
+ ('test/data/ShortMsgKAT_256.txt', 256),
+ ('test/data/ShortMsgKAT_384.txt', 384),
+ ('test/data/ShortMsgKAT_512.txt', 512),
+ ('test/data/LongMsgKAT_224.txt', 224),
+ ]
+
+ print """
+// This file generated by generate_tests.py
+
+var sys = require('sys');
+var assert = require('assert');
+var SHA3 = require('./../build/Release/sha3');
+
+"""
+
+ for path, hashlen in FILES:
+ contents = file(path).read().split('Len = ')
+ for test in contents:
+ lines = test.split('\n')
+ if lines and len(lines) and not lines[0].startswith('#'):
+ length = int(lines[0])
+ if length % 8 == 0 and length != 0:
+ msg = lines[1].split(' = ')[-1].lower()
+ md = lines[2].split(' = ')[-1].lower()
+ name = path.split('/')[-1].split('.')[0]
+
+ print """// %s %s
+ inst = new SHA3.SHA3Hash(%s);
+ inst.update(new Buffer(%r, 'hex'));
+ assert.equal(inst.digest('hex'), %r);
+ sys.print(".");
+
+""" % (name, length, hashlen, msg, md)
+
+ print 'sys.print("\\n");'
+
+if __name__ == '__main__':
+ generate()

0 comments on commit 7702b53

Please sign in to comment.
Something went wrong with that request. Please try again.