crypto.ecdsa: improves internal function of calc_digest_with_evpkey (#23901)

This commit is contained in:
blackshirt 2025-03-11 16:27:14 +07:00 committed by GitHub
parent 4cc6f2547f
commit de54be058e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -318,12 +318,6 @@ fn calc_digest_with_evpkey(key &C.EVP_PKEY, message []u8, opt SignerOpts) ![]u8
if message.len == 0 {
return error('null-length messages')
}
bits_size := C.EVP_PKEY_get_bits(key)
if bits_size <= 0 {
return error(' bits_size was invalid')
}
key_size := (bits_size + 7) / 8
match opt.hash_config {
.with_no_hash, .with_recommended_hash {
md := default_digest(key)!
@ -337,6 +331,7 @@ fn calc_digest_with_evpkey(key &C.EVP_PKEY, message []u8, opt SignerOpts) ![]u8
if cfg.custom_hash == unsafe { nil } {
return error('Custom hasher was not defined')
}
key_size := evp_key_size(key)!
if key_size > cfg.custom_hash.size() {
if !cfg.allow_smaller_size {
return error('Hash into smaller size than current key size was not allowed')