Skip to content

Commit

Permalink
FAB-1517 Add shake hash 256 to hash.js
Browse files Browse the repository at this point in the history
The orderer selected ShakeHash 256 in the place of SHA3-512 which
would be a much slower algorithm for the same security strength
(256 bits).

so the SDK must sent a shake hash of 256 bits strength (length of
512 bits or 64 bytes) in the configuration request to the orderer
as part of constructing a channel.

This PR adds the new API to the hash primitive class hash.js, to
be used by the SDK code that creates channels.

Change-Id: I180dedc7aa23d8f6695406bc2a4164e00aed39e2
Signed-off-by: Jim Zhang <jzhang@us.ibm.com>
  • Loading branch information
jimthematrix committed Jan 4, 2017
1 parent 5786857 commit fbb3ae3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hfc/lib/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
var sjcl = require('sjcl');
var sjcl_codec = require('sjcl-codec');
var jssha = require('jssha');
var sha3_256 = require('js-sha3').sha3_256;
var sha3_384 = require('js-sha3').sha3_384;

var jsSHA3 = require('js-sha3');
var sha3_256 = jsSHA3.sha3_256;
var sha3_384 = jsSHA3.sha3_384;
var shake_256 = jsSHA3.shake_256;

hash_sha2_256 = function (hash) {

Expand Down Expand Up @@ -165,3 +167,4 @@ exports.sha2_256 = function (data) {
};
exports.sha3_256 = sha3_256;
exports.sha3_384 = sha3_384;
exports.shake_256 = shake_256;
12 changes: 12 additions & 0 deletions test/unit/headless-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,8 @@ var HASH_MSG_SHA256 = '4e4aa09b6d80efbd684e80f54a70c1d8605625c3380f4cb012b32644a
var HASH_LONG_MSG_SHA256 = '0d98987f5e4e3ea611f0e3d768c594ff9aac25404265d73554d12c86d7f6fbbc';
var HASH_MSG_SHA3_256 = '7daeff454f7e91e3cd2d1c1bd5fcd1b6c9d4d5fffc6c327710d8fae7b06ee4a3';
var HASH_LONG_MSG_SHA3_256 = '577174210438a85ae4311a62e5fccf2441b960013f5691993cdf38ed6ba0c84f';
var HASH_MSG_SHAKE_256 = '8fe2527123be79ffea8d28572c570ffc54c6e1c03f382645f46b16ba5b7cffd8a6b1553f216909e9a28eb8c88d7711d7fafe757a30b40e203b4f29101b3a1d51';
var HASH_LONG_MSG_SHAKE_256 = 'bf8056882ba669f6ac174e7fd9c1b1af3202bb318b21bd7b47f70427a8f99b0f887462c7ef21a60ce5bd9b5c1cc39e180e23646f3a77e92a0e16730b52882155';

var TEST_KEY_PRIVATE = '93f15b31e3c3f3bddcd776d9219e93d8559e31453757b79e193a793cbd239573';
var TEST_KEY_PUBLIC = '04f46815aa00fe2ba2814b906aa4ef1755caf152658de8997a6a858088296054baf45b06b2eba514bcbc37ae0c0cc7465115d36429d0e0bff23dc40e3760c10aa9';
Expand Down Expand Up @@ -1080,6 +1082,7 @@ var asn1 = jsrsa.asn1;

var ecdsaKey = require('hfc/lib/impl/ecdsa/key.js');
var api = require('hfc/lib/api.js');
var hashPrimitive = require('hfc/lib/hash.js');

test('\n\n ** CryptoSuite_ECDSA_AES - function tests **\n\n', function (t) {
resetDefaults();
Expand Down Expand Up @@ -1126,6 +1129,13 @@ test('\n\n ** CryptoSuite_ECDSA_AES - function tests **\n\n', function (t) {
t.equal(cryptoUtils.hash(TEST_LONG_MSG), HASH_LONG_MSG_SHA3_384,
'CryptoSuite_ECDSA_AES function tests: using "SHA2" hashing algorithm with key size 384');

// test SHAKE_256 hash primitive
t.equal(hashPrimitive.shake_256(TEST_MSG, 512), HASH_MSG_SHAKE_256,
'hash.js function tests: shake_256() on short message');

t.equal(hashPrimitive.shake_256(TEST_LONG_MSG, 512), HASH_LONG_MSG_SHAKE_256,
'hash.js function tests: shake_256() on long message');

return cryptoUtils.generateKey();
})
.then(function (key) {
Expand Down Expand Up @@ -2039,6 +2049,8 @@ test('FabricCOPServices: Test _parseURL() function', function (t) {
var Identity = require('hfc/lib/msp/identity.js');
var MSP = require('hfc/lib/msp/msp.js');



test('\n\n ** Identity class tests **\n\n', function (t) {
t.throws(
function() {
Expand Down

0 comments on commit fbb3ae3

Please sign in to comment.