test/bntest.c:1125: error: MEMORY_LEAK
  memory dynamically allocated to `return` by call to `BN_MONT_CTX_new()` at line 1109, column 12 is not reachable after line 1125, column 9.
Showing all 64 steps of the trace


test/bntest.c:1099:1: start of procedure test_mod_exp_mont5()
1097.    * x86_64 cause a different code branch to be taken.
1098.    */
1099. > int test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
1100.   {
1101.       BIGNUM *a, *p, *m, *d, *e;

test/bntest.c:1104:5: Skipping BN_new(): empty list of specs
1102.       BN_MONT_CTX *mont;
1103.   
1104.       a = BN_new();
            ^
1105.       p = BN_new();
1106.       m = BN_new();

test/bntest.c:1105:5: Skipping BN_new(): empty list of specs
1103.   
1104.       a = BN_new();
1105.       p = BN_new();
            ^
1106.       m = BN_new();
1107.       d = BN_new();

test/bntest.c:1106:5: Skipping BN_new(): empty list of specs
1104.       a = BN_new();
1105.       p = BN_new();
1106.       m = BN_new();
            ^
1107.       d = BN_new();
1108.       e = BN_new();

test/bntest.c:1107:5: Skipping BN_new(): empty list of specs
1105.       p = BN_new();
1106.       m = BN_new();
1107.       d = BN_new();
            ^
1108.       e = BN_new();
1109.       mont = BN_MONT_CTX_new();

test/bntest.c:1108:5: Skipping BN_new(): empty list of specs
1106.       m = BN_new();
1107.       d = BN_new();
1108.       e = BN_new();
            ^
1109.       mont = BN_MONT_CTX_new();
1110.   

test/bntest.c:1109:5: 
1107.       d = BN_new();
1108.       e = BN_new();
1109. >     mont = BN_MONT_CTX_new();
1110.   
1111.       BN_bntest_rand(m, 1024, 0, 1); /* must be odd for montgomery */

crypto/bn/bn_mont.c:213:1: start of procedure BN_MONT_CTX_new()
  211.   }
  212.   
  213. > BN_MONT_CTX *BN_MONT_CTX_new(void)
  214.   {
  215.       BN_MONT_CTX *ret;

crypto/bn/bn_mont.c:217:9: 
  215.       BN_MONT_CTX *ret;
  216.   
  217. >     if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
  218.           return (NULL);
  219.   

crypto/mem.c:71:1: start of procedure CRYPTO_malloc()
    69.   }
    70.   
    71. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    72.   {
    73.       void *ret = NULL;

crypto/mem.c:73:5: 
    71.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    72.   {
    73. >     void *ret = NULL;
    74.   
    75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:75:9: Taking false branch
    73.       void *ret = NULL;
    74.   
    75.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                  ^
    76.           return malloc_impl(num, file, line);
    77.   

crypto/mem.c:78:9: Taking false branch
    76.           return malloc_impl(num, file, line);
    77.   
    78.       if (num <= 0)
                  ^
    79.           return NULL;
    80.   

crypto/mem.c:81:5: 
    79.           return NULL;
    80.   
    81. >     allow_customize = 0;
    82.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
    83.       if (call_malloc_debug) {

crypto/mem.c:91:5: 
    89.       }
    90.   #else
    91. >     osslargused(file); osslargused(line);
    92.       ret = malloc(num);
    93.   #endif

crypto/mem.c:91:24: 
    89.       }
    90.   #else
    91. >     osslargused(file); osslargused(line);
    92.       ret = malloc(num);
    93.   #endif

crypto/mem.c:92:5: 
    90.   #else
    91.       osslargused(file); osslargused(line);
    92. >     ret = malloc(num);
    93.   #endif
    94.   

crypto/mem.c:95:5: 
    93.   #endif
    94.   
    95. >     return ret;
    96.   }
    97.   

crypto/mem.c:96:1: return from a call to CRYPTO_malloc
    94.   
    95.       return ret;
    96. > }
    97.   
    98.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/bn/bn_mont.c:217:9: Taking false branch
  215.       BN_MONT_CTX *ret;
  216.   
  217.       if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
                 ^
  218.           return (NULL);
  219.   

crypto/bn/bn_mont.c:220:5: 
  218.           return (NULL);
  219.   
  220. >     BN_MONT_CTX_init(ret);
  221.       ret->flags = BN_FLG_MALLOCED;
  222.       return (ret);

