test/bntest.c:406: error: NULL_DEREFERENCE
  pointer `a` last assigned on line 398 could be null and is dereferenced by call to `BN_set_bit()` at line 406, column 17.
Showing all 105 steps of the trace


test/bntest.c:393:1: start of procedure test_sub()
391.   }
392.   
393. > int test_sub(BIO *bp)
394.   {
395.       BIGNUM *a, *b, *c;

test/bntest.c:398:5: 
396.       int i;
397.   
398. >     a = BN_new();
399.       b = BN_new();
400.       c = BN_new();

crypto/bn/bn_lib.c:276:1: start of procedure BN_new()
  274.   }
  275.   
  276. > BIGNUM *BN_new(void)
  277.   {
  278.       BIGNUM *ret;

crypto/bn/bn_lib.c:280:9: 
  278.       BIGNUM *ret;
  279.   
  280. >     if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/mem.c:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (num <= 0)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

crypto/mem.c:126:5: 
      124.           return NULL;
      125.   
      126. >     allow_customize = 0;
      127.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      128.       if (call_malloc_debug) {

crypto/mem.c:136:5: 
      134.       }
      135.   #else
      136. >     (void)file;
      137.       (void)line;
      138.       ret = malloc(num);

crypto/mem.c:137:5: 
      135.   #else
      136.       (void)file;
      137. >     (void)line;
      138.       ret = malloc(num);
      139.   #endif

crypto/mem.c:138:5: 
      136.       (void)file;
      137.       (void)line;
      138. >     ret = malloc(num);
      139.   #endif
      140.   

crypto/mem.c:153:5: 
      151.   #endif
      152.   
      153. >     return ret;
      154.   }
      155.   

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
      152.   
      153.       return ret;
      154. > }
      155.   
      156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:160:9: Taking false branch
    158.       void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)
                   ^
    161.           memset(ret, 0, num);
    162.       return ret;

crypto/mem.c:162:5: 
    160.       if (ret != NULL)
    161.           memset(ret, 0, num);
    162. >     return ret;
    163.   }
    164.   

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/bn/bn_lib.c:280:9: Taking true branch
  278.       BIGNUM *ret;
  279.   
  280.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
                 ^
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/bn/bn_lib.c:281:9: Skipping ERR_put_error(): empty list of specs
  279.   
  280.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
                 ^
  282.           return (NULL);
  283.       }

crypto/bn/bn_lib.c:282:9: 
  280.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282. >         return (NULL);
  283.       }
  284.       ret->flags = BN_FLG_MALLOCED;

crypto/bn/bn_lib.c:287:1: return from a call to BN_new
  285.       bn_check_top(ret);
  286.       return (ret);
  287. > }
  288.   
  289.    BIGNUM *BN_secure_new(void)

test/bntest.c:399:5: 
397.   
398.       a = BN_new();
399. >     b = BN_new();
400.       c = BN_new();
401.   

crypto/bn/bn_lib.c:276:1: start of procedure BN_new()
  274.   }
  275.   
  276. > BIGNUM *BN_new(void)
  277.   {
  278.       BIGNUM *ret;

crypto/bn/bn_lib.c:280:9: 
  278.       BIGNUM *ret;
  279.   
  280. >     if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/mem.c:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (num <= 0)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

crypto/mem.c:126:5: 
      124.           return NULL;
      125.   
      126. >     allow_customize = 0;
      127.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      128.       if (call_malloc_debug) {

crypto/mem.c:136:5: 
      134.       }
      135.   #else
      136. >     (void)file;
      137.       (void)line;
      138.       ret = malloc(num);

crypto/mem.c:137:5: 
      135.   #else
      136.       (void)file;
      137. >     (void)line;
      138.       ret = malloc(num);
      139.   #endif

crypto/mem.c:138:5: 
      136.       (void)file;
      137.       (void)line;
      138. >     ret = malloc(num);
      139.   #endif
      140.   

crypto/mem.c:153:5: 
      151.   #endif
      152.   
      153. >     return ret;
      154.   }
      155.   

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
      152.   
      153.       return ret;
      154. > }
      155.   
      156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:160:9: Taking true branch
    158.       void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)
                   ^
    161.           memset(ret, 0, num);
    162.       return ret;

