存储 OpenSSL BIGNUM 运算结果

Storing OpenSSL BIGNUM operation result

BIGNUMs 上的 OpenSSL 函数将存储结果的变量作为第一个参数,例如 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);,计算出r=a+b; 在下面的语句中使用 a 是安全的,还是我应该声明一个新变量来保存结果?

BN_add(a, a, b);

很安全,你可以在crypto/bn/bntest.c中查找示例。在那里你可以找到像这样的代码:

    BN_add(&c, &c, &b);
    BN_sub(&c, &c, &a);

此外,根据https://www.openssl.org/docs/manmaster/crypto/BN_add.html

BN_add() adds a and b and places the result in r (r=a+b). r may be the same BIGNUM as a or b.