crypto/bn/bn_mont.c:225:1: start of procedure BN_MONT_CTX_init()
    223.   }
    224.   
    225. > void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
    226.   {
    227.       ctx->ri = 0;

crypto/bn/bn_mont.c:227:5: 
    225.   void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
    226.   {
    227. >     ctx->ri = 0;
    228.       bn_init(&(ctx->RR));
    229.       bn_init(&(ctx->N));

crypto/bn/bn_mont.c:228:5: Skipping bn_init(): empty list of specs
    226.   {
    227.       ctx->ri = 0;
    228.       bn_init(&(ctx->RR));
               ^
    229.       bn_init(&(ctx->N));
    230.       bn_init(&(ctx->Ni));

crypto/bn/bn_mont.c:229:5: Skipping bn_init(): empty list of specs
    227.       ctx->ri = 0;
    228.       bn_init(&(ctx->RR));
    229.       bn_init(&(ctx->N));
               ^
    230.       bn_init(&(ctx->Ni));
    231.       ctx->n0[0] = ctx->n0[1] = 0;

crypto/bn/bn_mont.c:230:5: Skipping bn_init(): empty list of specs
    228.       bn_init(&(ctx->RR));
    229.       bn_init(&(ctx->N));
    230.       bn_init(&(ctx->Ni));
               ^
    231.       ctx->n0[0] = ctx->n0[1] = 0;
    232.       ctx->flags = 0;

crypto/bn/bn_mont.c:231:5: 
    229.       bn_init(&(ctx->N));
    230.       bn_init(&(ctx->Ni));
    231. >     ctx->n0[0] = ctx->n0[1] = 0;
    232.       ctx->flags = 0;
    233.   }

crypto/bn/bn_mont.c:232:5: 
    230.       bn_init(&(ctx->Ni));
    231.       ctx->n0[0] = ctx->n0[1] = 0;
    232. >     ctx->flags = 0;
    233.   }
    234.   

crypto/bn/bn_mont.c:233:1: return from a call to BN_MONT_CTX_init
    231.       ctx->n0[0] = ctx->n0[1] = 0;
    232.       ctx->flags = 0;
    233. > }
    234.   
    235.   void BN_MONT_CTX_free(BN_MONT_CTX *mont)

crypto/bn/bn_mont.c:221:5: 
  219.   
  220.       BN_MONT_CTX_init(ret);
  221. >     ret->flags = BN_FLG_MALLOCED;
  222.       return (ret);
  223.   }

crypto/bn/bn_mont.c:222:5: 
  220.       BN_MONT_CTX_init(ret);
  221.       ret->flags = BN_FLG_MALLOCED;
  222. >     return (ret);
  223.   }
  224.   

crypto/bn/bn_mont.c:223:1: return from a call to BN_MONT_CTX_new
  221.       ret->flags = BN_FLG_MALLOCED;
  222.       return (ret);
  223. > }
  224.   
  225.   void BN_MONT_CTX_init(BN_MONT_CTX *ctx)

test/bntest.c:1111:5: 
1109.       mont = BN_MONT_CTX_new();
1110.   
1111. >     BN_bntest_rand(m, 1024, 0, 1); /* must be odd for montgomery */
1112.       /* Zero exponent */
1113.       BN_bntest_rand(a, 1024, 0, 0);

crypto/bn/bn_rand.c:103:1: start of procedure BN_bntest_rand()
  101.   }
  102.   
  103. > int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:105:5: Skipping bnrand(): empty list of specs
  103.   int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);
             ^
  106.   }
  107.   

crypto/bn/bn_rand.c:106:1: return from a call to BN_bntest_rand
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);
  106. > }
  107.   
  108.   /* random number r:  0 <= r < range */

test/bntest.c:1113:5: 
1111.       BN_bntest_rand(m, 1024, 0, 1); /* must be odd for montgomery */
1112.       /* Zero exponent */
1113. >     BN_bntest_rand(a, 1024, 0, 0);
1114.       BN_zero(p);
1115.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))

crypto/bn/bn_rand.c:103:1: start of procedure BN_bntest_rand()
  101.   }
  102.   
  103. > int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:105:5: Skipping bnrand(): empty list of specs
  103.   int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);
             ^
  106.   }
  107.   

crypto/bn/bn_rand.c:106:1: return from a call to BN_bntest_rand
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);
  106. > }
  107.   
  108.   /* random number r:  0 <= r < range */

test/bntest.c:1114:5: Skipping BN_set_word(): empty list of specs
1112.       /* Zero exponent */
1113.       BN_bntest_rand(a, 1024, 0, 0);
1114.       BN_zero(p);
            ^
1115.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
1116.           return 0;