crypto/mem.c:161:9: 
    159.   
    160.       if (ret != NULL)
    161. >         memset(ret, 0, num);
    162.       return ret;
    163.   }

crypto/mem.c:162:5: 
    160.       if (ret != NULL)
    161.           memset(ret, 0, num);
    162. >     return ret;
    163.   }
    164.   

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/bn/bn_lib.c:280:9: Taking false branch
  278.       BIGNUM *ret;
  279.   
  280.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
                 ^
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/bn/bn_lib.c:284:5: 
  282.           return (NULL);
  283.       }
  284. >     ret->flags = BN_FLG_MALLOCED;
  285.       bn_check_top(ret);
  286.       return (ret);

crypto/bn/bn_lib.c:286:5: 
  284.       ret->flags = BN_FLG_MALLOCED;
  285.       bn_check_top(ret);
  286. >     return (ret);
  287.   }
  288.   

crypto/bn/bn_lib.c:287:1: return from a call to BN_new
  285.       bn_check_top(ret);
  286.       return (ret);
  287. > }
  288.   
  289.    BIGNUM *BN_secure_new(void)

test/bntest.c:400:5: 
398.       a = BN_new();
399.       b = BN_new();
400. >     c = BN_new();
401.   
402.       for (i = 0; i < num0 + num1; i++) {

crypto/bn/bn_lib.c:276:1: start of procedure BN_new()
  274.   }
  275.   
  276. > BIGNUM *BN_new(void)
  277.   {
  278.       BIGNUM *ret;

crypto/bn/bn_lib.c:280:9: 
  278.       BIGNUM *ret;
  279.   
  280. >     if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/mem.c:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (num <= 0)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

crypto/mem.c:126:5: 
      124.           return NULL;
      125.   
      126. >     allow_customize = 0;
      127.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      128.       if (call_malloc_debug) {

crypto/mem.c:136:5: 
      134.       }
      135.   #else
      136. >     (void)file;
      137.       (void)line;
      138.       ret = malloc(num);

crypto/mem.c:137:5: 
      135.   #else
      136.       (void)file;
      137. >     (void)line;
      138.       ret = malloc(num);
      139.   #endif

crypto/mem.c:138:5: 
      136.       (void)file;
      137.       (void)line;
      138. >     ret = malloc(num);
      139.   #endif
      140.   

crypto/mem.c:153:5: 
      151.   #endif
      152.   
      153. >     return ret;
      154.   }
      155.   

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
      152.   
      153.       return ret;
      154. > }
      155.   
      156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:160:9: Taking true branch
    158.       void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)
                   ^
    161.           memset(ret, 0, num);
    162.       return ret;

crypto/mem.c:161:9: 
    159.   
    160.       if (ret != NULL)
    161. >         memset(ret, 0, num);
    162.       return ret;
    163.   }

crypto/mem.c:162:5: 
    160.       if (ret != NULL)
    161.           memset(ret, 0, num);
    162. >     return ret;
    163.   }
    164.   

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/bn/bn_lib.c:280:9: Taking false branch
  278.       BIGNUM *ret;
  279.   
  280.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
                 ^
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/bn/bn_lib.c:284:5: 
  282.           return (NULL);
  283.       }
  284. >     ret->flags = BN_FLG_MALLOCED;
  285.       bn_check_top(ret);
  286.       return (ret);

crypto/bn/bn_lib.c:286:5: 
  284.       ret->flags = BN_FLG_MALLOCED;
  285.       bn_check_top(ret);
  286. >     return (ret);
  287.   }
  288.   

crypto/bn/bn_lib.c:287:1: return from a call to BN_new
  285.       bn_check_top(ret);
  286.       return (ret);
  287. > }
  288.   
  289.    BIGNUM *BN_secure_new(void)

