crypto/jpake/jpaketest.c:25: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `JPAKE_STEP1_process`.
Showing all 28 steps of the trace


crypto/jpake/jpaketest.c:24:5: Call
22.       puts("A->B s1");
23.       JPAKE_STEP1_init(&alice_s1);
24.       JPAKE_STEP1_generate(&alice_s1, alice);
          ^
25.       if(!JPAKE_STEP1_process(bob, &alice_s1))
26.   	{

crypto/jpake/jpake.c:280:5: Call
  278.       genrand(ctx);
  279.       generate_step_part(&send->p1, ctx->xa, ctx->p.g, ctx);
  280.       generate_step_part(&send->p2, ctx->xb, ctx->p.g, ctx);
             ^
  281.   
  282.       return 1;

crypto/jpake/jpake.c:251:5: Call
    249.       {
    250.       BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx);
    251.       generate_zkp(p, x, g, ctx);
               ^
    252.       }
    253.   

crypto/jpake/jpake.c:199:5: Call
      197.       BN_rand_range(r, ctx->p.q);
      198.      /* g^r */
      199.       BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx);
                 ^
      200.   
      201.      /* h=hash... */

crypto/bn/bn_exp.c:219:8: Call
        217.   			{
        218.   			BN_ULONG A = a->d[0];
        219.   			ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);
                      ^
        220.   			}
        221.   		else