test/bntest.c:1115:10: Taking false branch
1113.       BN_bntest_rand(a, 1024, 0, 0);
1114.       BN_zero(p);
1115.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
                 ^
1116.           return 0;
1117.       if (!BN_is_one(d)) {

test/bntest.c:1117:10: 
1115.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
1116.           return 0;
1117. >     if (!BN_is_one(d)) {
1118.           fprintf(stderr, "Modular exponentiation test failed!\n");
1119.           return 0;

crypto/bn/bn_lib.c:925:1: start of procedure BN_is_one()
  923.   }
  924.   
  925. > int BN_is_one(const BIGNUM *a)
  926.   {
  927.       return BN_abs_is_word(a, 1) && !a->neg;

crypto/bn/bn_lib.c:927:12: 
  925.   int BN_is_one(const BIGNUM *a)
  926.   {
  927. >     return BN_abs_is_word(a, 1) && !a->neg;
  928.   }
  929.   

crypto/bn/bn_lib.c:915:1: start of procedure BN_abs_is_word()
    913.   }
    914.   
    915. > int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
    916.   {
    917.       return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));

crypto/bn/bn_lib.c:917:14: Condition is true
    915.   int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
    916.   {
    917.       return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));
                        ^
    918.   }
    919.   

crypto/bn/bn_lib.c:917:31: Condition is true
    915.   int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
    916.   {
    917.       return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));
                                         ^
    918.   }
    919.   

crypto/bn/bn_lib.c:917:12: 
    915.   int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
    916.   {
    917. >     return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));
    918.   }
    919.   

crypto/bn/bn_lib.c:917:5: 
    915.   int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
    916.   {
    917. >     return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));
    918.   }
    919.   

crypto/bn/bn_lib.c:918:1: return from a call to BN_abs_is_word
    916.   {
    917.       return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));
    918. > }
    919.   
    920.   int BN_is_zero(const BIGNUM *a)

crypto/bn/bn_lib.c:927:12: Condition is true
  925.   int BN_is_one(const BIGNUM *a)
  926.   {
  927.       return BN_abs_is_word(a, 1) && !a->neg;
                    ^
  928.   }
  929.   

crypto/bn/bn_lib.c:927:37: Condition is true
  925.   int BN_is_one(const BIGNUM *a)
  926.   {
  927.       return BN_abs_is_word(a, 1) && !a->neg;
                                             ^
  928.   }
  929.   

crypto/bn/bn_lib.c:927:12: 
  925.   int BN_is_one(const BIGNUM *a)
  926.   {
  927. >     return BN_abs_is_word(a, 1) && !a->neg;
  928.   }
  929.   

crypto/bn/bn_lib.c:927:5: 
  925.   int BN_is_one(const BIGNUM *a)
  926.   {
  927. >     return BN_abs_is_word(a, 1) && !a->neg;
  928.   }
  929.   

crypto/bn/bn_lib.c:928:1: return from a call to BN_is_one
  926.   {
  927.       return BN_abs_is_word(a, 1) && !a->neg;
  928. > }
  929.   
  930.   int BN_is_word(const BIGNUM *a, const BN_ULONG w)

test/bntest.c:1117:10: Taking false branch
1115.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
1116.           return 0;
1117.       if (!BN_is_one(d)) {
                 ^
1118.           fprintf(stderr, "Modular exponentiation test failed!\n");
1119.           return 0;

test/bntest.c:1122:5: 
1120.       }
1121.       /* Zero input */
1122. >     BN_bntest_rand(p, 1024, 0, 0);
1123.       BN_zero(a);
1124.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))

crypto/bn/bn_rand.c:103:1: start of procedure BN_bntest_rand()
  101.   }
  102.   
  103. > int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:105:5: Skipping bnrand(): empty list of specs
  103.   int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);
             ^
  106.   }
  107.   

crypto/bn/bn_rand.c:106:1: return from a call to BN_bntest_rand
  104.   {
  105.       return bnrand(2, rnd, bits, top, bottom);
  106. > }
  107.   
  108.   /* random number r:  0 <= r < range */

test/bntest.c:1123:5: Skipping BN_set_word(): empty list of specs
1121.       /* Zero input */
1122.       BN_bntest_rand(p, 1024, 0, 0);
1123.       BN_zero(a);
            ^
1124.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
1125.           return 0;

test/bntest.c:1124:10: Taking true branch
1122.       BN_bntest_rand(p, 1024, 0, 0);
1123.       BN_zero(a);
1124.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
                 ^
