diff options
Diffstat (limited to 'src/lib/libcrypto/pem/pem_seal.c')
| -rw-r--r-- | src/lib/libcrypto/pem/pem_seal.c | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c index b4b36df453..ae463a301d 100644 --- a/src/lib/libcrypto/pem/pem_seal.c +++ b/src/lib/libcrypto/pem/pem_seal.c | |||
| @@ -56,23 +56,18 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #ifndef OPENSSL_NO_RSA | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
| 61 | #include "evp.h" | 62 | #include <openssl/evp.h> |
| 62 | #include "rand.h" | 63 | #include <openssl/rand.h> |
| 63 | #include "objects.h" | 64 | #include <openssl/objects.h> |
| 64 | #include "x509.h" | 65 | #include <openssl/x509.h> |
| 65 | #include "pem.h" | 66 | #include <openssl/pem.h> |
| 66 | 67 | ||
| 67 | int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) | 68 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, |
| 68 | PEM_ENCODE_SEAL_CTX *ctx; | 69 | unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, |
| 69 | EVP_CIPHER *type; | 70 | int npubk) |
| 70 | EVP_MD *md_type; | ||
| 71 | unsigned char **ek; | ||
| 72 | int *ekl; | ||
| 73 | unsigned char *iv; | ||
| 74 | EVP_PKEY **pubk; | ||
| 75 | int npubk; | ||
| 76 | { | 71 | { |
| 77 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 72 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
| 78 | int ret= -1; | 73 | int ret= -1; |
| @@ -89,17 +84,20 @@ int npubk; | |||
| 89 | j=RSA_size(pubk[i]->pkey.rsa); | 84 | j=RSA_size(pubk[i]->pkey.rsa); |
| 90 | if (j > max) max=j; | 85 | if (j > max) max=j; |
| 91 | } | 86 | } |
| 92 | s=(char *)Malloc(max*2); | 87 | s=(char *)OPENSSL_malloc(max*2); |
| 93 | if (s == NULL) | 88 | if (s == NULL) |
| 94 | { | 89 | { |
| 95 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); | 90 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); |
| 96 | goto err; | 91 | goto err; |
| 97 | } | 92 | } |
| 98 | 93 | ||
| 99 | EVP_EncodeInit(&(ctx->encode)); | 94 | EVP_EncodeInit(&ctx->encode); |
| 100 | EVP_SignInit(&(ctx->md),md_type); | 95 | |
| 96 | EVP_MD_CTX_init(&ctx->md); | ||
| 97 | EVP_SignInit(&ctx->md,md_type); | ||
| 101 | 98 | ||
| 102 | ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk); | 99 | EVP_CIPHER_CTX_init(&ctx->cipher); |
| 100 | ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk); | ||
| 103 | if (!ret) goto err; | 101 | if (!ret) goto err; |
| 104 | 102 | ||
| 105 | /* base64 encode the keys */ | 103 | /* base64 encode the keys */ |
| @@ -113,23 +111,19 @@ int npubk; | |||
| 113 | 111 | ||
| 114 | ret=npubk; | 112 | ret=npubk; |
| 115 | err: | 113 | err: |
| 116 | if (s != NULL) Free(s); | 114 | if (s != NULL) OPENSSL_free(s); |
| 117 | memset(key,0,EVP_MAX_KEY_LENGTH); | 115 | memset(key,0,EVP_MAX_KEY_LENGTH); |
| 118 | return(ret); | 116 | return(ret); |
| 119 | } | 117 | } |
| 120 | 118 | ||
| 121 | void PEM_SealUpdate(ctx,out,outl,in,inl) | 119 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, |
| 122 | PEM_ENCODE_SEAL_CTX *ctx; | 120 | unsigned char *in, int inl) |
| 123 | unsigned char *out; | ||
| 124 | int *outl; | ||
| 125 | unsigned char *in; | ||
| 126 | int inl; | ||
| 127 | { | 121 | { |
| 128 | unsigned char buffer[1600]; | 122 | unsigned char buffer[1600]; |
| 129 | int i,j; | 123 | int i,j; |
| 130 | 124 | ||
| 131 | *outl=0; | 125 | *outl=0; |
| 132 | EVP_SignUpdate(&(ctx->md),in,inl); | 126 | EVP_SignUpdate(&ctx->md,in,inl); |
| 133 | for (;;) | 127 | for (;;) |
| 134 | { | 128 | { |
| 135 | if (inl <= 0) break; | 129 | if (inl <= 0) break; |
| @@ -137,8 +131,8 @@ int inl; | |||
| 137 | i=1200; | 131 | i=1200; |
| 138 | else | 132 | else |
| 139 | i=inl; | 133 | i=inl; |
| 140 | EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i); | 134 | EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i); |
| 141 | EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j); | 135 | EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j); |
| 142 | *outl+=j; | 136 | *outl+=j; |
| 143 | out+=j; | 137 | out+=j; |
| 144 | in+=i; | 138 | in+=i; |
| @@ -146,13 +140,8 @@ int inl; | |||
| 146 | } | 140 | } |
| 147 | } | 141 | } |
| 148 | 142 | ||
| 149 | int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) | 143 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl, |
| 150 | PEM_ENCODE_SEAL_CTX *ctx; | 144 | unsigned char *out, int *outl, EVP_PKEY *priv) |
| 151 | unsigned char *sig; | ||
| 152 | int *sigl; | ||
| 153 | unsigned char *out; | ||
| 154 | int *outl; | ||
| 155 | EVP_PKEY *priv; | ||
| 156 | { | 145 | { |
| 157 | unsigned char *s=NULL; | 146 | unsigned char *s=NULL; |
| 158 | int ret=0,j; | 147 | int ret=0,j; |
| @@ -165,27 +154,34 @@ EVP_PKEY *priv; | |||
| 165 | } | 154 | } |
| 166 | i=RSA_size(priv->pkey.rsa); | 155 | i=RSA_size(priv->pkey.rsa); |
| 167 | if (i < 100) i=100; | 156 | if (i < 100) i=100; |
| 168 | s=(unsigned char *)Malloc(i*2); | 157 | s=(unsigned char *)OPENSSL_malloc(i*2); |
| 169 | if (s == NULL) | 158 | if (s == NULL) |
| 170 | { | 159 | { |
| 171 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); | 160 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); |
| 172 | goto err; | 161 | goto err; |
| 173 | } | 162 | } |
| 174 | 163 | ||
| 175 | EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i); | 164 | EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i); |
| 176 | EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i); | 165 | EVP_EncodeUpdate(&ctx->encode,out,&j,s,i); |
| 177 | *outl=j; | 166 | *outl=j; |
| 178 | out+=j; | 167 | out+=j; |
| 179 | EVP_EncodeFinal(&(ctx->encode),out,&j); | 168 | EVP_EncodeFinal(&ctx->encode,out,&j); |
| 180 | *outl+=j; | 169 | *outl+=j; |
| 181 | 170 | ||
| 182 | if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err; | 171 | if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err; |
| 183 | *sigl=EVP_EncodeBlock(sig,s,i); | 172 | *sigl=EVP_EncodeBlock(sig,s,i); |
| 184 | 173 | ||
| 185 | ret=1; | 174 | ret=1; |
| 186 | err: | 175 | err: |
| 187 | memset((char *)&(ctx->md),0,sizeof(ctx->md)); | 176 | EVP_MD_CTX_cleanup(&ctx->md); |
| 188 | memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher)); | 177 | EVP_CIPHER_CTX_cleanup(&ctx->cipher); |
| 189 | if (s != NULL) Free(s); | 178 | if (s != NULL) OPENSSL_free(s); |
| 190 | return(ret); | 179 | return(ret); |
| 191 | } | 180 | } |
| 181 | #else /* !OPENSSL_NO_RSA */ | ||
| 182 | |||
| 183 | # if PEDANTIC | ||
| 184 | static void *dummy=&dummy; | ||
| 185 | # endif | ||
| 186 | |||
| 187 | #endif | ||
