void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len)
{
    CRYPTO_gcm128_finish(ctx, NULL, 0);
    memcpy(tag, ctx->Xi.c,
           len <= sizeof(ctx->Xi.c) ? len : sizeof(ctx->Xi.c));
}
['static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,\n                          const unsigned char *in, size_t len)\n{\n    EVP_AES_GCM_CTX *gctx = EVP_C_DATA(EVP_AES_GCM_CTX,ctx);\n    if (!gctx->key_set)\n        return -1;\n    if (gctx->tls_aad_len >= 0)\n        return aes_gcm_tls_cipher(ctx, out, in, len);\n    if (!gctx->iv_set)\n        return -1;\n    if (in) {\n        if (out == NULL) {\n            if (CRYPTO_gcm128_aad(&gctx->gcm, in, len))\n                return -1;\n        } else if (EVP_CIPHER_CTX_encrypting(ctx)) {\n            if (gctx->ctr) {\n                size_t bulk = 0;\n# if defined(AES_GCM_ASM)\n                if (len >= 32 && AES_GCM_ASM(gctx)) {\n                    size_t res = (16 - gctx->gcm.mres) % 16;\n                    if (CRYPTO_gcm128_encrypt(&gctx->gcm, in, out, res))\n                        return -1;\n                    bulk = AES_gcm_encrypt(in + res,\n                                           out + res, len - res,\n                                           gctx->gcm.key, gctx->gcm.Yi.c,\n                                           gctx->gcm.Xi.u);\n                    gctx->gcm.len.u[1] += bulk;\n                    bulk += res;\n                }\n# endif\n                if (CRYPTO_gcm128_encrypt_ctr32(&gctx->gcm,\n                                                in + bulk,\n                                                out + bulk,\n                                                len - bulk, gctx->ctr))\n                    return -1;\n            } else {\n                size_t bulk = 0;\n# if defined(AES_GCM_ASM2)\n                if (len >= 32 && AES_GCM_ASM2(gctx)) {\n                    size_t res = (16 - gctx->gcm.mres) % 16;\n                    if (CRYPTO_gcm128_encrypt(&gctx->gcm, in, out, res))\n                        return -1;\n                    bulk = AES_gcm_encrypt(in + res,\n                                           out + res, len - res,\n                                           gctx->gcm.key, gctx->gcm.Yi.c,\n                                           gctx->gcm.Xi.u);\n                    gctx->gcm.len.u[1] += bulk;\n                    bulk += res;\n                }\n# endif\n                if (CRYPTO_gcm128_encrypt(&gctx->gcm,\n                                          in + bulk, out + bulk, len - bulk))\n                    return -1;\n            }\n        } else {\n            if (gctx->ctr) {\n                size_t bulk = 0;\n# if defined(AES_GCM_ASM)\n                if (len >= 16 && AES_GCM_ASM(gctx)) {\n                    size_t res = (16 - gctx->gcm.mres) % 16;\n                    if (CRYPTO_gcm128_decrypt(&gctx->gcm, in, out, res))\n                        return -1;\n                    bulk = AES_gcm_decrypt(in + res,\n                                           out + res, len - res,\n                                           gctx->gcm.key,\n                                           gctx->gcm.Yi.c, gctx->gcm.Xi.u);\n                    gctx->gcm.len.u[1] += bulk;\n                    bulk += res;\n                }\n# endif\n                if (CRYPTO_gcm128_decrypt_ctr32(&gctx->gcm,\n                                                in + bulk,\n                                                out + bulk,\n                                                len - bulk, gctx->ctr))\n                    return -1;\n            } else {\n                size_t bulk = 0;\n# if defined(AES_GCM_ASM2)\n                if (len >= 16 && AES_GCM_ASM2(gctx)) {\n                    size_t res = (16 - gctx->gcm.mres) % 16;\n                    if (CRYPTO_gcm128_decrypt(&gctx->gcm, in, out, res))\n                        return -1;\n                    bulk = AES_gcm_decrypt(in + res,\n                                           out + res, len - res,\n                                           gctx->gcm.key,\n                                           gctx->gcm.Yi.c, gctx->gcm.Xi.u);\n                    gctx->gcm.len.u[1] += bulk;\n                    bulk += res;\n                }\n# endif\n                if (CRYPTO_gcm128_decrypt(&gctx->gcm,\n                                          in + bulk, out + bulk, len - bulk))\n                    return -1;\n            }\n        }\n        return len;\n    } else {\n        if (!EVP_CIPHER_CTX_encrypting(ctx)) {\n            if (gctx->taglen < 0)\n                return -1;\n            if (CRYPTO_gcm128_finish(&gctx->gcm,\n                                     EVP_CIPHER_CTX_buf_noconst(ctx),\n                                     gctx->taglen) != 0)\n                return -1;\n            gctx->iv_set = 0;\n            return 0;\n        }\n        CRYPTO_gcm128_tag(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx), 16);\n        gctx->taglen = 16;\n        gctx->iv_set = 0;\n        return 0;\n    }\n}', 'void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len)\n{\n    CRYPTO_gcm128_finish(ctx, NULL, 0);\n    memcpy(tag, ctx->Xi.c,\n           len <= sizeof(ctx->Xi.c) ? len : sizeof(ctx->Xi.c));\n}', 'int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag,\n                         size_t len)\n{\n    const union {\n        long one;\n        char little;\n    } is_endian = { 1 };\n    u64 alen = ctx->len.u[0] << 3;\n    u64 clen = ctx->len.u[1] << 3;\n#ifdef GCM_FUNCREF_4BIT\n    void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult;\n#endif\n    if (ctx->mres || ctx->ares)\n        GCM_MUL(ctx, Xi);\n    if (is_endian.little) {\n#ifdef BSWAP8\n        alen = BSWAP8(alen);\n        clen = BSWAP8(clen);\n#else\n        u8 *p = ctx->len.c;\n        ctx->len.u[0] = alen;\n        ctx->len.u[1] = clen;\n        alen = (u64)GETU32(p) << 32 | GETU32(p + 4);\n        clen = (u64)GETU32(p + 8) << 32 | GETU32(p + 12);\n#endif\n    }\n    ctx->Xi.u[0] ^= alen;\n    ctx->Xi.u[1] ^= clen;\n    GCM_MUL(ctx, Xi);\n    ctx->Xi.u[0] ^= ctx->EK0.u[0];\n    ctx->Xi.u[1] ^= ctx->EK0.u[1];\n    if (tag && len <= sizeof(ctx->Xi))\n        return CRYPTO_memcmp(ctx->Xi.c, tag, len);\n    else\n        return -1;\n}']