include <openssl/bn.h>
include <stdio.h>
/ * Эта функция предполагает, что она вызывается внутри другой функции, например main, которая имеет свои переменные bn_ctx для передачи в функцию * /
int BN_func(BIGNUM *R, BIGNUM *in_a,BIGNUM *in_b, BN_CTX *ctx)
{
BIGNUM *a, *b, *t;//declare ptrs of type BIGNUM
int ret = 0;//return code
bn_check_top(in_a);//checktop does makes sure the
// internal array is nonempty
bn_check_top(in_b);
BN_CTX_start(ctx);//BigNum context usedto obtain temp BN vars from
// a BN_CTX which have already been created by using BN_CTX_new
a = BN_CTX_get(ctx);//gets ptr from ctx
b = BN_CTX_get(ctx);//
if (a == NULL || b == NULL) //checks if ptr is NULL;
//if so, exits immediately.
goto err;
if (BN_copy(a, in_a) == NULL)//copy the func params to local ctx vars
goto err; //check if null as above
if (BN_copy(b, in_b) == NULL)
goto err;
a->neg = 0;// sets neg to 0 indicating positive qty.
b->neg = 0;
/*after all that we can calculate with the 'a' and 'b' params safely*/
//your code here
/*on error go here*/
err:
BN_CTX_end(ctx);
bn_check_top(R);
return (ret);
}