2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/rand.h>
13 #include <openssl/rsa.h>
14 #include <openssl/evp.h>
15 #include <openssl/objects.h>
16 #include <openssl/x509.h>
18 int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
19 unsigned char **ek, int *ekl, unsigned char *iv,
20 EVP_PKEY **pubk, int npubk)
22 unsigned char key[EVP_MAX_KEY_LENGTH];
26 EVP_CIPHER_CTX_reset(ctx);
27 if (!EVP_EncryptInit_ex(ctx, type, NULL, NULL, NULL))
30 if ((npubk <= 0) || !pubk)
32 if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0)
34 if (EVP_CIPHER_CTX_iv_length(ctx)
35 && RAND_bytes(iv, EVP_CIPHER_CTX_iv_length(ctx)) <= 0)
38 if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv))
41 for (i = 0; i < npubk; i++) {
43 EVP_PKEY_encrypt_old(ek[i], key, EVP_CIPHER_CTX_key_length(ctx),
52 void EVP_SealUpdate(ctx,out,outl,in,inl)
59 EVP_EncryptUpdate(ctx,out,outl,in,inl);
63 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
66 i = EVP_EncryptFinal_ex(ctx, out, outl);
68 i = EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, NULL);