adjust asserts in fc/crypto
This commit is contained in:
parent
0a90eff697
commit
59f503d643
2 changed files with 4 additions and 4 deletions
|
|
@ -140,7 +140,7 @@ namespace fc { namespace ecc {
|
||||||
std::string public_key::to_base58( const public_key_data &key )
|
std::string public_key::to_base58( const public_key_data &key )
|
||||||
{
|
{
|
||||||
uint32_t check = (uint32_t)sha256::hash(key.data, sizeof(key))._hash[0];
|
uint32_t check = (uint32_t)sha256::hash(key.data, sizeof(key))._hash[0];
|
||||||
assert(key.size() + sizeof(check) == 37);
|
static_assert(sizeof(key) + sizeof(check) == 37, "Elliptic public key size (or its hash) is incorrect");
|
||||||
array<char, 37> data;
|
array<char, 37> data;
|
||||||
memcpy(data.data, key.begin(), key.size());
|
memcpy(data.data, key.begin(), key.size());
|
||||||
memcpy(data.begin() + key.size(), (const char*)&check, sizeof(check));
|
memcpy(data.begin() + key.size(), (const char*)&check, sizeof(check));
|
||||||
|
|
@ -192,7 +192,7 @@ namespace fc { namespace ecc {
|
||||||
BN_mod(secexp, secexp, order, ctx);
|
BN_mod(secexp, secexp, order, ctx);
|
||||||
|
|
||||||
fc::sha256 secret;
|
fc::sha256 secret;
|
||||||
assert(BN_num_bytes(secexp) <= int64_t(sizeof(secret)));
|
FC_ASSERT(BN_num_bytes(secexp) <= int64_t(sizeof(secret)));
|
||||||
auto shift = sizeof(secret) - BN_num_bytes(secexp);
|
auto shift = sizeof(secret) - BN_num_bytes(secexp);
|
||||||
BN_bn2bin(secexp, ((unsigned char*)&secret)+shift);
|
BN_bn2bin(secexp, ((unsigned char*)&secret)+shift);
|
||||||
return regenerate( secret );
|
return regenerate( secret );
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,13 @@ namespace fc {
|
||||||
|
|
||||||
bool public_key::verify( const sha1& digest, const signature& sig )const
|
bool public_key::verify( const sha1& digest, const signature& sig )const
|
||||||
{
|
{
|
||||||
assert( sig.size() == 2048/8 );
|
static_assert( sig.size() == 2048/8, "Invalid signature size" );
|
||||||
return 0 != RSA_verify( NID_sha1, (const uint8_t*)&digest, 20,
|
return 0 != RSA_verify( NID_sha1, (const uint8_t*)&digest, 20,
|
||||||
(uint8_t*)sig.data(), 2048/8, my->rsa );
|
(uint8_t*)sig.data(), 2048/8, my->rsa );
|
||||||
}
|
}
|
||||||
bool public_key::verify( const sha256& digest, const signature& sig )const
|
bool public_key::verify( const sha256& digest, const signature& sig )const
|
||||||
{
|
{
|
||||||
assert( sig.size() == 2048/8 );
|
static_assert( sig.size() == 2048/8, "Invalid signature size" );
|
||||||
return 0 != RSA_verify( NID_sha256, (const uint8_t*)&digest, 32,
|
return 0 != RSA_verify( NID_sha256, (const uint8_t*)&digest, 32,
|
||||||
(uint8_t*)sig.data(), 2048/8, my->rsa );
|
(uint8_t*)sig.data(), 2048/8, my->rsa );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue