/* crypto/evp/p_seal.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
#include <stdio.h>
#include "cryptlib.h"
-#include "rand.h"
-#include "rsa.h"
-#include "evp.h"
-#include "objects.h"
-#include "x509.h"
+#include <openssl/rand.h>
+#ifndef NO_RSA
+#include <openssl/rsa.h>
+#endif
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+#include <openssl/x509.h>
-int EVP_SealInit(ctx,type,ek,ekl,iv,pubk,npubk)
-EVP_CIPHER_CTX *ctx;
-EVP_CIPHER *type;
-unsigned char **ek;
-int *ekl;
-unsigned char *iv;
-EVP_PKEY **pubk;
-int npubk;
+int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
+ int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
- int i,ret=0,n;
+ int i;
+ if(type) {
+ EVP_CIPHER_CTX_init(ctx);
+ if(!EVP_EncryptInit(ctx,type,NULL,NULL)) return 0;
+ }
if (npubk <= 0) return(0);
- RAND_bytes(key,EVP_MAX_KEY_LENGTH);
- if (type->iv_len > 0)
- RAND_bytes(iv,type->iv_len);
+ if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
+ return(0);
+ if (EVP_CIPHER_CTX_iv_length(ctx))
+ RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx));
+
+ if(!EVP_EncryptInit(ctx,NULL,key,iv)) return 0;
- EVP_EncryptInit(ctx,type,key,iv);
for (i=0; i<npubk; i++)
{
- if (pubk[i]->type != EVP_PKEY_RSA)
- {
- EVPerr(EVP_F_EVP_SEALINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
- goto err;
- }
- n=RSA_public_encrypt(type->key_len,key,ek[i],pubk[i]->pkey.rsa,
- RSA_PKCS1_PADDING);
- if (n <= 0) goto err;
- ekl[i]=n;
+ ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_CTX_key_length(ctx),
+ pubk[i]);
+ if (ekl[i] <= 0) return(-1);
}
- ret=npubk;
-err:
- memset(key,0,EVP_MAX_KEY_LENGTH);
- return(ret);
+ return(npubk);
}
/* MACRO
}
*/
-void EVP_SealFinal(ctx,out,outl)
-EVP_CIPHER_CTX *ctx;
-unsigned char *out;
-int *outl;
+void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
{
EVP_EncryptFinal(ctx,out,outl);
EVP_EncryptInit(ctx,NULL,NULL,NULL);