mirror of https://github.com/wolfSSL/wolfssl.git
Merge pull request #3125 from SparkiDev/mp_leading_bit
Change mp_leading_bit (integer.c) to not to require a copypull/3142/head
commit
50f228af0a
|
@ -271,23 +271,10 @@ int mp_count_bits (mp_int * a)
|
|||
|
||||
int mp_leading_bit (mp_int * a)
|
||||
{
|
||||
int bit = 0;
|
||||
mp_int t;
|
||||
int c = mp_count_bits(a);
|
||||
|
||||
if (mp_init_copy(&t, a) != MP_OKAY)
|
||||
return 0;
|
||||
|
||||
while (mp_iszero(&t) == MP_NO) {
|
||||
#ifndef MP_8BIT
|
||||
bit = (t.dp[0] & 0x80) != 0;
|
||||
#else
|
||||
bit = ((t.dp[0] | ((t.dp[1] & 0x01) << 7)) & 0x80) != 0;
|
||||
#endif
|
||||
if (mp_div_2d (&t, 8, &t, NULL) != MP_OKAY)
|
||||
break;
|
||||
}
|
||||
mp_clear(&t);
|
||||
return bit;
|
||||
if (c == 0) return 0;
|
||||
return (c % 8) == 0;
|
||||
}
|
||||
|
||||
int mp_to_unsigned_bin_at_pos(int x, mp_int *t, unsigned char *b)
|
||||
|
|
Loading…
Reference in New Issue