test/bntest.c:402:10: 
400.       c = BN_new();
401.   
402. >     for (i = 0; i < num0 + num1; i++) {
403.           if (i < num1) {
404.               BN_bntest_rand(a, 512, 0, 0);

test/bntest.c:402:17: Loop condition is true. Entering loop body
400.       c = BN_new();
401.   
402.       for (i = 0; i < num0 + num1; i++) {
                       ^
403.           if (i < num1) {
404.               BN_bntest_rand(a, 512, 0, 0);

test/bntest.c:403:13: Taking true branch
401.   
402.       for (i = 0; i < num0 + num1; i++) {
403.           if (i < num1) {
                   ^
404.               BN_bntest_rand(a, 512, 0, 0);
405.               BN_copy(b, a);

test/bntest.c:404:13: 
402.       for (i = 0; i < num0 + num1; i++) {
403.           if (i < num1) {
404. >             BN_bntest_rand(a, 512, 0, 0);
405.               BN_copy(b, a);
406.               if (BN_set_bit(a, i) == 0)

crypto/bn/bn_rand.c:209:1: start of procedure BN_bntest_rand()
  207.   }
  208.   
  209. > int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  210.   {
  211.       return bnrand(2, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:211:5: 
  209.   int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  210.   {
  211. >     return bnrand(2, rnd, bits, top, bottom);
  212.   }
  213.   

crypto/bn/bn_rand.c:118:1: start of procedure bnrand()
    116.   #include <openssl/sha.h>
    117.   
    118. > static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
    119.   {
    120.       unsigned char *buf = NULL;

crypto/bn/bn_rand.c:120:5: 
    118.   static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
    119.   {
    120. >     unsigned char *buf = NULL;
    121.       int ret = 0, bit, bytes, mask;
    122.       time_t tim;

crypto/bn/bn_rand.c:121:5: 
    119.   {
    120.       unsigned char *buf = NULL;
    121. >     int ret = 0, bit, bytes, mask;
    122.       time_t tim;
    123.   

crypto/bn/bn_rand.c:124:9: Taking false branch
    122.       time_t tim;
    123.   
    124.       if (bits < 0 || (bits == 1 && top > 0)) {
                   ^
    125.           BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);
    126.           return 0;

crypto/bn/bn_rand.c:124:22: Taking false branch
    122.       time_t tim;
    123.   
    124.       if (bits < 0 || (bits == 1 && top > 0)) {
                                ^
    125.           BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);
    126.           return 0;

crypto/bn/bn_rand.c:129:9: Taking false branch
    127.       }
    128.   
    129.       if (bits == 0) {
                   ^
    130.           BN_zero(rnd);
    131.           return 1;

crypto/bn/bn_rand.c:134:5: 
    132.       }
    133.   
    134. >     bytes = (bits + 7) / 8;
    135.       bit = (bits - 1) % 8;
    136.       mask = 0xff << (bit + 1);

crypto/bn/bn_rand.c:135:5: 
    133.   
    134.       bytes = (bits + 7) / 8;
    135. >     bit = (bits - 1) % 8;
    136.       mask = 0xff << (bit + 1);
    137.   

crypto/bn/bn_rand.c:136:5: 
    134.       bytes = (bits + 7) / 8;
    135.       bit = (bits - 1) % 8;
    136. >     mask = 0xff << (bit + 1);
    137.   
    138.       buf = OPENSSL_malloc(bytes);

crypto/bn/bn_rand.c:138:5: 
    136.       mask = 0xff << (bit + 1);
    137.   
    138. >     buf = OPENSSL_malloc(bytes);
    139.       if (buf == NULL) {
    140.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (num <= 0)

crypto/mem.c:123:9: Taking true branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

crypto/mem.c:124:9: 
      122.   
      123.       if (num <= 0)
      124. >         return NULL;
      125.   
      126.       allow_customize = 0;

crypto/mem.c:154:1: return from a call to CRYPTO_malloc
      152.   
      153.       return ret;
      154. > }
      155.   
      156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/bn/bn_rand.c:139:9: Taking true branch
    137.   
    138.       buf = OPENSSL_malloc(bytes);
    139.       if (buf == NULL) {
                   ^
    140.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
    141.           goto err;

crypto/bn/bn_rand.c:140:9: Skipping ERR_put_error(): empty list of specs
    138.       buf = OPENSSL_malloc(bytes);
    139.       if (buf == NULL) {
    140.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
                   ^
    141.           goto err;
    142.       }

crypto/bn/bn_rand.c:193:2: 
    191.           goto err;
    192.       ret = 1;
    193. >  err:
    194.       OPENSSL_clear_free(buf, bytes);
    195.       bn_check_top(rnd);

crypto/bn/bn_rand.c:194:5: 
    192.       ret = 1;
    193.    err:
    194. >     OPENSSL_clear_free(buf, bytes);
    195.       bn_check_top(rnd);
    196.       return (ret);

crypto/mem.c:248:1: start of procedure CRYPTO_clear_free()
      246.   }
      247.   
      248. > void CRYPTO_clear_free(void *str, size_t num)
      249.   {
      250.       if (str == NULL)

crypto/mem.c:250:9: Taking true branch
      248.   void CRYPTO_clear_free(void *str, size_t num)
      249.   {
      250.       if (str == NULL)
                     ^
      251.           return;
      252.       if (num)

crypto/mem.c:251:9: 
      249.   {
      250.       if (str == NULL)
      251. >         return;
      252.       if (num)
      253.           OPENSSL_cleanse(str, num);

crypto/mem.c:255:1: return from a call to CRYPTO_clear_free
      253.           OPENSSL_cleanse(str, num);
      254.       CRYPTO_free(str);
      255. > }

crypto/bn/bn_rand.c:196:5: 
    194.       OPENSSL_clear_free(buf, bytes);
    195.       bn_check_top(rnd);
    196. >     return (ret);
    197.   }
    198.   

crypto/bn/bn_rand.c:197:1: return from a call to bnrand
    195.       bn_check_top(rnd);
    196.       return (ret);
    197. > }
    198.   
    199.   int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)

crypto/bn/bn_rand.c:212:1: return from a call to BN_bntest_rand
  210.   {
  211.       return bnrand(2, rnd, bits, top, bottom);
  212. > }
  213.   
  214.   /* random number r:  0 <= r < range */

test/bntest.c:405:13: Skipping BN_copy(): empty list of specs
403.           if (i < num1) {
404.               BN_bntest_rand(a, 512, 0, 0);
405.               BN_copy(b, a);
                   ^
406.               if (BN_set_bit(a, i) == 0)
407.                   return (0);

test/bntest.c:406:17: 
404.               BN_bntest_rand(a, 512, 0, 0);
405.               BN_copy(b, a);
406. >             if (BN_set_bit(a, i) == 0)
407.                   return (0);
408.               BN_add_word(b, i);

crypto/bn/bn_lib.c:747:1: start of procedure BN_set_bit()
  745.   }
  746.   
  747. > int BN_set_bit(BIGNUM *a, int n)
  748.   {
  749.       int i, j, k;

crypto/bn/bn_lib.c:751:9: Taking false branch
  749.       int i, j, k;
  750.   
  751.       if (n < 0)
                 ^
  752.           return 0;
  753.   

crypto/bn/bn_lib.c:754:5: 
  752.           return 0;
  753.   
  754. >     i = n / BN_BITS2;
  755.       j = n % BN_BITS2;
  756.       if (a->top <= i) {

crypto/bn/bn_lib.c:755:5: 
  753.   
  754.       i = n / BN_BITS2;
  755. >     j = n % BN_BITS2;
  756.       if (a->top <= i) {
  757.           if (bn_wexpand(a, i + 1) == NULL)

crypto/bn/bn_lib.c:756:9: 
  754.       i = n / BN_BITS2;
  755.       j = n % BN_BITS2;
  756. >     if (a->top <= i) {
  757.           if (bn_wexpand(a, i + 1) == NULL)
  758.               return (0);

int test_sub(BIO *bp)
{
    BIGNUM *a, *b, *c;
    int i;
    a = BN_new();
    b = BN_new();
    c = BN_new();
    for (i = 0; i < num0 + num1; i++) {
        if (i < num1) {
            BN_bntest_rand(a, 512, 0, 0);
            BN_copy(b, a);
            if (BN_set_bit(a, i) == 0)
                return (0);
            BN_add_word(b, i);
        } else {
            BN_bntest_rand(b, 400 + i - num1, 0, 0);
            a->neg = rand_neg();
            b->neg = rand_neg();
        }
        BN_sub(c, a, b);
        if (bp != NULL) {
            if (!results) {
                BN_print(bp, a);
                BIO_puts(bp, " - ");
                BN_print(bp, b);
                BIO_puts(bp, " - ");
            }
            BN_print(bp, c);
            BIO_puts(bp, "\n");
        }
        BN_add(c, c, b);
        BN_sub(c, c, a);
        if (!BN_is_zero(c)) {
            fprintf(stderr, "Subtract test failed!\n");
            return 0;
        }
    }
    BN_free(a);
    BN_free(b);
    BN_free(c);
    return (1);
}
['int test_sub(BIO *bp)\n{\n    BIGNUM *a, *b, *c;\n    int i;\n    a = BN_new();\n    b = BN_new();\n    c = BN_new();\n    for (i = 0; i < num0 + num1; i++) {\n        if (i < num1) {\n            BN_bntest_rand(a, 512, 0, 0);\n            BN_copy(b, a);\n            if (BN_set_bit(a, i) == 0)\n                return (0);\n            BN_add_word(b, i);\n        } else {\n            BN_bntest_rand(b, 400 + i - num1, 0, 0);\n            a->neg = rand_neg();\n            b->neg = rand_neg();\n        }\n        BN_sub(c, a, b);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " - ");\n                BN_print(bp, b);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, c);\n            BIO_puts(bp, "\\n");\n        }\n        BN_add(c, c, b);\n        BN_sub(c, c, a);\n        if (!BN_is_zero(c)) {\n            fprintf(stderr, "Subtract test failed!\\n");\n            return 0;\n        }\n    }\n    BN_free(a);\n    BN_free(b);\n    BN_free(c);\n    return (1);\n}', 'BIGNUM *BN_new(void)\n{\n    BIGNUM *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->flags = BN_FLG_MALLOCED;\n    bn_check_top(ret);\n    return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n    return bnrand(2, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n    unsigned char *buf = NULL;\n    int ret = 0, bit, bytes, mask;\n    time_t tim;\n    if (bits < 0 || (bits == 1 && top > 0)) {\n        BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n        return 0;\n    }\n    if (bits == 0) {\n        BN_zero(rnd);\n        return 1;\n    }\n    bytes = (bits + 7) / 8;\n    bit = (bits - 1) % 8;\n    mask = 0xff << (bit + 1);\n    buf = OPENSSL_malloc(bytes);\n    if (buf == NULL) {\n        BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    time(&tim);\n    RAND_add(&tim, sizeof(tim), 0.0);\n    if (pseudorand) {\n        if (RAND_bytes(buf, bytes) <= 0)\n            goto err;\n    } else {\n        if (RAND_bytes(buf, bytes) <= 0)\n            goto err;\n    }\n    if (pseudorand == 2) {\n        int i;\n        unsigned char c;\n        for (i = 0; i < bytes; i++) {\n            if (RAND_bytes(&c, 1) <= 0)\n                goto err;\n            if (c >= 128 && i > 0)\n                buf[i] = buf[i - 1];\n            else if (c < 42)\n                buf[i] = 0;\n            else if (c < 84)\n                buf[i] = 255;\n        }\n    }\n    if (top >= 0) {\n        if (top) {\n            if (bit == 0) {\n                buf[0] = 1;\n                buf[1] |= 0x80;\n            } else {\n                buf[0] |= (3 << (bit - 1));\n            }\n        } else {\n            buf[0] |= (1 << bit);\n        }\n    }\n    buf[0] &= ~mask;\n    if (bottom)\n        buf[bytes - 1] |= 1;\n    if (!BN_bin2bn(buf, bytes, rnd))\n        goto err;\n    ret = 1;\n err:\n    OPENSSL_clear_free(buf, bytes);\n    bn_check_top(rnd);\n    return (ret);\n}', 'void CRYPTO_clear_free(void *str, size_t num)\n{\n    if (str == NULL)\n        return;\n    if (num)\n        OPENSSL_cleanse(str, num);\n    CRYPTO_free(str);\n}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n    int i, j, k;\n    if (n < 0)\n        return 0;\n    i = n / BN_BITS2;\n    j = n % BN_BITS2;\n    if (a->top <= i) {\n        if (bn_wexpand(a, i + 1) == NULL)\n            return (0);\n        for (k = a->top; k < i + 1; k++)\n            a->d[k] = 0;\n        a->top = i + 1;\n    }\n    a->d[i] |= (((BN_ULONG)1) << j);\n    bn_check_top(a);\n    return (1);\n}']