Reputation: 189
I am using OpenSSL library. I write a piece of code as following:
BIGNUM* a;
BIGNUM* b;
BIGNUM* p;
a = BN_new();
b = BN_new();
p = BN_new();
BN_dec2bn(&a, "1");
BN_dec2bn(&b, "1");
BN_dec2bn(&p, "23");
printf("a=");
BN_print_fp(stdout, a);
printf("\n");
printf("b=");
BN_print_fp(stdout, b);
printf("\n");
printf("p=");
BN_print_fp(stdout, p);
printf("\n");
When run it , it always output as following:
a=1
b=1
p=17
As I excepted, p should be 23. But hex(23) = 0x17
, where is wrong ?
Upvotes: -1
Views: 896
Reputation: 52509
From the documentation:
BN_print()
andBN_print_fp()
write the hexadecimal encoding ofa
, with a leading '-' for negative numbers, to theBIO
orFILE fp
.
So nothing's wrong; it's working as expected. If you want to print out a bignum in base 10:
char *as_str = BN_bn2dec(p);
printf("p=%s\n", as_str);
OPENSSL_free(as_str);
Upvotes: 1