在 OpenSSL 1.1 中访问 BIGNUM 位?

Access BIGNUM bits in OpenSSL 1.1?

OpenSSL 的 1.1 之前版本 API 我可以通过结构 bignum_st:

中的 "d" 字段访问 BIGNUM 类型的原始表示
   struct bignum_st
           {
           BN_ULONG *d;    /* Pointer to an array of 'BN_BITS2' bit chunks. */
           int top;        /* Index of last used d +1. */
           /* The next are internal book keeping for bn_expand. */
           int dmax;       /* Size of the d array. */
           int neg;        /* one if the number is negative */
           int flags;
           };

在我的程序中,我需要在一些计算之后从 BIGNUM 中获取最低字节 - 这很容易 - 简单地说:

(bn->d[0] & 0xff)

使用 OpenSSL 1.1 版 API,许多 BN 内部结构变得不透明 - 我无法直接访问 BIGNUM 的表示。我仍然可以获得原始表示,但需要额外的复制 - BN_bn2binBN_mask_bits.

有什么方法可以在不进行额外复制的情况下访问最低字节吗?

There is any way to access lowest byte without extra copying?

是也不是。如果 BIGNUM 小于 0xffffffff,则使用 BN_get_word(bn) & 0xff;

如果您的 BIGNUM 大于 0xffffffff,则使用 BN_bn2binpad 复制出一个字节范围。

另请参阅 OpenSSL 错误跟踪器中的 Issue 2001, Please provide BIGNUM And, Or and Xor ops