From d69e67c032088b823c8175d35cc3cb50b2859dcd Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 11 Mar 2015 15:54:21 +0100 Subject: [PATCH] Work around too deterministic nonce --- src/crypto/elliptic_secp256k1.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/crypto/elliptic_secp256k1.cpp b/src/crypto/elliptic_secp256k1.cpp index d270b6f..538c716 100644 --- a/src/crypto/elliptic_secp256k1.cpp +++ b/src/crypto/elliptic_secp256k1.cpp @@ -82,14 +82,23 @@ namespace fc { namespace ecc { return fc::sha512::hash( pub.begin() + 1, pub.size() - 1 ); } + static int extended_nonce_function( unsigned char *nonce32, const unsigned char *msg32, + const unsigned char *key32, unsigned int attempt, + const void *data ) { + unsigned int* extra = (unsigned int*) data; + (*extra)++; + return secp256k1_nonce_function_default( nonce32, msg32, key32, *extra, nullptr ); + } + compact_signature private_key::sign_compact( const fc::sha256& digest )const { FC_ASSERT( my->_key != nullptr ); compact_signature result; int recid; + unsigned int counter = 0; do { - FC_ASSERT( secp256k1_ecdsa_sign_compact( (unsigned char*) digest.data(), (unsigned char*) result.begin() + 1, (unsigned char*) my->_key->data(), NULL, NULL, &recid )); + FC_ASSERT( secp256k1_ecdsa_sign_compact( (unsigned char*) digest.data(), (unsigned char*) result.begin() + 1, (unsigned char*) my->_key->data(), extended_nonce_function, &counter, &recid )); } while( !public_key::is_canonical( result ) ); result.begin()[0] = 27 + 4 + recid; return result;