crypto/modes/gcm128.c:1661: error: BUFFER_OVERRUN_L3
  Offset added: 16 Size: [0, +oo].
Showing all 3 steps of the trace


crypto/modes/gcm128.c:1623:1: <Length trace>
1621.   }
1622.   
1623. > int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
1624.                                   const unsigned char *in, unsigned char *out,
1625.                                   size_t len, ctr128_f stream)

crypto/modes/gcm128.c:1623:1: Parameter `ctx->Xn[*]`
1621.   }
1622.   
1623. > int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
1624.                                   const unsigned char *in, unsigned char *out,
1625.                                   size_t len, ctr128_f stream)

crypto/modes/gcm128.c:1661:9: Array access: Offset added: 16 Size: [0, +oo]
1659.               return 0;
1660.           }
1661.           memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));
                ^
1662.           ctx->Xi.u[0] = 0;
1663.           ctx->Xi.u[1] = 0;

int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
                                const unsigned char *in, unsigned char *out,
                                size_t len, ctr128_f stream)
{
#if defined(OPENSSL_SMALL_FOOTPRINT)
    return CRYPTO_gcm128_decrypt(ctx, in, out, len);
#else
    const union {
        long one;
        char little;
    } is_endian = { 1 };
    unsigned int n, ctr, mres;
    size_t i;
    u64 mlen = ctx->len.u[1];
    void *key = ctx->key;
# ifdef GCM_FUNCREF_4BIT
    void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult;
#  ifdef GHASH
    void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16],
                         const u8 *inp, size_t len) = ctx->ghash;
#  endif
# endif
    mlen += len;
    if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len))
        return -1;
    ctx->len.u[1] = mlen;
    mres = ctx->mres;
    if (ctx->ares) {
# if defined(GHASH)
        if (len == 0) {
            GCM_MUL(ctx);
            ctx->ares = 0;
            return 0;
        }
        memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));
        ctx->Xi.u[0] = 0;
        ctx->Xi.u[1] = 0;
        mres = sizeof(ctx->Xi);
# else
        GCM_MUL(ctx);
# endif
        ctx->ares = 0;
    }
    if (is_endian.little)
# ifdef BSWAP4
        ctr = BSWAP4(ctx->Yi.d[3]);
# else
        ctr = GETU32(ctx->Yi.c + 12);
# endif
    else
        ctr = ctx->Yi.d[3];
    n = mres % 16;
    if (n) {
# if defined(GHASH)
        while (n && len) {
            *(out++) = (ctx->Xn[mres++] = *(in++)) ^ ctx->EKi.c[n];
            --len;
            n = (n + 1) % 16;
        }
        if (n == 0) {
            GHASH(ctx, ctx->Xn, mres);
            mres = 0;
        } else {
            ctx->mres = mres;
            return 0;
        }
# else
        while (n && len) {
            u8 c = *(in++);
            *(out++) = c ^ ctx->EKi.c[n];
            ctx->Xi.c[n] ^= c;
            --len;
            n = (n + 1) % 16;
        }
        if (n == 0) {
            GCM_MUL(ctx);
            mres = 0;
        } else {
            ctx->mres = n;
            return 0;
        }
# endif
    }
# if defined(GHASH)
    if (len >= 16 && mres) {
        GHASH(ctx, ctx->Xn, mres);
        mres = 0;
    }
#  if defined(GHASH_CHUNK)
    while (len >= GHASH_CHUNK) {
        GHASH(ctx, in, GHASH_CHUNK);
        (*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c);
        ctr += GHASH_CHUNK / 16;
        if (is_endian.little)
#   ifdef BSWAP4
            ctx->Yi.d[3] = BSWAP4(ctr);
#   else
            PUTU32(ctx->Yi.c + 12, ctr);
#   endif
        else
            ctx->Yi.d[3] = ctr;
        out += GHASH_CHUNK;
        in += GHASH_CHUNK;
        len -= GHASH_CHUNK;
    }
#  endif
# endif
    if ((i = (len & (size_t)-16))) {
        size_t j = i / 16;
# if defined(GHASH)
        GHASH(ctx, in, i);
# else
        while (j--) {
            size_t k;
            for (k = 0; k < 16; ++k)
                ctx->Xi.c[k] ^= in[k];
            GCM_MUL(ctx);
            in += 16;
        }
        j = i / 16;
        in -= i;
# endif
        (*stream) (in, out, j, key, ctx->Yi.c);
        ctr += (unsigned int)j;
        if (is_endian.little)
# ifdef BSWAP4
            ctx->Yi.d[3] = BSWAP4(ctr);
# else
            PUTU32(ctx->Yi.c + 12, ctr);
# endif
        else
            ctx->Yi.d[3] = ctr;
        out += i;
        in += i;
        len -= i;
    }
    if (len) {
        (*ctx->block) (ctx->Yi.c, ctx->EKi.c, key);
        ++ctr;
        if (is_endian.little)
# ifdef BSWAP4
            ctx->Yi.d[3] = BSWAP4(ctr);
# else
            PUTU32(ctx->Yi.c + 12, ctr);
# endif
        else
            ctx->Yi.d[3] = ctr;
        while (len--) {
# if defined(GHASH)
            out[n] = (ctx->Xn[mres++] = in[n]) ^ ctx->EKi.c[n];
# else
            u8 c = in[n];
            ctx->Xi.c[mres++] ^= c;
            out[n] = c ^ ctx->EKi.c[n];
# endif
            ++n;
        }
    }
    ctx->mres = mres;
    return 0;
