diff options
Diffstat (limited to 'src/lib/libcrypto/evp/p_open.c')
| -rw-r--r-- | src/lib/libcrypto/evp/p_open.c | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c index b832ec6a6b..88c0a45544 100644 --- a/src/lib/libcrypto/evp/p_open.c +++ b/src/lib/libcrypto/evp/p_open.c | |||
| @@ -5,21 +5,21 @@ | |||
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,7 +49,7 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| @@ -66,57 +66,60 @@ | |||
| 66 | #include <openssl/x509.h> | 66 | #include <openssl/x509.h> |
| 67 | #include <openssl/rsa.h> | 67 | #include <openssl/rsa.h> |
| 68 | 68 | ||
| 69 | int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, | 69 | int |
| 70 | const unsigned char *ek, int ekl, const unsigned char *iv, | 70 | EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, |
| 71 | EVP_PKEY *priv) | 71 | const unsigned char *ek, int ekl, const unsigned char *iv, EVP_PKEY *priv) |
| 72 | { | 72 | { |
| 73 | unsigned char *key=NULL; | 73 | unsigned char *key = NULL; |
| 74 | int i,size=0,ret=0; | 74 | int i, size = 0, ret = 0; |
| 75 | 75 | ||
| 76 | if(type) { | 76 | if (type) { |
| 77 | EVP_CIPHER_CTX_init(ctx); | 77 | EVP_CIPHER_CTX_init(ctx); |
| 78 | if(!EVP_DecryptInit_ex(ctx,type,NULL, NULL,NULL)) return 0; | 78 | if (!EVP_DecryptInit_ex(ctx, type, NULL, NULL, NULL)) |
| 79 | return 0; | ||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | if(!priv) return 1; | 82 | if (!priv) |
| 83 | return 1; | ||
| 82 | 84 | ||
| 83 | if (priv->type != EVP_PKEY_RSA) | 85 | if (priv->type != EVP_PKEY_RSA) { |
| 84 | { | 86 | EVPerr(EVP_F_EVP_OPENINIT, EVP_R_PUBLIC_KEY_NOT_RSA); |
| 85 | EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
| 86 | goto err; | 87 | goto err; |
| 87 | } | 88 | } |
| 88 | 89 | ||
| 89 | size=RSA_size(priv->pkey.rsa); | 90 | size = RSA_size(priv->pkey.rsa); |
| 90 | key=(unsigned char *)malloc(size+2); | 91 | key = (unsigned char *)malloc(size + 2); |
| 91 | if (key == NULL) | 92 | if (key == NULL) { |
| 92 | { | ||
| 93 | /* ERROR */ | 93 | /* ERROR */ |
| 94 | EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE); | 94 | EVPerr(EVP_F_EVP_OPENINIT, ERR_R_MALLOC_FAILURE); |
| 95 | goto err; | 95 | goto err; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | i=EVP_PKEY_decrypt_old(key,ek,ekl,priv); | 98 | i = EVP_PKEY_decrypt_old(key, ek, ekl, priv); |
| 99 | if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i)) | 99 | if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i)) { |
| 100 | { | ||
| 101 | /* ERROR */ | 100 | /* ERROR */ |
| 102 | goto err; | 101 | goto err; |
| 103 | } | 102 | } |
| 104 | if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv)) goto err; | 103 | if (!EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv)) |
| 104 | goto err; | ||
| 105 | |||
| 106 | ret = 1; | ||
| 105 | 107 | ||
| 106 | ret=1; | ||
| 107 | err: | 108 | err: |
| 108 | if (key != NULL) OPENSSL_cleanse(key,size); | 109 | if (key != NULL) |
| 110 | OPENSSL_cleanse(key, size); | ||
| 109 | free(key); | 111 | free(key); |
| 110 | return(ret); | 112 | return (ret); |
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | 115 | int |
| 114 | { | 116 | EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) |
| 117 | { | ||
| 115 | int i; | 118 | int i; |
| 116 | 119 | ||
| 117 | i=EVP_DecryptFinal_ex(ctx,out,outl); | 120 | i = EVP_DecryptFinal_ex(ctx, out, outl); |
| 118 | if (i) | 121 | if (i) |
| 119 | i = EVP_DecryptInit_ex(ctx,NULL,NULL,NULL,NULL); | 122 | i = EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL); |
| 120 | return(i); | 123 | return (i); |
| 121 | } | 124 | } |
| 122 | #endif | 125 | #endif |
