static int aes_wrap_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                           const unsigned char *in, size_t inlen)
{
    EVP_AES_WRAP_CTX *wctx = ctx->cipher_data;
    size_t rv;
    if (!in)
        return 0;
    if (inlen % 8)
        return -1;
    if (ctx->encrypt && inlen < 8)
        return -1;
    if (!ctx->encrypt && inlen < 16)
        return -1;
    if (!out) {
        if (ctx->encrypt)
            return inlen + 8;
        else
            return inlen - 8;
    }
    if (ctx->encrypt)
        rv = CRYPTO_128_wrap(&wctx->ks.ks, wctx->iv, out, in, inlen,
                             (block128_f) AES_encrypt);
    else
        rv = CRYPTO_128_unwrap(&wctx->ks.ks, wctx->iv, out, in, inlen,
                               (block128_f) AES_decrypt);
    return rv ? (int)rv : -1;
}
static int aes_wrap_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                           const unsigned char *in, size_t inlen)
{
    EVP_AES_WRAP_CTX *wctx = ctx->cipher_data;
    size_t rv;
    if (!in)
        return 0;
    if (inlen % 8)
        return -1;
    if (ctx->encrypt && inlen < 8)
        return -1;
    if (!ctx->encrypt && inlen < 16)
        return -1;
    if (!out) {
        if (ctx->encrypt)
            return inlen + 8;
        else
            return inlen - 8;
    }
    if (ctx->encrypt)
        rv = CRYPTO_128_wrap(&wctx->ks.ks, wctx->iv, out, in, inlen,
                             (block128_f) AES_encrypt);
    else
        rv = CRYPTO_128_unwrap(&wctx->ks.ks, wctx->iv, out, in, inlen,
                               (block128_f) AES_decrypt);
    return rv ? (int)rv : -1;
}