Skip to content

Commit

Permalink
Add Snefru v2.0, Snefru v2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nf404 committed Sep 22, 2017
1 parent 353cad8 commit 845b7c6
Show file tree
Hide file tree
Showing 8 changed files with 1,482 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* 0.7.5
- Add Snefru v2.0, Snefru v2.5
* 0.7.4
- Add HAS-160
- Add WHIRLPOOL, WHIRLPOOL-0, WHIRLPOOL-T
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* [SHA512/256 (SHA512/224)](http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf)
* [HAS-160](https://www.randombit.net/has160.html)
* [WHIRLPOOL (WHIRLPOOL-0, WHIRLPOOL-T)](http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html)
* Snefru v2.0 (2 rounds 128, 4 rounds 256), Snefru v2.5 (8 rounds)

### MAC
* [HMAC](https://tools.ietf.org/html/rfc2104)
Expand Down Expand Up @@ -77,6 +78,18 @@ var hash = CryptoApi.hash('whirlpool-0', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('whirlpool-t', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('snefru-2-128', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('snefru-4-128', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('snefru-8-128', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('snefru-2-256', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('snefru-4-256', 'test message', {}).stringify('hex');

var hash = CryptoApi.hash('snefru-8-256', 'test message', {}).stringify('hex');

var hash_hmac = CryptoApi.mac('hmac', 'sha256', '', {}).update('test message')
.finalize().stringify('hex');
```
Expand Down
24 changes: 23 additions & 1 deletion example/benchmark.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script src="../lib/hasher.ripemd160.js"></script>
<script src="../lib/hasher.has160.js"></script>
<script src="../lib/hasher.whirlpool.js"></script>
<script src="../lib/hasher.snefru.js"></script>
<script>
suite('Hash from simple string with HEX result', function(suite) {
bench('md2', function() {
Expand Down Expand Up @@ -70,7 +71,12 @@
bench('whirlpool', function() {
!! CryptoApi.hash('whirlpool', 'xxx', {}).stringify('hex');
});

bench('snefru-2-128', function() {
!! CryptoApi.hash('snefru-2-128', 'xxx', {}).stringify('hex');
});
bench('snefru-8-128', function() {
!! CryptoApi.hash('snefru-8-128', 'xxx', {}).stringify('hex');
});
});
suite('Update', function(suite) {
setup(function() {
Expand All @@ -87,7 +93,11 @@
suite.sha224 = CryptoApi.hasher('sha224', {});
suite.sha256 = CryptoApi.hasher('sha256', {});
suite.sha512 = CryptoApi.hasher('sha512', {});
suite.whirlpool0 = CryptoApi.hasher('whirlpool-0', {});
suite.whirlpoolt = CryptoApi.hasher('whirlpool-t', {});
suite.whirlpool = CryptoApi.hasher('whirlpool', {});
suite.snefru2_128 = CryptoApi.hasher('snefru-2-128', {});
suite.snefru8_128 = CryptoApi.hasher('snefru-8-128', {});
});

bench('md2', function() {
Expand Down Expand Up @@ -129,9 +139,21 @@
bench('sha512', function() {
!! suite.sha512.update('xxx');
});
bench('whirlpool-0', function() {
!! suite.whirlpool0.update('xxx');
});
bench('whirlpool-t', function() {
!! suite.whirlpoolt.update('xxx');
});
bench('whirlpool', function() {
!! suite.whirlpool.update('xxx');
});
bench('snefru-2-128', function() {
!! suite.snefru2_128.update('xxx');
});
bench('snefru-8-128', function() {
!! suite.snefru8_128.update('xxx');
});
});
</script>
</body>
Expand Down
18 changes: 18 additions & 0 deletions lib/crypto-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,24 @@
case 'whirlpool-t':
filename = 'whirlpool';
break;
case 'snefru-2-128':
filename = 'snefru';
break;
case 'snefru-2-256':
filename = 'snefru';
break;
case 'snefru-4-128':
filename = 'snefru';
break;
case 'snefru-4-256':
filename = 'snefru';
break;
case 'snefru-8-128':
filename = 'snefru';
break;
case 'snefru-8-256':
filename = 'snefru';
break;
}
require('./hasher.' + filename);
Hasher = this.hashers[name];
Expand Down
1,155 changes: 1,155 additions & 0 deletions lib/hasher.snefru.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "crypto-api",
"description": "Hashing and encrypting library with no depedencies",
"version": "0.7.4",
"version": "0.7.5",
"homepage": "https://github.com/nf404/crypto-api/",
"author": {
"name": "Aleksandr Mogilnikov",
Expand Down Expand Up @@ -73,6 +73,7 @@
"whirlpool",
"whirlpool-0",
"whirlpool-t",
"snefru",
"hmac"
]
}
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script src="../lib/hasher.ripemd160.js"></script>
<script src="../lib/hasher.has160.js"></script>
<script src="../lib/hasher.whirlpool.js"></script>
<script src="../lib/hasher.snefru.js"></script>
<script src="../lib/mac.hmac.js"></script>
<script src="test-vectors/hash.js"></script>
<script src="test-vectors/hmac.js"></script>
Expand Down
Loading

0 comments on commit 845b7c6

Please sign in to comment.