summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem/pem_seal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pem/pem_seal.c')
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 2a6c513348..ae463a301d 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA 59#ifndef OPENSSL_NO_RSA
60#include <stdio.h> 60#include <stdio.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/evp.h> 62#include <openssl/evp.h>
@@ -91,10 +91,13 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
91 goto err; 91 goto err;
92 } 92 }
93 93
94 EVP_EncodeInit(&(ctx->encode)); 94 EVP_EncodeInit(&ctx->encode);
95 EVP_SignInit(&(ctx->md),md_type);
96 95
97 ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk); 96 EVP_MD_CTX_init(&ctx->md);
97 EVP_SignInit(&ctx->md,md_type);
98
99 EVP_CIPHER_CTX_init(&ctx->cipher);
100 ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk);
98 if (!ret) goto err; 101 if (!ret) goto err;
99 102
100 /* base64 encode the keys */ 103 /* base64 encode the keys */
@@ -120,7 +123,7 @@ void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
120 int i,j; 123 int i,j;
121 124
122 *outl=0; 125 *outl=0;
123 EVP_SignUpdate(&(ctx->md),in,inl); 126 EVP_SignUpdate(&ctx->md,in,inl);
124 for (;;) 127 for (;;)
125 { 128 {
126 if (inl <= 0) break; 129 if (inl <= 0) break;
@@ -128,8 +131,8 @@ void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
128 i=1200; 131 i=1200;
129 else 132 else
130 i=inl; 133 i=inl;
131 EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i); 134 EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i);
132 EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j); 135 EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j);
133 *outl+=j; 136 *outl+=j;
134 out+=j; 137 out+=j;
135 in+=i; 138 in+=i;
@@ -158,24 +161,24 @@ int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
158 goto err; 161 goto err;
159 } 162 }
160 163
161 EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i); 164 EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i);
162 EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i); 165 EVP_EncodeUpdate(&ctx->encode,out,&j,s,i);
163 *outl=j; 166 *outl=j;
164 out+=j; 167 out+=j;
165 EVP_EncodeFinal(&(ctx->encode),out,&j); 168 EVP_EncodeFinal(&ctx->encode,out,&j);
166 *outl+=j; 169 *outl+=j;
167 170
168 if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err; 171 if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err;
169 *sigl=EVP_EncodeBlock(sig,s,i); 172 *sigl=EVP_EncodeBlock(sig,s,i);
170 173
171 ret=1; 174 ret=1;
172err: 175err:
173 memset((char *)&(ctx->md),0,sizeof(ctx->md)); 176 EVP_MD_CTX_cleanup(&ctx->md);
174 memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher)); 177 EVP_CIPHER_CTX_cleanup(&ctx->cipher);
175 if (s != NULL) OPENSSL_free(s); 178 if (s != NULL) OPENSSL_free(s);
176 return(ret); 179 return(ret);
177 } 180 }
178#else /* !NO_RSA */ 181#else /* !OPENSSL_NO_RSA */
179 182
180# if PEDANTIC 183# if PEDANTIC
181static void *dummy=&dummy; 184static void *dummy=&dummy;