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)));
    assert(!overlapped);
    return overlapped;
}
['static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,\n                   pem_password_cb *cb, void *u)\n{\n    int outlen = 24, pklen;\n    unsigned char *p = NULL, *start = NULL, *salt = NULL;\n    EVP_CIPHER_CTX *cctx = NULL;\n    if (enclevel)\n        outlen += PVK_SALTLEN;\n    pklen = do_i2b(NULL, pk, 0);\n    if (pklen < 0)\n        return -1;\n    outlen += pklen;\n    if (out == NULL)\n        return outlen;\n    if (*out != NULL) {\n        p = *out;\n    } else {\n        start = p = OPENSSL_malloc(outlen);\n        if (p == NULL) {\n            PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);\n            return -1;\n        }\n    }\n    cctx = EVP_CIPHER_CTX_new();\n    if (cctx == NULL)\n        goto error;\n    write_ledword(&p, MS_PVKMAGIC);\n    write_ledword(&p, 0);\n    if (EVP_PKEY_id(pk) == EVP_PKEY_DSA)\n        write_ledword(&p, MS_KEYTYPE_SIGN);\n    else\n        write_ledword(&p, MS_KEYTYPE_KEYX);\n    write_ledword(&p, enclevel ? 1 : 0);\n    write_ledword(&p, enclevel ? PVK_SALTLEN : 0);\n    write_ledword(&p, pklen);\n    if (enclevel) {\n        if (RAND_bytes(p, PVK_SALTLEN) <= 0)\n            goto error;\n        salt = p;\n        p += PVK_SALTLEN;\n    }\n    do_i2b(&p, pk, 0);\n    if (enclevel != 0) {\n        char psbuf[PEM_BUFSIZE];\n        unsigned char keybuf[20];\n        int enctmplen, inlen;\n        if (cb)\n            inlen = cb(psbuf, PEM_BUFSIZE, 1, u);\n        else\n            inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u);\n        if (inlen <= 0) {\n            PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ);\n            goto error;\n        }\n        if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,\n                            (unsigned char *)psbuf, inlen))\n            goto error;\n        if (enclevel == 1)\n            memset(keybuf + 5, 0, 11);\n        p = salt + PVK_SALTLEN + 8;\n        if (!EVP_EncryptInit_ex(cctx, EVP_rc4(), NULL, keybuf, NULL))\n            goto error;\n        OPENSSL_cleanse(keybuf, 20);\n        if (!EVP_DecryptUpdate(cctx, p, &enctmplen, p, pklen - 8))\n            goto error;\n        if (!EVP_DecryptFinal_ex(cctx, p + enctmplen, &enctmplen))\n            goto error;\n    }\n    EVP_CIPHER_CTX_free(cctx);\n    if (*out == NULL)\n        *out = start;\n    return outlen;\n error:\n    EVP_CIPHER_CTX_free(cctx);\n    if (*out == NULL)\n        OPENSSL_free(start);\n    return -1;\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;\n    unsigned int b;\n    b = ctx->cipher->block_size;\n    if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n        if (b == 1 && is_partially_overlapping(out, in, inl)) {\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_EncryptUpdate(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_EncryptUpdate(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    assert(!overlapped);\n    return overlapped;\n}']