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_sign.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_sign.c')
-rw-r--r-- | src/lib/libcrypto/evp/p_sign.c | 94 |
1 files changed, 46 insertions, 48 deletions
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c index 8afb664306..b064ec5fb5 100644 --- a/src/lib/libcrypto/evp/p_sign.c +++ b/src/lib/libcrypto/evp/p_sign.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 |
@@ -63,37 +63,39 @@ | |||
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | #ifdef undef | 65 | #ifdef undef |
66 | void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) | 66 | void |
67 | { | 67 | EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) |
68 | EVP_DigestInit_ex(ctx,type); | 68 | { |
69 | } | 69 | EVP_DigestInit_ex(ctx, type); |
70 | } | ||
70 | 71 | ||
71 | void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, | 72 | void |
72 | unsigned int count) | 73 | EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, |
73 | { | 74 | unsigned int count) |
74 | EVP_DigestUpdate(ctx,data,count); | 75 | { |
75 | } | 76 | EVP_DigestUpdate(ctx, data, count); |
77 | } | ||
76 | #endif | 78 | #endif |
77 | 79 | ||
78 | int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, | 80 | int |
79 | EVP_PKEY *pkey) | 81 | EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, |
80 | { | 82 | EVP_PKEY *pkey) |
83 | { | ||
81 | unsigned char m[EVP_MAX_MD_SIZE]; | 84 | unsigned char m[EVP_MAX_MD_SIZE]; |
82 | unsigned int m_len; | 85 | unsigned int m_len; |
83 | int i = 0,ok = 0,v; | 86 | int i = 0, ok = 0, v; |
84 | EVP_MD_CTX tmp_ctx; | 87 | EVP_MD_CTX tmp_ctx; |
85 | EVP_PKEY_CTX *pkctx = NULL; | 88 | EVP_PKEY_CTX *pkctx = NULL; |
86 | 89 | ||
87 | *siglen=0; | 90 | *siglen = 0; |
88 | EVP_MD_CTX_init(&tmp_ctx); | 91 | EVP_MD_CTX_init(&tmp_ctx); |
89 | if (!EVP_MD_CTX_copy_ex(&tmp_ctx,ctx)) | 92 | if (!EVP_MD_CTX_copy_ex(&tmp_ctx, ctx)) |
90 | goto err; | 93 | goto err; |
91 | if (!EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len)) | 94 | if (!EVP_DigestFinal_ex(&tmp_ctx, &(m[0]), &m_len)) |
92 | goto err; | 95 | goto err; |
93 | EVP_MD_CTX_cleanup(&tmp_ctx); | 96 | EVP_MD_CTX_cleanup(&tmp_ctx); |
94 | 97 | ||
95 | if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) | 98 | if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { |
96 | { | ||
97 | size_t sltmp = (size_t)EVP_PKEY_size(pkey); | 99 | size_t sltmp = (size_t)EVP_PKEY_size(pkey); |
98 | i = 0; | 100 | i = 0; |
99 | pkctx = EVP_PKEY_CTX_new(pkey, NULL); | 101 | pkctx = EVP_PKEY_CTX_new(pkey, NULL); |
@@ -107,33 +109,29 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, | |||
107 | goto err; | 109 | goto err; |
108 | *siglen = sltmp; | 110 | *siglen = sltmp; |
109 | i = 1; | 111 | i = 1; |
110 | err: | 112 | err: |
111 | EVP_PKEY_CTX_free(pkctx); | 113 | EVP_PKEY_CTX_free(pkctx); |
112 | return i; | 114 | return i; |
113 | } | 115 | } |
114 | 116 | ||
115 | for (i=0; i<4; i++) | 117 | for (i = 0; i < 4; i++) { |
116 | { | 118 | v = ctx->digest->required_pkey_type[i]; |
117 | v=ctx->digest->required_pkey_type[i]; | 119 | if (v == 0) |
118 | if (v == 0) break; | 120 | break; |
119 | if (pkey->type == v) | 121 | if (pkey->type == v) { |
120 | { | 122 | ok = 1; |
121 | ok=1; | ||
122 | break; | 123 | break; |
123 | } | ||
124 | } | ||
125 | if (!ok) | ||
126 | { | ||
127 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
128 | return(0); | ||
129 | } | ||
130 | |||
131 | if (ctx->digest->sign == NULL) | ||
132 | { | ||
133 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED); | ||
134 | return(0); | ||
135 | } | 124 | } |
136 | return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen, | 125 | } |
137 | pkey->pkey.ptr)); | 126 | if (!ok) { |
127 | EVPerr(EVP_F_EVP_SIGNFINAL, EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
128 | return (0); | ||
138 | } | 129 | } |
139 | 130 | ||
131 | if (ctx->digest->sign == NULL) { | ||
132 | EVPerr(EVP_F_EVP_SIGNFINAL, EVP_R_NO_SIGN_FUNCTION_CONFIGURED); | ||
133 | return (0); | ||
134 | } | ||
135 | return(ctx->digest->sign(ctx->digest->type, m,m_len, sigret, siglen, | ||
136 | pkey->pkey.ptr)); | ||
137 | } | ||