crypto/bn/bn_exp.c:727:1: Parameter `rr->top`
          725.   	}
          726.   
          727. > int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
          728.                            const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
          729.   	{

crypto/jpake/jpake.c:202:5: Call
      200.   
      201.      /* h=hash... */
      202.       zkp_hash(h, zkpg, p, ctx->p.name);
                 ^
      203.   
      204.      /* b = r - x*h */

crypto/jpake/jpake.c:162:1: Parameter `p->zkpx.gr->top`
        160.   
        161.   /* h=hash(g, g^r, g^x, name) */
        162. > static void zkp_hash(BIGNUM *h, const BIGNUM *zkpg, const JPAKE_STEP_PART *p,
        163.   		     const char *proof_name)
        164.       {

crypto/jpake/jpake.c:175:5: Call
        173.       hashbn(&sha, zkpg);
        174.       OPENSSL_assert(!BN_is_zero(p->zkpx.gr));
        175.       hashbn(&sha, p->zkpx.gr);
                   ^
        176.       hashbn(&sha, p->gx);
        177.       hashstring(&sha, proof_name);

crypto/jpake/jpake.c:150:1: Parameter `bn->top`
          148.       }
          149.   
          150. > static void hashbn(SHA_CTX *sha, const BIGNUM *bn)
          151.       {
          152.       size_t l = BN_num_bytes(bn);

crypto/jpake/jpake.c:152:16: Call
          150.   static void hashbn(SHA_CTX *sha, const BIGNUM *bn)
          151.       {
          152.       size_t l = BN_num_bytes(bn);
                                ^
          153.       unsigned char *bin = OPENSSL_malloc(l);
          154.   

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
            246.   	}
            247.   
            248. > int BN_num_bits(const BIGNUM *a)
            249.   	{
            250.   	int i = a->top - 1;

crypto/jpake/jpake.c:156:5: Call
          154.   
          155.       hashlength(sha, l);
          156.       BN_bn2bin(bn, bin);
                     ^
          157.       SHA1_Update(sha, bin, l);
          158.       OPENSSL_free(bin);

crypto/bn/bn_lib.c:641:1: Parameter `a->top`
            639.   
            640.   /* ignore negative */
            641. > int BN_bn2bin(const BIGNUM *a, unsigned char *to)
            642.   	{
            643.   	int n,i;

crypto/bn/bn_lib.c:647:6: Call
            645.   
            646.   	bn_check_top(a);
            647.   	n=i=BN_num_bytes(a);
                        ^
            648.   	while (i--)
            649.   		{

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
              246.   	}
              247.   
              248. > int BN_num_bits(const BIGNUM *a)
              249.   	{
              250.   	int i = a->top - 1;

crypto/jpake/jpaketest.c:25:9: Call
23.       JPAKE_STEP1_init(&alice_s1);
24.       JPAKE_STEP1_generate(&alice_s1, alice);
25.       if(!JPAKE_STEP1_process(bob, &alice_s1))
              ^
26.   	{
27.   	printf("Bob fails to process Alice's step 1\n");

crypto/jpake/jpake.c:285:1: Parameter `ctx->p.g->top`
  283.       }
  284.   
  285. > int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received)
  286.       {
  287.      /* verify their ZKP(xc) */

crypto/jpake/jpake.c:288:9: Call
  286.       {
  287.      /* verify their ZKP(xc) */
  288.       if(!verify_zkp(&received->p1, ctx->p.g, ctx))
                 ^
  289.   	{
  290.   	JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X3_FAILED);

crypto/jpake/jpake.c:214:1: Parameter `zkpg->top`
    212.       }
    213.   
    214. > static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg,
    215.   		      JPAKE_CTX *ctx)
    216.       {

crypto/jpake/jpake.c:223:5: Call
    221.       int ret = 0;
    222.   
    223.       zkp_hash(h, zkpg, p, ctx->p.peer_name);
               ^
    224.   
    225.      /* t1 = g^b */

crypto/jpake/jpake.c:162:1: Parameter `zkpg->top`
      160.   
      161.   /* h=hash(g, g^r, g^x, name) */
      162. > static void zkp_hash(BIGNUM *h, const BIGNUM *zkpg, const JPAKE_STEP_PART *p,
      163.   		     const char *proof_name)
      164.       {

crypto/jpake/jpake.c:173:5: Call
      171.       */
      172.       SHA1_Init(&sha);
      173.       hashbn(&sha, zkpg);
                 ^
      174.       OPENSSL_assert(!BN_is_zero(p->zkpx.gr));
      175.       hashbn(&sha, p->zkpx.gr);

crypto/jpake/jpake.c:150:1: Parameter `bn->top`
        148.       }
        149.   
        150. > static void hashbn(SHA_CTX *sha, const BIGNUM *bn)
        151.       {
        152.       size_t l = BN_num_bytes(bn);

crypto/jpake/jpake.c:152:16: Call
        150.   static void hashbn(SHA_CTX *sha, const BIGNUM *bn)
        151.       {
        152.       size_t l = BN_num_bytes(bn);
                              ^
        153.       unsigned char *bin = OPENSSL_malloc(l);
        154.   

crypto/bn/bn_lib.c:248:1: <LHS trace>
246.   	}
247.   
248. > int BN_num_bits(const BIGNUM *a)
249.   	{
250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
          246.   	}
          247.   
          248. > int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:250:2: Binary operation: ([0, +oo] - 1):unsigned64 by call to `JPAKE_STEP1_process` 
          248.   int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;
                  ^
          251.   	bn_check_top(a);
          252.   

int BN_num_bits(const BIGNUM *a)
	{
	int i = a->top - 1;
	bn_check_top(a);
	if (BN_is_zero(a)) return 0;
	return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
	}
['static int run_jpake(JPAKE_CTX *alice, JPAKE_CTX *bob)\n    {\n    JPAKE_STEP1 alice_s1;\n    JPAKE_STEP1 bob_s1;\n    JPAKE_STEP2 alice_s2;\n    JPAKE_STEP2 bob_s2;\n    JPAKE_STEP3A alice_s3a;\n    JPAKE_STEP3B bob_s3b;\n    puts("A->B s1");\n    JPAKE_STEP1_init(&alice_s1);\n    JPAKE_STEP1_generate(&alice_s1, alice);\n    if(!JPAKE_STEP1_process(bob, &alice_s1))\n\t{\n\tprintf("Bob fails to process Alice\'s step 1\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 1;\n\t}\n    JPAKE_STEP1_release(&alice_s1);\n    puts("B->A s1");\n    JPAKE_STEP1_init(&bob_s1);\n    JPAKE_STEP1_generate(&bob_s1, bob);\n    if(!JPAKE_STEP1_process(alice, &bob_s1))\n\t{\n\tprintf("Alice fails to process Bob\'s step 1\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 2;\n\t}\n    JPAKE_STEP1_release(&bob_s1);\n    puts("A->B s2");\n    JPAKE_STEP2_init(&alice_s2);\n    JPAKE_STEP2_generate(&alice_s2, alice);\n    if(!JPAKE_STEP2_process(bob, &alice_s2))\n\t{\n\tprintf("Bob fails to process Alice\'s step 2\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 3;\n\t}\n    JPAKE_STEP2_release(&alice_s2);\n    puts("B->A s2");\n    JPAKE_STEP2_init(&bob_s2);\n    JPAKE_STEP2_generate(&bob_s2, bob);\n    if(!JPAKE_STEP2_process(alice, &bob_s2))\n\t{\n\tprintf("Alice fails to process Bob\'s step 2\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 4;\n\t}\n    JPAKE_STEP2_release(&bob_s2);\n    showbn("Alice\'s key", JPAKE_get_shared_key(alice));\n    showbn("Bob\'s key  ", JPAKE_get_shared_key(bob));\n    puts("A->B s3a");\n    JPAKE_STEP3A_init(&alice_s3a);\n    JPAKE_STEP3A_generate(&alice_s3a, alice);\n    if(!JPAKE_STEP3A_process(bob, &alice_s3a))\n\t{\n\tprintf("Bob fails to process Alice\'s step 3a\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 5;\n\t}\n    JPAKE_STEP3A_release(&alice_s3a);\n    puts("B->A s3b");\n    JPAKE_STEP3B_init(&bob_s3b);\n    JPAKE_STEP3B_generate(&bob_s3b, bob);\n    if(!JPAKE_STEP3B_process(alice, &bob_s3b))\n\t{\n\tprintf("Alice fails to process Bob\'s step 3b\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 6;\n\t}\n    JPAKE_STEP3B_release(&bob_s3b);\n    return 0;\n    }', 'int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx)\n    {\n    genrand(ctx);\n    generate_step_part(&send->p1, ctx->xa, ctx->p.g, ctx);\n    generate_step_part(&send->p2, ctx->xb, ctx->p.g, ctx);\n    return 1;\n    }', 'static void generate_step_part(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t       const BIGNUM *g, JPAKE_CTX *ctx)\n    {\n    BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx);\n    generate_zkp(p, x, g, ctx);\n    }', 'static void generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *zkpg, JPAKE_CTX *ctx)\n    {\n    BIGNUM *r = BN_new();\n    BIGNUM *h = BN_new();\n    BIGNUM *t = BN_new();\n    BN_rand_range(r, ctx->p.q);\n    BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx);\n    zkp_hash(h, zkpg, p, ctx->p.name);\n    BN_mod_mul(t, x, h, ctx->p.q, ctx->ctx);\n    BN_mod_sub(p->zkpx.b, r, t, ctx->p.q, ctx->ctx);\n    BN_free(t);\n    BN_free(h);\n    BN_free(r);\n    }', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t       BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n#  ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n#  endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n                         const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tBN_MONT_CTX *mont = NULL;\n\tint b, bits, ret=0;\n\tint r_is_one;\n\tBN_ULONG w, next_w;\n\tBIGNUM *d, *r, *t;\n\tBIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n\t\t(BN_mul_word(r, (w)) && \\\n\t\t(   \\\n\t\t\t(BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n\t\t(BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tif (m->top == 1)\n\t\ta %= m->d[0];\n\tbits = BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tif (a == 0)\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tt = BN_CTX_get(ctx);\n\tif (d == NULL || r == NULL || t == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont = BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont, m, ctx)) goto err;\n\t\t}\n\tr_is_one = 1;\n\tw = a;\n\tfor (b = bits-2; b >= 0; b--)\n\t\t{\n\t\tnext_w = w*w;\n\t\tif ((next_w/w) != w)\n\t\t\t{\n\t\t\tif (r_is_one)\n\t\t\t\t{\n\t\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\t\tr_is_one = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t\t}\n\t\t\tnext_w = 1;\n\t\t\t}\n\t\tw = next_w;\n\t\tif (!r_is_one)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) goto err;\n\t\t\t}\n\t\tif (BN_is_bit_set(p, b))\n\t\t\t{\n\t\t\tnext_w = w*a;\n\t\t\tif ((next_w/a) != w)\n\t\t\t\t{\n\t\t\t\tif (r_is_one)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\t\t\tr_is_one = 0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t\t\t}\n\t\t\t\tnext_w = a;\n\t\t\t\t}\n\t\t\tw = next_w;\n\t\t\t}\n\t\t}\n\tif (w != 1)\n\t\t{\n\t\tif (r_is_one)\n\t\t\t{\n\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t}\n\t\t}\n\tif (r_is_one)\n\t\t{\n\t\tif (!BN_one(rr)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_from_montgomery(rr, r, mont, ctx)) goto err;\n\t\t}\n\tret = 1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'static void zkp_hash(BIGNUM *h, const BIGNUM *zkpg, const JPAKE_STEP_PART *p,\n\t\t     const char *proof_name)\n    {\n    unsigned char md[SHA_DIGEST_LENGTH];\n    SHA_CTX sha;\n    SHA1_Init(&sha);\n    hashbn(&sha, zkpg);\n    OPENSSL_assert(!BN_is_zero(p->zkpx.gr));\n    hashbn(&sha, p->zkpx.gr);\n    hashbn(&sha, p->gx);\n    hashstring(&sha, proof_name);\n    SHA1_Final(md, &sha);\n    BN_bin2bn(md, SHA_DIGEST_LENGTH, h);\n    }', 'static void hashbn(SHA_CTX *sha, const BIGNUM *bn)\n    {\n    size_t l = BN_num_bytes(bn);\n    unsigned char *bin = OPENSSL_malloc(l);\n    hashlength(sha, l);\n    BN_bn2bin(bn, bin);\n    SHA1_Update(sha, bin, l);\n    OPENSSL_free(bin);\n    }', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tbn_check_top(a);\n\tn=i=BN_num_bytes(a);\n\twhile (i--)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}', 'int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received)\n    {\n    if(!verify_zkp(&received->p1, ctx->p.g, ctx))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X3_FAILED);\n\treturn 0;\n\t}\n    if(!verify_zkp(&received->p2, ctx->p.g, ctx))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X4_FAILED);\n\treturn 0;\n\t}\n    if(BN_is_one(received->p2.gx))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_ONE);\n\treturn 0;\n\t}\n    BN_copy(ctx->p.gxc, received->p1.gx);\n    BN_copy(ctx->p.gxd, received->p2.gx);\n    return 1;\n    }', 'static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg,\n\t\t      JPAKE_CTX *ctx)\n    {\n    BIGNUM *h = BN_new();\n    BIGNUM *t1 = BN_new();\n    BIGNUM *t2 = BN_new();\n    BIGNUM *t3 = BN_new();\n    int ret = 0;\n    zkp_hash(h, zkpg, p, ctx->p.peer_name);\n    BN_mod_exp(t1, zkpg, p->zkpx.b, ctx->p.p, ctx->ctx);\n    BN_mod_exp(t2, p->gx, h, ctx->p.p, ctx->ctx);\n    BN_mod_mul(t3, t1, t2, ctx->p.p, ctx->ctx);\n    if(BN_cmp(t3, p->zkpx.gr) == 0)\n\tret = 1;\n    else\n\tJPAKEerr(JPAKE_F_VERIFY_ZKP, JPAKE_R_ZKP_VERIFY_FAILED);\n    BN_free(t3);\n    BN_free(t2);\n    BN_free(t1);\n    BN_free(h);\n    return ret;\n    }']