test/srptest.c:62: error: BUFFER_OVERRUN_L3
  Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `SRP_Calc_B`.
Showing all 21 steps of the trace


test/srptest.c:56:9: Call
54.       /* Server random */
55.       RAND_bytes(rand_tmp, sizeof(rand_tmp));
56.       b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);
              ^
57.       if (!TEST_BN_ne_zero(b))
58.           goto end;

crypto/bn/bn_lib.c:389:9: Assignment
  387.       n = len;
  388.       if (n == 0) {
  389.           ret->top = 0;
                 ^
  390.           return ret;
  391.       }

test/srptest.c:62:12: Call
60.   
61.       /* Server's first message */
62.       Bpub = SRP_Calc_B(b, GN->N, GN->g, v);
                 ^
63.       test_output_bignum("B", Bpub);
64.   

crypto/srp/srp_lib.c:87:1: Parameter `v->top`
  85.   }
  86.   
  87. > BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
  88.                      const BIGNUM *v)
  89.   {

crypto/srp/srp_lib.c:106:13: Call
  104.       if (!BN_mod_exp(gb, g, b, N, bn_ctx)
  105.           || (k = srp_Calc_k(N, g)) == NULL
  106.           || !BN_mod_mul(kv, v, k, N, bn_ctx)
                     ^
  107.           || !BN_mod_add(B, gb, kv, N, bn_ctx)) {
  108.           BN_free(B);

crypto/bn/bn_mod.c:193:1: Parameter `a->top`
    191.   
    192.   /* slow but works */
    193. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
    194.                  BN_CTX *ctx)
    195.   {

crypto/bn/bn_mod.c:207:14: Call
    205.           goto err;
    206.       if (a == b) {
    207.           if (!BN_sqr(t, a, ctx))
                        ^
    208.               goto err;
    209.       } else {

crypto/bn/bn_sqr.c:17:1: Parameter `*r->d`
      15.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
      16.    */
      17. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int ret = bn_sqr_fixed_top(r, a, ctx);

crypto/bn/bn_sqr.c:19:15: Call
      17.   int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int ret = bn_sqr_fixed_top(r, a, ctx);
                          ^
      20.   
      21.       bn_correct_top(r);

crypto/bn/bn_sqr.c:27:1: Parameter `a->top`
        25.   }
        26.   
        27. > int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
        28.   {
        29.       int max, al;

crypto/bn/bn_sqr.c:35:5: Assignment
        33.       bn_check_top(a);
        34.   
        35.       al = a->top;
                  ^
        36.       if (al <= 0) {
        37.           r->top = 0;

crypto/bn/bn_sqr.c:84:17: Call
        82.                   if (bn_wexpand(tmp, max) == NULL)
        83.                       goto err;
        84.                   bn_sqr_normal(rr->d, a->d, al, tmp->d);
                              ^
        85.               }
        86.           }

crypto/bn/bn_sqr.c:109:1: <Offset trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `n`
          107.   
          108.   /* tmp must have 2*n words */
          109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
          110.   {
          111.       int i, j, max;

crypto/bn/bn_sqr.c:120:5: Assignment
          118.       rp[0] = rp[max - 1] = 0;
          119.       rp++;
          120.       j = n;
                     ^
          121.   
          122.       if (--j > 0) {

crypto/bn/bn_sqr.c:122:9: Assignment
          120.       j = n;
          121.   
          122.       if (--j > 0) {
                         ^
          123.           ap++;
          124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);

crypto/bn/bn_sqr.c:109:1: <Length trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `*r`
          107.   
          108.   /* tmp must have 2*n words */
          109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
          110.   {
          111.       int i, j, max;

crypto/bn/bn_sqr.c:117:5: Assignment
          115.       max = n * 2;
          116.       ap = a;
          117.       rp = r;
                     ^
          118.       rp[0] = rp[max - 1] = 0;
          119.       rp++;

crypto/bn/bn_sqr.c:119:5: Assignment
          117.       rp = r;
          118.       rp[0] = rp[max - 1] = 0;
          119.       rp++;
                     ^
          120.       j = n;
          121.   

crypto/bn/bn_sqr.c:124:9: Array access: Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `SRP_Calc_B` 
          122.       if (--j > 0) {
          123.           ap++;
          124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
                         ^
          125.           rp += 2;
          126.       }

void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
    int i, j, max;
    const BN_ULONG *ap;
    BN_ULONG *rp;
    max = n * 2;
    ap = a;
    rp = r;
    rp[0] = rp[max - 1] = 0;
    rp++;
    j = n;
    if (--j > 0) {
        ap++;
        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    for (i = n - 2; i > 0; i--) {
        j--;
        ap++;
        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    bn_add_words(r, r, r, max);
    bn_sqr_words(tmp, a, n);
    bn_add_words(r, r, tmp, max);
}
['static int run_srp(const char *username, const char *client_pass,\n                   const char *server_pass)\n{\n    int ret = 0;\n    BIGNUM *s = NULL;\n    BIGNUM *v = NULL;\n    BIGNUM *a = NULL;\n    BIGNUM *b = NULL;\n    BIGNUM *u = NULL;\n    BIGNUM *x = NULL;\n    BIGNUM *Apub = NULL;\n    BIGNUM *Bpub = NULL;\n    BIGNUM *Kclient = NULL;\n    BIGNUM *Kserver = NULL;\n    unsigned char rand_tmp[RANDOM_SIZE];\n    const SRP_gN *GN;\n    if (!TEST_ptr(GN = SRP_get_default_gN("1024")))\n        return 0;\n    if (!TEST_true(SRP_create_verifier_BN(username, server_pass,\n                                          &s, &v, GN->N, GN->g)))\n        goto end;\n    test_output_bignum("N", GN->N);\n    test_output_bignum("g", GN->g);\n    test_output_bignum("Salt", s);\n    test_output_bignum("Verifier", v);\n    RAND_bytes(rand_tmp, sizeof(rand_tmp));\n    b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);\n    if (!TEST_BN_ne_zero(b))\n        goto end;\n    test_output_bignum("b", b);\n    Bpub = SRP_Calc_B(b, GN->N, GN->g, v);\n    test_output_bignum("B", Bpub);\n    if (!TEST_true(SRP_Verify_B_mod_N(Bpub, GN->N)))\n        goto end;\n    RAND_bytes(rand_tmp, sizeof(rand_tmp));\n    a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);\n    if (!TEST_BN_ne_zero(a))\n        goto end;\n    test_output_bignum("a", a);\n    Apub = SRP_Calc_A(a, GN->N, GN->g);\n    test_output_bignum("A", Apub);\n    if (!TEST_true(SRP_Verify_A_mod_N(Apub, GN->N)))\n        goto end;\n    u = SRP_Calc_u(Apub, Bpub, GN->N);\n    x = SRP_Calc_x(s, username, client_pass);\n    Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u);\n    test_output_bignum("Client\'s key", Kclient);\n    Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N);\n    test_output_bignum("Server\'s key", Kserver);\n    if (!TEST_BN_eq(Kclient, Kserver))\n        goto end;\n    ret = 1;\nend:\n    BN_clear_free(Kclient);\n    BN_clear_free(Kserver);\n    BN_clear_free(x);\n    BN_free(u);\n    BN_free(Apub);\n    BN_clear_free(a);\n    BN_free(Bpub);\n    BN_clear_free(b);\n    BN_free(s);\n    BN_clear_free(v);\n    return ret;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return NULL;\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return ret;\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return ret;\n}', 'BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,\n                   const BIGNUM *v)\n{\n    BIGNUM *kv = NULL, *gb = NULL;\n    BIGNUM *B = NULL, *k = NULL;\n    BN_CTX *bn_ctx;\n    if (b == NULL || N == NULL || g == NULL || v == NULL ||\n        (bn_ctx = BN_CTX_new()) == NULL)\n        return NULL;\n    if ((kv = BN_new()) == NULL ||\n        (gb = BN_new()) == NULL || (B = BN_new()) == NULL)\n        goto err;\n    if (!BN_mod_exp(gb, g, b, N, bn_ctx)\n        || (k = srp_Calc_k(N, g)) == NULL\n        || !BN_mod_mul(kv, v, k, N, bn_ctx)\n        || !BN_mod_add(B, gb, kv, N, bn_ctx)) {\n        BN_free(B);\n        B = NULL;\n    }\n err:\n    BN_CTX_free(bn_ctx);\n    BN_clear_free(kv);\n    BN_clear_free(gb);\n    BN_free(k);\n    return B;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    BIGNUM *t;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(m);\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (a == b) {\n        if (!BN_sqr(t, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(t, a, b, ctx))\n            goto err;\n    }\n    if (!BN_nnmod(r, t, m, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int ret = bn_sqr_fixed_top(r, a, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (rr == NULL || tmp == NULL)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    rr->top = max;\n    rr->flags |= BN_FLG_FIXED_TOP;\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\n    ret = 1;\n err:\n    bn_check_top(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n    int i, j, max;\n    const BN_ULONG *ap;\n    BN_ULONG *rp;\n    max = n * 2;\n    ap = a;\n    rp = r;\n    rp[0] = rp[max - 1] = 0;\n    rp++;\n    j = n;\n    if (--j > 0) {\n        ap++;\n        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    for (i = n - 2; i > 0; i--) {\n        j--;\n        ap++;\n        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    bn_add_words(r, r, r, max);\n    bn_sqr_words(tmp, a, n);\n    bn_add_words(r, r, tmp, max);\n}']