engines/ccgost/gost2001_keyx.c:44: error: BUFFER_OVERRUN_L3
  Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `BN_mod_mul`.
Showing all 17 steps of the trace


engines/ccgost/gost2001_keyx.c:38:11: Call
36.       }
37.       BN_CTX_start(ctx);
38.       UKM = BN_bin2bn(ukm_be, 8, NULL);
                ^
39.       p = BN_CTX_get(ctx);
40.       order = BN_CTX_get(ctx);

crypto/bn/bn_lib.c:542:1: Parameter `ret->top`
  540.   }
  541.   
  542. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  543.   {
  544.       unsigned int i, m;

engines/ccgost/gost2001_keyx.c:44:5: Call
42.       Y = BN_CTX_get(ctx);
43.       EC_GROUP_get_order(EC_KEY_get0_group(priv_key), order, ctx);
44.       BN_mod_mul(p, key, UKM, order, ctx);
          ^
45.       EC_POINT_mul(EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx);
46.       EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key),

crypto/bn/bn_mod.c:179:1: Parameter `a->top`
  177.   
  178.   /* slow but works */
  179. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  180.                  BN_CTX *ctx)
  181.   {

crypto/bn/bn_mod.c:193:14: Call
  191.           goto err;
  192.       if (a == b) {
  193.           if (!BN_sqr(t, a, ctx))
                      ^
  194.               goto err;
  195.       } else {

crypto/bn/bn_sqr.c:66:1: Parameter `a->top`
    64.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
    65.    */
    66. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
    67.   {
    68.       int max, al;

crypto/bn/bn_sqr.c:74:5: Assignment
    72.       bn_check_top(a);
    73.   
    74.       al = a->top;
              ^
    75.       if (al <= 0) {
    76.           r->top = 0;

crypto/bn/bn_sqr.c:123:17: Call
    121.                   if (bn_wexpand(tmp, max) == NULL)
    122.                       goto err;
    123.                   bn_sqr_normal(rr->d, a->d, al, tmp->d);
                           ^
    124.               }
    125.           }

crypto/bn/bn_sqr.c:153:1: <Offset trace>
151.   
152.   /* tmp must have 2*n words */
153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
154.   {
155.       int i, j, max;

crypto/bn/bn_sqr.c:153:1: Parameter `n`
      151.   
      152.   /* tmp must have 2*n words */
      153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
      154.   {
      155.       int i, j, max;

crypto/bn/bn_sqr.c:164:5: Assignment
      162.       rp[0] = rp[max - 1] = 0;
      163.       rp++;
      164.       j = n;
                 ^
      165.   
      166.       if (--j > 0) {

crypto/bn/bn_sqr.c:166:9: Assignment
      164.       j = n;
      165.   
      166.       if (--j > 0) {
                     ^
      167.           ap++;
      168.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);

crypto/bn/bn_sqr.c:153:1: <Length trace>
151.   
152.   /* tmp must have 2*n words */
153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
154.   {
155.       int i, j, max;

crypto/bn/bn_sqr.c:153:1: Parameter `*r`
      151.   
      152.   /* tmp must have 2*n words */
      153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
      154.   {
      155.       int i, j, max;

crypto/bn/bn_sqr.c:161:5: Assignment
      159.       max = n * 2;
      160.       ap = a;
      161.       rp = r;
                 ^
      162.       rp[0] = rp[max - 1] = 0;
      163.       rp++;

crypto/bn/bn_sqr.c:163:5: Assignment
      161.       rp = r;
      162.       rp[0] = rp[max - 1] = 0;
      163.       rp++;
                 ^
      164.       j = n;
      165.   

crypto/bn/bn_sqr.c:168:9: Array access: Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `BN_mod_mul` 
      166.       if (--j > 0) {
      167.           ap++;
      168.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
                     ^
      169.           rp += 2;
      170.       }

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 VKO_compute_key(unsigned char *shared_key, size_t shared_key_size,\n                           const EC_POINT *pub_key, EC_KEY *priv_key,\n                           const unsigned char *ukm)\n{\n    unsigned char ukm_be[8], databuf[64], hashbuf[64];\n    BIGNUM *UKM = NULL, *p = NULL, *order = NULL, *X = NULL, *Y = NULL;\n    const BIGNUM *key = EC_KEY_get0_private_key(priv_key);\n    EC_POINT *pnt = EC_POINT_new(EC_KEY_get0_group(priv_key));\n    int i;\n    gost_hash_ctx hash_ctx;\n    BN_CTX *ctx = BN_CTX_new();\n    for (i = 0; i < 8; i++) {\n        ukm_be[7 - i] = ukm[i];\n    }\n    BN_CTX_start(ctx);\n    UKM = BN_bin2bn(ukm_be, 8, NULL);\n    p = BN_CTX_get(ctx);\n    order = BN_CTX_get(ctx);\n    X = BN_CTX_get(ctx);\n    Y = BN_CTX_get(ctx);\n    EC_GROUP_get_order(EC_KEY_get0_group(priv_key), order, ctx);\n    BN_mod_mul(p, key, UKM, order, ctx);\n    EC_POINT_mul(EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx);\n    EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key),\n                                        pnt, X, Y, ctx);\n    store_bignum(Y, databuf, 32);\n    store_bignum(X, databuf + 32, 32);\n    for (i = 0; i < 64; i++) {\n        hashbuf[63 - i] = databuf[i];\n    }\n    init_gost_hash_ctx(&hash_ctx, &GostR3411_94_CryptoProParamSet);\n    start_hash(&hash_ctx);\n    hash_block(&hash_ctx, hashbuf, 64);\n    finish_hash(&hash_ctx, shared_key);\n    done_gost_hash_ctx(&hash_ctx);\n    BN_free(UKM);\n    BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    EC_POINT_free(pnt);\n    return 32;\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}', '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 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 || !tmp)\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    if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n        rr->top = max - 1;\n    else\n        rr->top = max;\n    if (rr != r)\n        BN_copy(r, rr);\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}']