#endif
}
['int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,\n                                const unsigned char *in, unsigned char *out,\n                                size_t len, ctr128_f stream)\n{\n#if defined(OPENSSL_SMALL_FOOTPRINT)\n    return CRYPTO_gcm128_decrypt(ctx, in, out, len);\n#else\n    const union {\n        long one;\n        char little;\n    } is_endian = { 1 };\n    unsigned int n, ctr, mres;\n    size_t i;\n    u64 mlen = ctx->len.u[1];\n    void *key = ctx->key;\n# ifdef GCM_FUNCREF_4BIT\n    void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult;\n#  ifdef GHASH\n    void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16],\n                         const u8 *inp, size_t len) = ctx->ghash;\n#  endif\n# endif\n    mlen += len;\n    if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len))\n        return -1;\n    ctx->len.u[1] = mlen;\n    mres = ctx->mres;\n    if (ctx->ares) {\n# if defined(GHASH)\n        if (len == 0) {\n            GCM_MUL(ctx);\n            ctx->ares = 0;\n            return 0;\n        }\n        memcpy(ctx->Xn, ctx->Xi.c, sizeof(ctx->Xi));\n        ctx->Xi.u[0] = 0;\n        ctx->Xi.u[1] = 0;\n        mres = sizeof(ctx->Xi);\n# else\n        GCM_MUL(ctx);\n# endif\n        ctx->ares = 0;\n    }\n    if (is_endian.little)\n# ifdef BSWAP4\n        ctr = BSWAP4(ctx->Yi.d[3]);\n# else\n        ctr = GETU32(ctx->Yi.c + 12);\n# endif\n    else\n        ctr = ctx->Yi.d[3];\n    n = mres % 16;\n    if (n) {\n# if defined(GHASH)\n        while (n && len) {\n            *(out++) = (ctx->Xn[mres++] = *(in++)) ^ ctx->EKi.c[n];\n            --len;\n            n = (n + 1) % 16;\n        }\n        if (n == 0) {\n            GHASH(ctx, ctx->Xn, mres);\n            mres = 0;\n        } else {\n            ctx->mres = mres;\n            return 0;\n        }\n# else\n        while (n && len) {\n            u8 c = *(in++);\n            *(out++) = c ^ ctx->EKi.c[n];\n            ctx->Xi.c[n] ^= c;\n            --len;\n            n = (n + 1) % 16;\n        }\n        if (n == 0) {\n            GCM_MUL(ctx);\n            mres = 0;\n        } else {\n            ctx->mres = n;\n            return 0;\n        }\n# endif\n    }\n# if defined(GHASH)\n    if (len >= 16 && mres) {\n        GHASH(ctx, ctx->Xn, mres);\n        mres = 0;\n    }\n#  if defined(GHASH_CHUNK)\n    while (len >= GHASH_CHUNK) {\n        GHASH(ctx, in, GHASH_CHUNK);\n        (*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c);\n        ctr += GHASH_CHUNK / 16;\n        if (is_endian.little)\n#   ifdef BSWAP4\n            ctx->Yi.d[3] = BSWAP4(ctr);\n#   else\n            PUTU32(ctx->Yi.c + 12, ctr);\n#   endif\n        else\n            ctx->Yi.d[3] = ctr;\n        out += GHASH_CHUNK;\n        in += GHASH_CHUNK;\n        len -= GHASH_CHUNK;\n    }\n#  endif\n# endif\n    if ((i = (len & (size_t)-16))) {\n        size_t j = i / 16;\n# if defined(GHASH)\n        GHASH(ctx, in, i);\n# else\n        while (j--) {\n            size_t k;\n            for (k = 0; k < 16; ++k)\n                ctx->Xi.c[k] ^= in[k];\n            GCM_MUL(ctx);\n            in += 16;\n        }\n        j = i / 16;\n        in -= i;\n# endif\n        (*stream) (in, out, j, key, ctx->Yi.c);\n        ctr += (unsigned int)j;\n        if (is_endian.little)\n# ifdef BSWAP4\n            ctx->Yi.d[3] = BSWAP4(ctr);\n# else\n            PUTU32(ctx->Yi.c + 12, ctr);\n# endif\n        else\n            ctx->Yi.d[3] = ctr;\n        out += i;\n        in += i;\n        len -= i;\n    }\n    if (len) {\n        (*ctx->block) (ctx->Yi.c, ctx->EKi.c, key);\n        ++ctr;\n        if (is_endian.little)\n# ifdef BSWAP4\n            ctx->Yi.d[3] = BSWAP4(ctr);\n# else\n            PUTU32(ctx->Yi.c + 12, ctr);\n# endif\n        else\n            ctx->Yi.d[3] = ctr;\n        while (len--) {\n# if defined(GHASH)\n            out[n] = (ctx->Xn[mres++] = in[n]) ^ ctx->EKi.c[n];\n# else\n            u8 c = in[n];\n            ctx->Xi.c[mres++] ^= c;\n            out[n] = c ^ ctx->EKi.c[n];\n# endif\n            ++n;\n        }\n    }\n    ctx->mres = mres;\n    return 0;\n#endif\n}']