robert
robert

Reputation: 3726

Storing OpenSSL BIGNUM operation result

OpenSSL functions over BIGNUMs take as first argument the variable where the result will be stored, like int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);, which calculates r=a+b; Is it safe the usea in the following statement, or should I declare a new variable to hold the result?

BN_add(a, a, b);

Upvotes: 2

Views: 137

Answers (1)

Leśny Rumcajs
Leśny Rumcajs

Reputation: 2516

It is safe, you can look-up examples in crypto/bn/bntest.c. There you can find code like:

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

Furthermore, according to 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.

Upvotes: 2

Related Questions