diff options
author | jsing <> | 2014-05-07 17:42:51 +0000 |
---|---|---|
committer | jsing <> | 2014-05-07 17:42:51 +0000 |
commit | dd9b16d5489a1196ae0fcbe4315fe0122b042d7d (patch) | |
tree | b341b2cdc0818410f55d0a4662a40677e4899326 /src/lib/libcrypto/evp/p_seal.c | |
parent | 1b7393e13080fa69e951cc4f482e3d5d85639c70 (diff) | |
download | openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.tar.gz openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.tar.bz2 openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.zip |
KNF.
Diffstat (limited to 'src/lib/libcrypto/evp/p_seal.c')
-rw-r--r-- | src/lib/libcrypto/evp/p_seal.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c index e5919b0fbf..6147447290 100644 --- a/src/lib/libcrypto/evp/p_seal.c +++ b/src/lib/libcrypto/evp/p_seal.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,33 +66,36 @@ | |||
66 | #include <openssl/objects.h> | 66 | #include <openssl/objects.h> |
67 | #include <openssl/x509.h> | 67 | #include <openssl/x509.h> |
68 | 68 | ||
69 | int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, | 69 | int |
70 | int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk) | 70 | EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek, |
71 | { | 71 | int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk) |
72 | { | ||
72 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 73 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
73 | int i; | 74 | int i; |
74 | 75 | ||
75 | if(type) { | 76 | if (type) { |
76 | EVP_CIPHER_CTX_init(ctx); | 77 | EVP_CIPHER_CTX_init(ctx); |
77 | if(!EVP_EncryptInit_ex(ctx,type,NULL,NULL,NULL)) return 0; | 78 | if (!EVP_EncryptInit_ex(ctx, type, NULL, NULL, NULL)) |
79 | return 0; | ||
78 | } | 80 | } |
79 | if ((npubk <= 0) || !pubk) | 81 | if ((npubk <= 0) || !pubk) |
80 | return 1; | 82 | return 1; |
81 | if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) | 83 | if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) |
82 | return 0; | 84 | return 0; |
83 | if (EVP_CIPHER_CTX_iv_length(ctx)) | 85 | if (EVP_CIPHER_CTX_iv_length(ctx)) |
84 | RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx)); | 86 | RAND_pseudo_bytes(iv, EVP_CIPHER_CTX_iv_length(ctx)); |
85 | 87 | ||
86 | if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv)) return 0; | 88 | if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) |
89 | return 0; | ||
87 | 90 | ||
88 | for (i=0; i<npubk; i++) | 91 | for (i = 0; i < npubk; i++) { |
89 | { | 92 | ekl[i] = EVP_PKEY_encrypt_old(ek[i], key, |
90 | ekl[i]=EVP_PKEY_encrypt_old(ek[i],key,EVP_CIPHER_CTX_key_length(ctx), | 93 | EVP_CIPHER_CTX_key_length(ctx), pubk[i]); |
91 | pubk[i]); | 94 | if (ekl[i] <= 0) |
92 | if (ekl[i] <= 0) return(-1); | 95 | return (-1); |
93 | } | ||
94 | return(npubk); | ||
95 | } | 96 | } |
97 | return (npubk); | ||
98 | } | ||
96 | 99 | ||
97 | /* MACRO | 100 | /* MACRO |
98 | void EVP_SealUpdate(ctx,out,outl,in,inl) | 101 | void EVP_SealUpdate(ctx,out,outl,in,inl) |
@@ -106,11 +109,13 @@ int inl; | |||
106 | } | 109 | } |
107 | */ | 110 | */ |
108 | 111 | ||
109 | int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | 112 | int |
110 | { | 113 | EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) |
114 | { | ||
111 | int i; | 115 | int i; |
112 | i = EVP_EncryptFinal_ex(ctx,out,outl); | 116 | |
113 | if (i) | 117 | i = EVP_EncryptFinal_ex(ctx, out, outl); |
114 | i = EVP_EncryptInit_ex(ctx,NULL,NULL,NULL,NULL); | 118 | if (i) |
119 | i = EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, NULL); | ||
115 | return i; | 120 | return i; |
116 | } | 121 | } |