BN_print_fp() 函数总是在 OpenSSL 中以十六进制输出 BIGNUM 对象?

BN_print_fp() function always output a BIGNUM object by hex in OpenSSL?

我正在使用 OpenSSL 库。我写了一段代码如下:

    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");

当运行时,总是输出如下:

a=1
b=1
p=17

正如我所排除的,p应该是23。但是hex(23) = 0x17,哪里错了?

来自the documentation

BN_print() and BN_print_fp() write the hexadecimal encoding of a, with a leading '-' for negative numbers, to the BIO or FILE fp.

所以没什么问题;它按预期工作。如果你想以 10 为基数打印出一个 bignum:

char *as_str = BN_bn2dec(p);
printf("p=%s\n", as_str);
OPENSSL_free(as_str);