int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)
{
    PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;
    int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
                                                (diff > (0 - (PTRDIFF_T)len)));
    return overlapped;
}
['X509 *OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert(OSSL_CRMF_ENCRYPTEDVALUE *ecert,\n                                            EVP_PKEY *pkey)\n{\n    X509 *cert = NULL;\n    EVP_CIPHER_CTX *evp_ctx = NULL;\n    unsigned char *ek = NULL;\n    const EVP_CIPHER *cipher = NULL;\n    unsigned char *iv = NULL;\n    unsigned char *outbuf = NULL;\n    const unsigned char *p = NULL;\n    int symmAlg = 0;\n    int n, outlen = 0;\n    EVP_PKEY_CTX *pkctx = NULL;\n    if (ecert == NULL || ecert->symmAlg == NULL || ecert->encSymmKey == NULL\n            || ecert->encValue == NULL || pkey == NULL) {\n        CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                CRMF_R_NULL_ARGUMENT);\n        return NULL;\n    }\n    if ((symmAlg = OBJ_obj2nid(ecert->symmAlg->algorithm)) == 0) {\n        CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                CRMF_R_UNSUPPORTED_CIPHER);\n        return NULL;\n    }\n    pkctx = EVP_PKEY_CTX_new(pkey, NULL);\n    if (pkctx != NULL && EVP_PKEY_decrypt_init(pkctx)) {\n        ASN1_BIT_STRING *encKey = ecert->encSymmKey;\n        size_t eksize = 0;\n        if (EVP_PKEY_decrypt(pkctx, NULL, &eksize, encKey->data, encKey->length)\n                <= 0\n                || (ek = OPENSSL_malloc(eksize)) == NULL\n                || EVP_PKEY_decrypt(pkctx, ek, &eksize, encKey->data,\n                                    encKey->length) <= 0) {\n            CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                    CRMF_R_ERROR_DECRYPTING_SYMMETRIC_KEY);\n            goto end;\n        }\n    } else {\n        goto oom;\n    }\n    if ((cipher = EVP_get_cipherbynid(symmAlg)) == NULL) {\n        CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                CRMF_R_UNSUPPORTED_CIPHER);\n        goto end;\n    }\n    if ((iv = OPENSSL_malloc(EVP_CIPHER_iv_length(cipher))) == NULL)\n        goto oom;\n    if (ASN1_TYPE_get_octetstring(ecert->symmAlg->parameter, iv,\n                                   EVP_CIPHER_iv_length(cipher))\n        != EVP_CIPHER_iv_length(cipher)) {\n        CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                CRMF_R_MALFORMED_IV);\n        goto end;\n    }\n    if ((p = outbuf = OPENSSL_malloc(ecert->encValue->length +\n                                     EVP_CIPHER_block_size(cipher))) == NULL\n            || (evp_ctx = EVP_CIPHER_CTX_new()) == NULL)\n        goto oom;\n    EVP_CIPHER_CTX_set_padding(evp_ctx, 0);\n    if (!EVP_DecryptInit(evp_ctx, cipher, ek, iv)\n            || !EVP_DecryptUpdate(evp_ctx, outbuf, &outlen,\n                                  ecert->encValue->data,\n                                  ecert->encValue->length)\n            || !EVP_DecryptFinal(evp_ctx, outbuf + outlen, &n)) {\n        CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                CRMF_R_ERROR_DECRYPTING_CERTIFICATE);\n        goto end;\n    }\n    outlen += n;\n    if ((cert = d2i_X509(NULL, &p, outlen)) == NULL) {\n        CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT,\n                CRMF_R_ERROR_DECODING_CERTIFICATE);\n    }\n    goto end;\n oom:\n    CRMFerr(CRMF_F_OSSL_CRMF_ENCRYPTEDVALUE_GET1_ENCCERT, ERR_R_MALLOC_FAILURE);\n end:\n    EVP_PKEY_CTX_free(pkctx);\n    OPENSSL_free(outbuf);\n    EVP_CIPHER_CTX_free(evp_ctx);\n    OPENSSL_free(ek);\n    OPENSSL_free(iv);\n    return cert;\n}', 'int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n                      const unsigned char *in, int inl)\n{\n    int fix_len, cmpl = inl;\n    unsigned int b;\n    if (ctx->encrypt) {\n        EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_INVALID_OPERATION);\n        return 0;\n    }\n    b = ctx->cipher->block_size;\n    if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))\n        cmpl = (cmpl + 7) / 8;\n    if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n        if (b == 1 && is_partially_overlapping(out, in, cmpl)) {\n            EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n            return 0;\n        }\n        fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);\n        if (fix_len < 0) {\n            *outl = 0;\n            return 0;\n        } else\n            *outl = fix_len;\n        return 1;\n    }\n    if (inl <= 0) {\n        *outl = 0;\n        return inl == 0;\n    }\n    if (ctx->flags & EVP_CIPH_NO_PADDING)\n        return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);\n    OPENSSL_assert(b <= sizeof(ctx->final));\n    if (ctx->final_used) {\n        if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n            || is_partially_overlapping(out, in, b)) {\n            EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n            return 0;\n        }\n        memcpy(out, ctx->final, b);\n        out += b;\n        fix_len = 1;\n    } else\n        fix_len = 0;\n    if (!evp_EncryptDecryptUpdate(ctx, out, outl, in, inl))\n        return 0;\n    if (b > 1 && !ctx->buf_len) {\n        *outl -= b;\n        ctx->final_used = 1;\n        memcpy(ctx->final, &out[*outl], b);\n    } else\n        ctx->final_used = 0;\n    if (fix_len)\n        *outl += b;\n    return 1;\n}', 'int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)\n{\n    PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n    int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n                                                (diff > (0 - (PTRDIFF_T)len)));\n    return overlapped;\n}']