From 89518ad44560888c0ec4bbcf4fb4a4ba0ccd3060 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 10 Dec 2015 10:48:50 -0800 Subject: [PATCH] Cleanup of the leading zero detection in wc_RsaKeyToDer and wc_DsaKeyToDer to use existing mp_leading_bit function. --- wolfcrypt/src/asn.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index a23190005..479c5d3c8 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -1980,11 +1980,7 @@ int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen) mp_int* keyInt = GetDsaInt(key, i); /* leading zero */ - if ((mp_count_bits(keyInt) & 7) == 0 || mp_iszero(keyInt) == MP_YES) - lbit = 1; - else - lbit = 0; - + lbit = mp_leading_bit(keyInt); rawLen = mp_unsigned_bin_size(keyInt) + lbit; tmps[i] = (byte*)XMALLOC(rawLen + MAX_SEQ_SZ, NULL, DYNAMIC_TYPE_DSA); @@ -5606,11 +5602,7 @@ int wc_RsaKeyToDer(RsaKey* key, byte* output, word32 inLen) mp_int* keyInt = GetRsaInt(key, i); /* leading zero */ - if ((mp_count_bits(keyInt) & 7) == 0 || mp_iszero(keyInt) == MP_YES) - lbit = 1; - else - lbit = 0; - + lbit = mp_leading_bit(keyInt); rawLen = mp_unsigned_bin_size(keyInt) + lbit; tmps[i] = (byte*)XMALLOC(rawLen + MAX_SEQ_SZ, key->heap,