1125.           return 0;
1126.       if (!BN_is_zero(d)) {

test/bntest.c:1125:9: 
1123.       BN_zero(a);
1124.       if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
1125. >         return 0;
1126.       if (!BN_is_zero(d)) {
1127.           fprintf(stderr, "Modular exponentiation test failed!\n");

int test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
{
    BIGNUM *a, *p, *m, *d, *e;
    BN_MONT_CTX *mont;
    a = BN_new();
    p = BN_new();
    m = BN_new();
    d = BN_new();
    e = BN_new();
    mont = BN_MONT_CTX_new();
    BN_bntest_rand(m, 1024, 0, 1);
    BN_bntest_rand(a, 1024, 0, 0);
    BN_zero(p);
    if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
        return 0;
    if (!BN_is_one(d)) {
        fprintf(stderr, "Modular exponentiation test failed!\n");
        return 0;
    }
    BN_bntest_rand(p, 1024, 0, 0);
    BN_zero(a);
    if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
        return 0;
    if (!BN_is_zero(d)) {
        fprintf(stderr, "Modular exponentiation test failed!\n");
        return 0;
    }
    BN_one(a);
    BN_MONT_CTX_set(mont, m, ctx);
    if (!BN_from_montgomery(e, a, mont, ctx))
        return 0;
    if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
        return 0;
    if (!BN_mod_exp_simple(a, e, p, m, ctx))
        return 0;
    if (BN_cmp(a, d) != 0) {
        fprintf(stderr, "Modular exponentiation test failed!\n");
        return 0;
    }
    BN_bntest_rand(e, 1024, 0, 0);
    if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
        return 0;
    if (!BN_mod_exp_simple(a, e, p, m, ctx))
        return 0;
    if (BN_cmp(a, d) != 0) {
        fprintf(stderr, "Modular exponentiation test failed!\n");
        return 0;
    }
    BN_MONT_CTX_free(mont);
    BN_free(a);
    BN_free(p);
    BN_free(m);
    BN_free(d);
    BN_free(e);
    return (1);
}
['int test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *p, *m, *d, *e;\n    BN_MONT_CTX *mont;\n    a = BN_new();\n    p = BN_new();\n    m = BN_new();\n    d = BN_new();\n    e = BN_new();\n    mont = BN_MONT_CTX_new();\n    BN_bntest_rand(m, 1024, 0, 1);\n    BN_bntest_rand(a, 1024, 0, 0);\n    BN_zero(p);\n    if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))\n        return 0;\n    if (!BN_is_one(d)) {\n        fprintf(stderr, "Modular exponentiation test failed!\\n");\n        return 0;\n    }\n    BN_bntest_rand(p, 1024, 0, 0);\n    BN_zero(a);\n    if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))\n        return 0;\n    if (!BN_is_zero(d)) {\n        fprintf(stderr, "Modular exponentiation test failed!\\n");\n        return 0;\n    }\n    BN_one(a);\n    BN_MONT_CTX_set(mont, m, ctx);\n    if (!BN_from_montgomery(e, a, mont, ctx))\n        return 0;\n    if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))\n        return 0;\n    if (!BN_mod_exp_simple(a, e, p, m, ctx))\n        return 0;\n    if (BN_cmp(a, d) != 0) {\n        fprintf(stderr, "Modular exponentiation test failed!\\n");\n        return 0;\n    }\n    BN_bntest_rand(e, 1024, 0, 0);\n    if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))\n        return 0;\n    if (!BN_mod_exp_simple(a, e, p, m, ctx))\n        return 0;\n    if (BN_cmp(a, d) != 0) {\n        fprintf(stderr, "Modular exponentiation test failed!\\n");\n        return 0;\n    }\n    BN_MONT_CTX_free(mont);\n    BN_free(a);\n    BN_free(p);\n    BN_free(m);\n    BN_free(d);\n    BN_free(e);\n    return (1);\n}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n{\n    BN_MONT_CTX *ret;\n    if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)\n        return (NULL);\n    BN_MONT_CTX_init(ret);\n    ret->flags = BN_FLG_MALLOCED;\n    return (ret);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\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    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'void BN_MONT_CTX_init(BN_MONT_CTX *ctx)\n{\n    ctx->ri = 0;\n    bn_init(&(ctx->RR));\n    bn_init(&(ctx->N));\n    bn_init(&(ctx->Ni));\n    ctx->n0[0] = ctx->n0[1] = 0;\n    ctx->flags = 0;\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n    return bnrand(2, rnd, bits, top, bottom);\n}', 'int BN_is_one(const BIGNUM *a)\n{\n    return BN_abs_is_word(a, 1) && !a->neg;\n}', 'int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n    return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));\n}']