diff --git a/fabric-client/config/default.json b/fabric-client/config/default.json index d0202ba69d..56c3be37b9 100644 --- a/fabric-client/config/default.json +++ b/fabric-client/config/default.json @@ -1,7 +1,7 @@ { "request-timeout" : 3000, "tcert-batch-size" : 10, - "crypto-hash-algo": "SHA2", + "crypto-hash-algo": "SHA3", "crypto-keysize": 256, "crypto-hsm": false, "crypto-suite-software": { diff --git a/fabric-client/lib/Chain.js b/fabric-client/lib/Chain.js index 9d4171ed85..ca3ea76746 100644 --- a/fabric-client/lib/Chain.js +++ b/fabric-client/lib/Chain.js @@ -29,6 +29,7 @@ var Orderer = require('./Orderer.js'); var settle = require('promise-settle'); var grpc = require('grpc'); var logger = utils.getLogger('Chain.js'); +var hashPrimitives = require('./hash.js'); var _ccProto = grpc.load(__dirname + '/protos/peer/chaincode.proto').protos; var _transProto = grpc.load(__dirname + '/protos/peer/transaction.proto').protos; @@ -1616,7 +1617,7 @@ var Chain = class { var creator_bytes = userContext.getIdentity().serialize();//same as signatureHeader.Creator var nonce_bytes = nonce;//nonce is already in bytes var trans_bytes = Buffer.concat([nonce_bytes, creator_bytes]); - var trans_hash = this.cryptoPrimitives.hash(trans_bytes); + var trans_hash = hashPrimitives.sha2_256(trans_bytes); var transaction_id = Buffer.from(trans_hash).toString(); logger.debug('buildTransactionID - transaction_id %s',transaction_id); return transaction_id; diff --git a/test/unit/cryptosuite-ecdsa-aes.js b/test/unit/cryptosuite-ecdsa-aes.js index ab1940cdea..5a83a63d80 100644 --- a/test/unit/cryptosuite-ecdsa-aes.js +++ b/test/unit/cryptosuite-ecdsa-aes.js @@ -265,11 +265,11 @@ test('\n\n ** CryptoSuite_ECDSA_AES - function tests **\n\n', function (t) { t.equal(true, (typeof cryptoUtils._ecdsaCurve !== 'undefined' && typeof cryptoUtils._ecdsa !== 'undefined'), 'CryptoSuite_ECDSA_AES function tests: default instance has "_ecdsaCurve" and "_ecdsa" properties'); - // test default curve 256 with SHA256 - t.equal(cryptoUtils.hash(TEST_MSG), HASH_MSG_SHA256, + // test default curve 256 with SHA3_256 + t.equal(cryptoUtils.hash(TEST_MSG), HASH_MSG_SHA3_256, 'CryptoSuite_ECDSA_AES function tests: using "SHA2" hashing algorithm with default key size which should be 256'); - t.equal(cryptoUtils.hash(TEST_LONG_MSG), HASH_LONG_MSG_SHA256, + t.equal(cryptoUtils.hash(TEST_LONG_MSG), HASH_LONG_MSG_SHA3_256, 'CryptoSuite_ECDSA_AES function tests: using "SHA2" hashing algorithm with default key size which should be 256'); // test SHA384 hash @@ -288,8 +288,8 @@ test('\n\n ** CryptoSuite_ECDSA_AES - function tests **\n\n', function (t) { t.equal('secp256r1', key.getPublicKey()._key.curveName, 'CryptoSuite_ECDSA_AES function tests: cryptoUtils generated public key curveName == secp256r1'); - // test curve 256 with SHA3_256 - utils.setConfigSetting('crypto-hash-algo', 'SHA3'); + // test curve 256 with SHA2_256 + utils.setConfigSetting('crypto-hash-algo', 'SHA2'); utils.setConfigSetting('crypto-keysize', 256); cryptoUtils = utils.getCryptoSuite(); return cryptoUtils.generateKey(); @@ -298,13 +298,14 @@ test('\n\n ** CryptoSuite_ECDSA_AES - function tests **\n\n', function (t) { t.equal('secp256r1', key.getPublicKey()._key.curveName, 'CryptoSuite_ECDSA_AES function tests: ccryptoUtils generated public key curveName == secp256r1'); - t.equal(cryptoUtils.hash(TEST_MSG), HASH_MSG_SHA3_256, + t.equal(cryptoUtils.hash(TEST_MSG), HASH_MSG_SHA256, 'CryptoSuite_ECDSA_AES function tests: using "SHA3" hashing algorithm with key size 256'); - t.equal(cryptoUtils.hash(TEST_LONG_MSG), HASH_LONG_MSG_SHA3_256, + t.equal(cryptoUtils.hash(TEST_LONG_MSG), HASH_LONG_MSG_SHA256, 'CryptoSuite_ECDSA_AES function tests: using "SHA3" hashing algorithm with key size 256'); // test SHA3_384 + utils.setConfigSetting('crypto-hash-algo', 'SHA3'); utils.setConfigSetting('crypto-keysize', 384); cryptoUtils = utils.getCryptoSuite();