diff options
author | jsing <> | 2014-04-19 06:43:34 +0000 |
---|---|---|
committer | jsing <> | 2014-04-19 06:43:34 +0000 |
commit | 524832e77ced4928195feaa76ecd8d699007445d (patch) | |
tree | 675608d06148241143e4bc3a2c57f7cc486d8d36 | |
parent | 2a0636b8bd35ee08c20816fa56e6c24a9f924bab (diff) | |
download | openbsd-524832e77ced4928195feaa76ecd8d699007445d.tar.gz openbsd-524832e77ced4928195feaa76ecd8d699007445d.tar.bz2 openbsd-524832e77ced4928195feaa76ecd8d699007445d.zip |
More KNF.
-rw-r--r-- | src/lib/libcrypto/asn1/d2i_pr.c | 66 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/d2i_pu.c | 57 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/evp_asn1.c | 164 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/f_enum.c | 173 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/f_int.c | 173 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/f_string.c | 164 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/d2i_pr.c | 66 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/d2i_pu.c | 57 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/evp_asn1.c | 164 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/f_enum.c | 173 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/f_int.c | 173 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/f_string.c | 164 |
12 files changed, 868 insertions, 726 deletions
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c index 5e6003ca5b..c356e3fda5 100644 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ b/src/lib/libcrypto/asn1/d2i_pr.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 |
@@ -68,18 +68,18 @@ | |||
68 | #include <openssl/asn1.h> | 68 | #include <openssl/asn1.h> |
69 | #include "asn1_locl.h" | 69 | #include "asn1_locl.h" |
70 | 70 | ||
71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | 71 | EVP_PKEY * |
72 | long length) | 72 | d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) |
73 | { | 73 | { |
74 | EVP_PKEY *ret; | 74 | EVP_PKEY *ret; |
75 | 75 | ||
76 | if ((a == NULL) || (*a == NULL)) { | 76 | if ((a == NULL) || (*a == NULL)) { |
77 | if ((ret=EVP_PKEY_new()) == NULL) { | 77 | if ((ret = EVP_PKEY_new()) == NULL) { |
78 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | 78 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_EVP_LIB); |
79 | return(NULL); | 79 | return (NULL); |
80 | } | 80 | } |
81 | } else { | 81 | } else { |
82 | ret= *a; | 82 | ret = *a; |
83 | #ifndef OPENSSL_NO_ENGINE | 83 | #ifndef OPENSSL_NO_ENGINE |
84 | if (ret->engine) { | 84 | if (ret->engine) { |
85 | ENGINE_finish(ret->engine); | 85 | ENGINE_finish(ret->engine); |
@@ -89,40 +89,44 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
89 | } | 89 | } |
90 | 90 | ||
91 | if (!EVP_PKEY_set_type(ret, type)) { | 91 | if (!EVP_PKEY_set_type(ret, type)) { |
92 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 92 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
93 | goto err; | 93 | goto err; |
94 | } | 94 | } |
95 | 95 | ||
96 | if (!ret->ameth->old_priv_decode || | 96 | if (!ret->ameth->old_priv_decode || |
97 | !ret->ameth->old_priv_decode(ret, pp, length)) { | 97 | !ret->ameth->old_priv_decode(ret, pp, length)) { |
98 | if (ret->ameth->priv_decode) { | 98 | if (ret->ameth->priv_decode) { |
99 | PKCS8_PRIV_KEY_INFO *p8=NULL; | 99 | PKCS8_PRIV_KEY_INFO *p8 = NULL; |
100 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 100 | p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, length); |
101 | if (!p8) goto err; | 101 | if (!p8) |
102 | goto err; | ||
102 | EVP_PKEY_free(ret); | 103 | EVP_PKEY_free(ret); |
103 | ret = EVP_PKCS82PKEY(p8); | 104 | ret = EVP_PKCS82PKEY(p8); |
104 | PKCS8_PRIV_KEY_INFO_free(p8); | 105 | PKCS8_PRIV_KEY_INFO_free(p8); |
105 | |||
106 | } else { | 106 | } else { |
107 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 107 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB); |
108 | goto err; | 108 | goto err; |
109 | } | 109 | } |
110 | } | 110 | } |
111 | if (a != NULL) (*a)=ret; | 111 | if (a != NULL) |
112 | return(ret); | 112 | (*a) = ret; |
113 | return (ret); | ||
114 | |||
113 | err: | 115 | err: |
114 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 116 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
115 | return(NULL); | 117 | EVP_PKEY_free(ret); |
118 | return (NULL); | ||
116 | } | 119 | } |
117 | 120 | ||
118 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | 121 | /* This works like d2i_PrivateKey() except it automatically works out the type */ |
119 | 122 | ||
120 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | 123 | EVP_PKEY * |
121 | long length) | 124 | d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length) |
122 | { | 125 | { |
123 | STACK_OF(ASN1_TYPE) *inkey; | 126 | STACK_OF(ASN1_TYPE) *inkey; |
124 | const unsigned char *p; | 127 | const unsigned char *p; |
125 | int keytype; | 128 | int keytype; |
129 | |||
126 | p = *pp; | 130 | p = *pp; |
127 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | 131 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): |
128 | * by analyzing it we can determine the passed structure: this | 132 | * by analyzing it we can determine the passed structure: this |
@@ -132,25 +136,27 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | |||
132 | /* Since we only need to discern "traditional format" RSA and DSA | 136 | /* Since we only need to discern "traditional format" RSA and DSA |
133 | * keys we can just count the elements. | 137 | * keys we can just count the elements. |
134 | */ | 138 | */ |
135 | if(sk_ASN1_TYPE_num(inkey) == 6) | 139 | if (sk_ASN1_TYPE_num(inkey) == 6) |
136 | keytype = EVP_PKEY_DSA; | 140 | keytype = EVP_PKEY_DSA; |
137 | else if (sk_ASN1_TYPE_num(inkey) == 4) | 141 | else if (sk_ASN1_TYPE_num(inkey) == 4) |
138 | keytype = EVP_PKEY_EC; | 142 | keytype = EVP_PKEY_EC; |
139 | else if (sk_ASN1_TYPE_num(inkey) == 3) { | 143 | else if (sk_ASN1_TYPE_num(inkey) == 3) { |
140 | /* This seems to be PKCS8, not traditional format */ | 144 | /* This seems to be PKCS8, not traditional format */ |
141 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 145 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO( |
146 | NULL, pp, length); | ||
142 | EVP_PKEY *ret; | 147 | EVP_PKEY *ret; |
143 | 148 | ||
144 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 149 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
145 | if (!p8) { | 150 | if (!p8) { |
146 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 151 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY, |
152 | ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
147 | return NULL; | 153 | return NULL; |
148 | } | 154 | } |
149 | ret = EVP_PKCS82PKEY(p8); | 155 | ret = EVP_PKCS82PKEY(p8); |
150 | PKCS8_PRIV_KEY_INFO_free(p8); | 156 | PKCS8_PRIV_KEY_INFO_free(p8); |
151 | if (a) { | 157 | if (a) { |
152 | *a = ret; | 158 | *a = ret; |
153 | } | 159 | } |
154 | return ret; | 160 | return ret; |
155 | } else | 161 | } else |
156 | keytype = EVP_PKEY_RSA; | 162 | keytype = EVP_PKEY_RSA; |
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c index ccd03c066f..564f0945b5 100644 --- a/src/lib/libcrypto/asn1/d2i_pu.c +++ b/src/lib/libcrypto/asn1/d2i_pu.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 |
@@ -72,31 +72,31 @@ | |||
72 | #include <openssl/ec.h> | 72 | #include <openssl/ec.h> |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | 75 | EVP_PKEY * |
76 | long length) | 76 | d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) |
77 | { | 77 | { |
78 | EVP_PKEY *ret; | 78 | EVP_PKEY *ret; |
79 | 79 | ||
80 | if ((a == NULL) || (*a == NULL)) { | 80 | if ((a == NULL) || (*a == NULL)) { |
81 | if ((ret=EVP_PKEY_new()) == NULL) { | 81 | if ((ret = EVP_PKEY_new()) == NULL) { |
82 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 82 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); |
83 | return(NULL); | 83 | return (NULL); |
84 | } | 84 | } |
85 | } | 85 | } else |
86 | else ret= *a; | 86 | ret = *a; |
87 | 87 | ||
88 | if (!EVP_PKEY_set_type(ret, type)) { | 88 | if (!EVP_PKEY_set_type(ret, type)) { |
89 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 89 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); |
90 | goto err; | 90 | goto err; |
91 | } | 91 | } |
92 | 92 | ||
93 | switch (EVP_PKEY_id(ret)) { | 93 | switch (EVP_PKEY_id(ret)) { |
94 | #ifndef OPENSSL_NO_RSA | 94 | #ifndef OPENSSL_NO_RSA |
95 | case EVP_PKEY_RSA: | 95 | case EVP_PKEY_RSA: |
96 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, | 96 | if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, |
97 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | 97 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ |
98 | { | 98 | { |
99 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 99 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
100 | goto err; | 100 | goto err; |
101 | } | 101 | } |
102 | break; | 102 | break; |
@@ -104,9 +104,9 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
104 | #ifndef OPENSSL_NO_DSA | 104 | #ifndef OPENSSL_NO_DSA |
105 | case EVP_PKEY_DSA: | 105 | case EVP_PKEY_DSA: |
106 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), | 106 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), |
107 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ | 107 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ |
108 | { | 108 | { |
109 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 109 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
110 | goto err; | 110 | goto err; |
111 | } | 111 | } |
112 | break; | 112 | break; |
@@ -114,22 +114,23 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
114 | #ifndef OPENSSL_NO_EC | 114 | #ifndef OPENSSL_NO_EC |
115 | case EVP_PKEY_EC: | 115 | case EVP_PKEY_EC: |
116 | if (!o2i_ECPublicKey(&(ret->pkey.ec), | 116 | if (!o2i_ECPublicKey(&(ret->pkey.ec), |
117 | (const unsigned char **)pp, length)) | 117 | (const unsigned char **)pp, length)) { |
118 | { | ||
119 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); | 118 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
120 | goto err; | 119 | goto err; |
121 | } | 120 | } |
122 | break; | 121 | break; |
123 | #endif | 122 | #endif |
124 | default: | 123 | default: |
125 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 124 | ASN1err(ASN1_F_D2I_PUBLICKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
126 | goto err; | 125 | goto err; |
127 | /* break; */ | 126 | /* break; */ |
128 | } | 127 | } |
129 | if (a != NULL) (*a)=ret; | 128 | if (a != NULL) |
130 | return(ret); | 129 | (*a) = ret; |
130 | return (ret); | ||
131 | |||
131 | err: | 132 | err: |
132 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 133 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
133 | return(NULL); | 134 | EVP_PKEY_free(ret); |
135 | return (NULL); | ||
134 | } | 136 | } |
135 | |||
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c index d4ea675f89..4ff03de1f9 100644 --- a/src/lib/libcrypto/asn1/evp_asn1.c +++ b/src/lib/libcrypto/asn1/evp_asn1.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 |
@@ -61,84 +61,91 @@ | |||
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1_mac.h> |
63 | 63 | ||
64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | 64 | int |
65 | ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | ||
65 | { | 66 | { |
66 | ASN1_STRING *os; | 67 | ASN1_STRING *os; |
67 | 68 | ||
68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); | 69 | if ((os = M_ASN1_OCTET_STRING_new()) == NULL) |
69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); | 70 | return (0); |
70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); | 71 | if (!M_ASN1_OCTET_STRING_set(os, data, len)) |
71 | return(1); | 72 | return (0); |
73 | ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os); | ||
74 | return (1); | ||
72 | } | 75 | } |
73 | 76 | ||
74 | /* int max_len: for returned value */ | 77 | /* int max_len: for returned value */ |
75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | 78 | int |
76 | int max_len) | 79 | ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len) |
77 | { | 80 | { |
78 | int ret,num; | 81 | int ret, num; |
79 | unsigned char *p; | 82 | unsigned char *p; |
80 | 83 | ||
81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { | 84 | if ((a->type != V_ASN1_OCTET_STRING) || |
82 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 85 | (a->value.octet_string == NULL)) { |
83 | return(-1); | 86 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG); |
87 | return (-1); | ||
84 | } | 88 | } |
85 | p=M_ASN1_STRING_data(a->value.octet_string); | 89 | p = M_ASN1_STRING_data(a->value.octet_string); |
86 | ret=M_ASN1_STRING_length(a->value.octet_string); | 90 | ret = M_ASN1_STRING_length(a->value.octet_string); |
87 | if (ret < max_len) | 91 | if (ret < max_len) |
88 | num=ret; | 92 | num = ret; |
89 | else | 93 | else |
90 | num=max_len; | 94 | num = max_len; |
91 | memcpy(data,p,num); | 95 | memcpy(data, p, num); |
92 | return(ret); | 96 | return (ret); |
93 | } | 97 | } |
94 | 98 | ||
95 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | 99 | int |
96 | int len) | 100 | ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, |
101 | int len) | ||
97 | { | 102 | { |
98 | int n,size; | 103 | int n, size; |
99 | ASN1_OCTET_STRING os,*osp; | 104 | ASN1_OCTET_STRING os, *osp; |
100 | ASN1_INTEGER in; | 105 | ASN1_INTEGER in; |
101 | unsigned char *p; | 106 | unsigned char *p; |
102 | unsigned char buf[32]; /* when they have 256bit longs, | 107 | unsigned char buf[32]; /* when they have 256bit longs, |
103 | * I'll be in trouble */ | 108 | * I'll be in trouble */ |
104 | in.data=buf; | 109 | in.data = buf; |
105 | in.length=32; | 110 | in.length = 32; |
106 | os.data=data; | 111 | os.data = data; |
107 | os.type=V_ASN1_OCTET_STRING; | 112 | os.type = V_ASN1_OCTET_STRING; |
108 | os.length=len; | 113 | os.length = len; |
109 | ASN1_INTEGER_set(&in,num); | 114 | ASN1_INTEGER_set(&in, num); |
110 | n = i2d_ASN1_INTEGER(&in,NULL); | 115 | n = i2d_ASN1_INTEGER(&in, NULL); |
111 | n+=M_i2d_ASN1_OCTET_STRING(&os,NULL); | 116 | n += M_i2d_ASN1_OCTET_STRING(&os, NULL); |
112 | 117 | ||
113 | size=ASN1_object_size(1,n,V_ASN1_SEQUENCE); | 118 | size = ASN1_object_size(1, n, V_ASN1_SEQUENCE); |
114 | 119 | ||
115 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | 120 | if ((osp = ASN1_STRING_new()) == NULL) |
121 | return (0); | ||
116 | /* Grow the 'string' */ | 122 | /* Grow the 'string' */ |
117 | if (!ASN1_STRING_set(osp,NULL,size)) { | 123 | if (!ASN1_STRING_set(osp, NULL, size)) { |
118 | ASN1_STRING_free(osp); | 124 | ASN1_STRING_free(osp); |
119 | return(0); | 125 | return (0); |
120 | } | 126 | } |
121 | 127 | ||
122 | M_ASN1_STRING_length_set(osp, size); | 128 | M_ASN1_STRING_length_set(osp, size); |
123 | p=M_ASN1_STRING_data(osp); | 129 | p = M_ASN1_STRING_data(osp); |
124 | 130 | ||
125 | ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | 131 | ASN1_put_object(&p, 1,n, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); |
126 | i2d_ASN1_INTEGER(&in,&p); | 132 | i2d_ASN1_INTEGER(&in, &p); |
127 | M_i2d_ASN1_OCTET_STRING(&os,&p); | 133 | M_i2d_ASN1_OCTET_STRING(&os, &p); |
128 | 134 | ||
129 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); | 135 | ASN1_TYPE_set(a, V_ASN1_SEQUENCE, osp); |
130 | return(1); | 136 | return (1); |
131 | } | 137 | } |
132 | 138 | ||
133 | /* we return the actual length..., num may be missing, in which | 139 | /* we return the actual length..., num may be missing, in which |
134 | * case, set it to zero */ | 140 | * case, set it to zero */ |
135 | /* int max_len: for returned value */ | 141 | /* int max_len: for returned value */ |
136 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | 142 | int |
137 | int max_len) | 143 | ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, |
144 | int max_len) | ||
138 | { | 145 | { |
139 | int ret= -1,n; | 146 | int ret = -1, n; |
140 | ASN1_INTEGER *ai=NULL; | 147 | ASN1_INTEGER *ai = NULL; |
141 | ASN1_OCTET_STRING *os=NULL; | 148 | ASN1_OCTET_STRING *os = NULL; |
142 | const unsigned char *p; | 149 | const unsigned char *p; |
143 | long length; | 150 | long length; |
144 | ASN1_const_CTX c; | 151 | ASN1_const_CTX c; |
@@ -146,40 +153,45 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | |||
146 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { | 153 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { |
147 | goto err; | 154 | goto err; |
148 | } | 155 | } |
149 | p=M_ASN1_STRING_data(a->value.sequence); | 156 | p = M_ASN1_STRING_data(a->value.sequence); |
150 | length=M_ASN1_STRING_length(a->value.sequence); | 157 | length = M_ASN1_STRING_length(a->value.sequence); |
151 | 158 | ||
152 | c.pp= &p; | 159 | c.pp = &p; |
153 | c.p=p; | 160 | c.p = p; |
154 | c.max=p+length; | 161 | c.max = p + length; |
155 | c.error=ASN1_R_DATA_IS_WRONG; | 162 | c.error = ASN1_R_DATA_IS_WRONG; |
156 | 163 | ||
157 | M_ASN1_D2I_start_sequence(); | 164 | M_ASN1_D2I_start_sequence(); |
158 | c.q=c.p; | 165 | c.q = c.p; |
159 | if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; | 166 | if ((ai = d2i_ASN1_INTEGER(NULL, &c.p, c.slen)) == NULL) |
160 | c.slen-=(c.p-c.q); | 167 | goto err; |
161 | c.q=c.p; | 168 | c.slen -= (c.p - c.q); |
162 | if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; | 169 | c.q = c.p; |
163 | c.slen-=(c.p-c.q); | 170 | if ((os = d2i_ASN1_OCTET_STRING(NULL, &c.p, c.slen)) == NULL) |
164 | if (!M_ASN1_D2I_end_sequence()) goto err; | 171 | goto err; |
172 | c.slen -= (c.p - c.q); | ||
173 | if (!M_ASN1_D2I_end_sequence()) | ||
174 | goto err; | ||
165 | 175 | ||
166 | if (num != NULL) | 176 | if (num != NULL) |
167 | *num=ASN1_INTEGER_get(ai); | 177 | *num = ASN1_INTEGER_get(ai); |
168 | 178 | ||
169 | ret=M_ASN1_STRING_length(os); | 179 | ret = M_ASN1_STRING_length(os); |
170 | if (max_len > ret) | 180 | if (max_len > ret) |
171 | n=ret; | 181 | n = ret; |
172 | else | 182 | else |
173 | n=max_len; | 183 | n = max_len; |
174 | 184 | ||
175 | if (data != NULL) | 185 | if (data != NULL) |
176 | memcpy(data,M_ASN1_STRING_data(os),n); | 186 | memcpy(data, M_ASN1_STRING_data(os), n); |
177 | if (0) { | 187 | if (0) { |
178 | err: | 188 | err: |
179 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 189 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, |
190 | ASN1_R_DATA_IS_WRONG); | ||
180 | } | 191 | } |
181 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 192 | if (os != NULL) |
182 | if (ai != NULL) M_ASN1_INTEGER_free(ai); | 193 | M_ASN1_OCTET_STRING_free(os); |
183 | return(ret); | 194 | if (ai != NULL) |
195 | M_ASN1_INTEGER_free(ai); | ||
196 | return (ret); | ||
184 | } | 197 | } |
185 | |||
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c index 4ccfbddf2a..e8736e5b72 100644 --- a/src/lib/libcrypto/asn1/f_enum.c +++ b/src/lib/libcrypto/asn1/f_enum.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,128 +63,145 @@ | |||
63 | 63 | ||
64 | /* Based on a_int.c: equivalent ENUMERATED functions */ | 64 | /* Based on a_int.c: equivalent ENUMERATED functions */ |
65 | 65 | ||
66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | 66 | int |
67 | i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | ||
67 | { | 68 | { |
68 | int i,n=0; | 69 | int i, n = 0; |
69 | static const char *h="0123456789ABCDEF"; | 70 | static const char *h = "0123456789ABCDEF"; |
70 | char buf[2]; | 71 | char buf[2]; |
71 | 72 | ||
72 | if (a == NULL) return(0); | 73 | if (a == NULL) |
74 | return (0); | ||
73 | 75 | ||
74 | if (a->length == 0) { | 76 | if (a->length == 0) { |
75 | if (BIO_write(bp,"00",2) != 2) goto err; | 77 | if (BIO_write(bp, "00", 2) != 2) |
76 | n=2; | 78 | goto err; |
79 | n = 2; | ||
77 | } else { | 80 | } else { |
78 | for (i=0; i<a->length; i++) { | 81 | for (i = 0; i < a->length; i++) { |
79 | if ((i != 0) && (i%35 == 0)) { | 82 | if ((i != 0) && (i % 35 == 0)) { |
80 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 83 | if (BIO_write(bp, "\\\n", 2) != 2) |
81 | n+=2; | 84 | goto err; |
85 | n += 2; | ||
82 | } | 86 | } |
83 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 87 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
84 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 88 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
85 | if (BIO_write(bp,buf,2) != 2) goto err; | 89 | if (BIO_write(bp, buf, 2) != 2) |
86 | n+=2; | 90 | goto err; |
91 | n += 2; | ||
87 | } | 92 | } |
88 | } | 93 | } |
89 | return(n); | 94 | return (n); |
95 | |||
90 | err: | 96 | err: |
91 | return(-1); | 97 | return (-1); |
92 | } | 98 | } |
93 | 99 | ||
94 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | 100 | int |
101 | a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | ||
95 | { | 102 | { |
96 | int ret=0; | 103 | int ret = 0; |
97 | int i,j,k,m,n,again,bufsize; | 104 | int i, j,k, m,n, again, bufsize; |
98 | unsigned char *s=NULL,*sp; | 105 | unsigned char *s = NULL, *sp; |
99 | unsigned char *bufp; | 106 | unsigned char *bufp; |
100 | int num=0,slen=0,first=1; | 107 | int num = 0, slen = 0, first = 1; |
101 | 108 | ||
102 | bs->type=V_ASN1_ENUMERATED; | 109 | bs->type = V_ASN1_ENUMERATED; |
103 | 110 | ||
104 | bufsize=BIO_gets(bp,buf,size); | 111 | bufsize = BIO_gets(bp, buf, size); |
105 | for (;;) { | 112 | for (;;) { |
106 | if (bufsize < 1) goto err_sl; | 113 | if (bufsize < 1) |
107 | i=bufsize; | 114 | goto err_sl; |
108 | if (buf[i-1] == '\n') buf[--i]='\0'; | 115 | i = bufsize; |
109 | if (i == 0) goto err_sl; | 116 | if (buf[i-1] == '\n') |
110 | if (buf[i-1] == '\r') buf[--i]='\0'; | 117 | buf[--i] = '\0'; |
111 | if (i == 0) goto err_sl; | 118 | if (i == 0) |
112 | again=(buf[i-1] == '\\'); | 119 | goto err_sl; |
120 | if (buf[i-1] == '\r') | ||
121 | buf[--i] = '\0'; | ||
122 | if (i == 0) | ||
123 | goto err_sl; | ||
124 | again = (buf[i - 1] == '\\'); | ||
113 | 125 | ||
114 | for (j=0; j<i; j++) { | 126 | for (j = 0; j < i; j++) { |
115 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 127 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
116 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 128 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
117 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 129 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
118 | i=j; | 130 | i = j; |
119 | break; | 131 | break; |
120 | } | 132 | } |
121 | } | 133 | } |
122 | buf[i]='\0'; | 134 | buf[i] = '\0'; |
123 | /* We have now cleared all the crap off the end of the | 135 | /* We have now cleared all the crap off the end of the |
124 | * line */ | 136 | * line */ |
125 | if (i < 2) goto err_sl; | 137 | if (i < 2) |
138 | goto err_sl; | ||
126 | 139 | ||
127 | bufp=(unsigned char *)buf; | 140 | bufp = (unsigned char *)buf; |
128 | if (first) { | 141 | if (first) { |
129 | first=0; | 142 | first = 0; |
130 | if ((bufp[0] == '0') && (buf[1] == '0')) { | 143 | if ((bufp[0] == '0') && (buf[1] == '0')) { |
131 | bufp+=2; | 144 | bufp += 2; |
132 | i-=2; | 145 | i -= 2; |
133 | } | 146 | } |
134 | } | 147 | } |
135 | k=0; | 148 | k = 0; |
136 | i-=again; | 149 | i -= again; |
137 | if (i%2 != 0) { | 150 | if (i % 2 != 0) { |
138 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); | 151 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, |
152 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
139 | goto err; | 153 | goto err; |
140 | } | 154 | } |
141 | i/=2; | 155 | i /= 2; |
142 | if (num+i > slen) { | 156 | if (num + i > slen) { |
143 | if (s == NULL) | 157 | if (s == NULL) |
144 | sp=(unsigned char *)malloc( | 158 | sp = (unsigned char *)malloc( |
145 | (unsigned int)num+i*2); | 159 | (unsigned int)num + i * 2); |
146 | else | 160 | else |
147 | sp=(unsigned char *)realloc(s, | 161 | sp = (unsigned char *)realloc(s, |
148 | (unsigned int)num+i*2); | 162 | (unsigned int)num + i * 2); |
149 | if (sp == NULL) { | 163 | if (sp == NULL) { |
150 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | 164 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, |
151 | if (s != NULL) free(s); | 165 | ERR_R_MALLOC_FAILURE); |
166 | if (s != NULL) | ||
167 | free(s); | ||
152 | goto err; | 168 | goto err; |
153 | } | 169 | } |
154 | s=sp; | 170 | s = sp; |
155 | slen=num+i*2; | 171 | slen = num + i * 2; |
156 | } | 172 | } |
157 | for (j=0; j<i; j++,k+=2) { | 173 | for (j = 0; j < i; j++, k += 2) { |
158 | for (n=0; n<2; n++) { | 174 | for (n = 0; n < 2; n++) { |
159 | m=bufp[k+n]; | 175 | m = bufp[k + n]; |
160 | if ((m >= '0') && (m <= '9')) | 176 | if ((m >= '0') && (m <= '9')) |
161 | m-='0'; | 177 | m -= '0'; |
162 | else if ((m >= 'a') && (m <= 'f')) | 178 | else if ((m >= 'a') && (m <= 'f')) |
163 | m=m-'a'+10; | 179 | m = m - 'a' + 10; |
164 | else if ((m >= 'A') && (m <= 'F')) | 180 | else if ((m >= 'A') && (m <= 'F')) |
165 | m=m-'A'+10; | 181 | m = m - 'A' + 10; |
166 | else { | 182 | else { |
167 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); | 183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, |
184 | ASN1_R_NON_HEX_CHARACTERS); | ||
168 | goto err; | 185 | goto err; |
169 | } | 186 | } |
170 | s[num+j]<<=4; | 187 | s[num + j] <<= 4; |
171 | s[num+j]|=m; | 188 | s[num + j] |= m; |
172 | } | 189 | } |
173 | } | 190 | } |
174 | num+=i; | 191 | num += i; |
175 | if (again) | 192 | if (again) |
176 | bufsize=BIO_gets(bp,buf,size); | 193 | bufsize = BIO_gets(bp, buf, size); |
177 | else | 194 | else |
178 | break; | 195 | break; |
179 | } | 196 | } |
180 | bs->length=num; | 197 | bs->length = num; |
181 | bs->data=s; | 198 | bs->data = s; |
182 | ret=1; | 199 | ret = 1; |
200 | |||
183 | err: | 201 | err: |
184 | if (0) { | 202 | if (0) { |
185 | err_sl: | 203 | err_sl: |
186 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); | 204 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ASN1_R_SHORT_LINE); |
187 | } | 205 | } |
188 | return(ret); | 206 | return (ret); |
189 | } | 207 | } |
190 | |||
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c index 6cea1f8485..f355dbacbe 100644 --- a/src/lib/libcrypto/asn1/f_int.c +++ b/src/lib/libcrypto/asn1/f_int.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 |
@@ -61,132 +61,151 @@ | |||
61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | 64 | int |
65 | i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | ||
65 | { | 66 | { |
66 | int i,n=0; | 67 | int i, n = 0; |
67 | static const char *h="0123456789ABCDEF"; | 68 | static const char *h = "0123456789ABCDEF"; |
68 | char buf[2]; | 69 | char buf[2]; |
69 | 70 | ||
70 | if (a == NULL) return(0); | 71 | if (a == NULL) |
72 | return (0); | ||
71 | 73 | ||
72 | if (a->type & V_ASN1_NEG) { | 74 | if (a->type & V_ASN1_NEG) { |
73 | if (BIO_write(bp, "-", 1) != 1) goto err; | 75 | if (BIO_write(bp, "-", 1) != 1) |
76 | goto err; | ||
74 | n = 1; | 77 | n = 1; |
75 | } | 78 | } |
76 | 79 | ||
77 | if (a->length == 0) { | 80 | if (a->length == 0) { |
78 | if (BIO_write(bp,"00",2) != 2) goto err; | 81 | if (BIO_write(bp, "00", 2) != 2) |
82 | goto err; | ||
79 | n += 2; | 83 | n += 2; |
80 | } else { | 84 | } else { |
81 | for (i=0; i<a->length; i++) { | 85 | for (i = 0; i < a->length; i++) { |
82 | if ((i != 0) && (i%35 == 0)) { | 86 | if ((i != 0) && (i % 35 == 0)) { |
83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 87 | if (BIO_write(bp, "\\\n", 2) != 2) |
84 | n+=2; | 88 | goto err; |
89 | n += 2; | ||
85 | } | 90 | } |
86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 91 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 92 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
88 | if (BIO_write(bp,buf,2) != 2) goto err; | 93 | if (BIO_write(bp, buf, 2) != 2) |
89 | n+=2; | 94 | goto err; |
95 | n += 2; | ||
90 | } | 96 | } |
91 | } | 97 | } |
92 | return(n); | 98 | return (n); |
99 | |||
93 | err: | 100 | err: |
94 | return(-1); | 101 | return (-1); |
95 | } | 102 | } |
96 | 103 | ||
97 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | 104 | int |
105 | a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | ||
98 | { | 106 | { |
99 | int ret=0; | 107 | int ret = 0; |
100 | int i,j,k,m,n,again,bufsize; | 108 | int i, j,k, m,n, again, bufsize; |
101 | unsigned char *s=NULL,*sp; | 109 | unsigned char *s = NULL, *sp; |
102 | unsigned char *bufp; | 110 | unsigned char *bufp; |
103 | int num=0,slen=0,first=1; | 111 | int num = 0, slen = 0, first = 1; |
104 | 112 | ||
105 | bs->type=V_ASN1_INTEGER; | 113 | bs->type = V_ASN1_INTEGER; |
106 | 114 | ||
107 | bufsize=BIO_gets(bp,buf,size); | 115 | bufsize = BIO_gets(bp, buf, size); |
108 | for (;;) { | 116 | for (;;) { |
109 | if (bufsize < 1) goto err_sl; | 117 | if (bufsize < 1) |
110 | i=bufsize; | 118 | goto err_sl; |
111 | if (buf[i-1] == '\n') buf[--i]='\0'; | 119 | i = bufsize; |
112 | if (i == 0) goto err_sl; | 120 | if (buf[i - 1] == '\n') |
113 | if (buf[i-1] == '\r') buf[--i]='\0'; | 121 | buf[--i] = '\0'; |
114 | if (i == 0) goto err_sl; | 122 | if (i == 0) |
115 | again=(buf[i-1] == '\\'); | 123 | goto err_sl; |
124 | if (buf[i - 1] == '\r') | ||
125 | buf[--i] = '\0'; | ||
126 | if (i == 0) | ||
127 | goto err_sl; | ||
128 | again = (buf[i - 1] == '\\'); | ||
116 | 129 | ||
117 | for (j=0; j<i; j++) { | 130 | for (j = 0; j < i; j++) { |
118 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 131 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
119 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 132 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
120 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 133 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
121 | i=j; | 134 | i = j; |
122 | break; | 135 | break; |
123 | } | 136 | } |
124 | } | 137 | } |
125 | buf[i]='\0'; | 138 | buf[i] = '\0'; |
126 | /* We have now cleared all the crap off the end of the | 139 | /* We have now cleared all the crap off the end of the |
127 | * line */ | 140 | * line */ |
128 | if (i < 2) goto err_sl; | 141 | if (i < 2) |
142 | goto err_sl; | ||
129 | 143 | ||
130 | bufp=(unsigned char *)buf; | 144 | bufp = (unsigned char *)buf; |
131 | if (first) { | 145 | if (first) { |
132 | first=0; | 146 | first = 0; |
133 | if ((bufp[0] == '0') && (buf[1] == '0')) { | 147 | if ((bufp[0] == '0') && (buf[1] == '0')) { |
134 | bufp+=2; | 148 | bufp += 2; |
135 | i-=2; | 149 | i -= 2; |
136 | } | 150 | } |
137 | } | 151 | } |
138 | k=0; | 152 | k = 0; |
139 | i-=again; | 153 | i -= again; |
140 | if (i%2 != 0) { | 154 | if (i % 2 != 0) { |
141 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | 155 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, |
156 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
142 | goto err; | 157 | goto err; |
143 | } | 158 | } |
144 | i/=2; | 159 | i /= 2; |
145 | if (num+i > slen) { | 160 | if (num + i > slen) { |
146 | if (s == NULL) | 161 | if (s == NULL) |
147 | sp=(unsigned char *)malloc( | 162 | sp = (unsigned char *)malloc( |
148 | (unsigned int)num+i*2); | 163 | (unsigned int)num + i * 2); |
149 | else | 164 | else |
150 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | 165 | sp = OPENSSL_realloc_clean(s, slen, |
166 | num + i * 2); | ||
151 | if (sp == NULL) { | 167 | if (sp == NULL) { |
152 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 168 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, |
153 | if (s != NULL) free(s); | 169 | ERR_R_MALLOC_FAILURE); |
170 | if (s != NULL) | ||
171 | free(s); | ||
154 | goto err; | 172 | goto err; |
155 | } | 173 | } |
156 | s=sp; | 174 | s = sp; |
157 | slen=num+i*2; | 175 | slen = num + i * 2; |
158 | } | 176 | } |
159 | for (j=0; j<i; j++,k+=2) { | 177 | for (j = 0; j < i; j++, k += 2) { |
160 | for (n=0; n<2; n++) { | 178 | for (n = 0; n < 2; n++) { |
161 | m=bufp[k+n]; | 179 | m = bufp[k + n]; |
162 | if ((m >= '0') && (m <= '9')) | 180 | if ((m >= '0') && (m <= '9')) |
163 | m-='0'; | 181 | m -= '0'; |
164 | else if ((m >= 'a') && (m <= 'f')) | 182 | else if ((m >= 'a') && (m <= 'f')) |
165 | m=m-'a'+10; | 183 | m = m - 'a' + 10; |
166 | else if ((m >= 'A') && (m <= 'F')) | 184 | else if ((m >= 'A') && (m <= 'F')) |
167 | m=m-'A'+10; | 185 | m = m - 'A' + 10; |
168 | else { | 186 | else { |
169 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | 187 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, |
188 | ASN1_R_NON_HEX_CHARACTERS); | ||
170 | goto err; | 189 | goto err; |
171 | } | 190 | } |
172 | s[num+j]<<=4; | 191 | s[num + j] <<= 4; |
173 | s[num+j]|=m; | 192 | s[num + j] |= m; |
174 | } | 193 | } |
175 | } | 194 | } |
176 | num+=i; | 195 | num += i; |
177 | if (again) | 196 | if (again) |
178 | bufsize=BIO_gets(bp,buf,size); | 197 | bufsize = BIO_gets(bp, buf, size); |
179 | else | 198 | else |
180 | break; | 199 | break; |
181 | } | 200 | } |
182 | bs->length=num; | 201 | bs->length = num; |
183 | bs->data=s; | 202 | bs->data = s; |
184 | ret=1; | 203 | ret = 1; |
204 | |||
185 | err: | 205 | err: |
186 | if (0) { | 206 | if (0) { |
187 | err_sl: | 207 | err_sl: |
188 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | 208 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE); |
189 | } | 209 | } |
190 | return(ret); | 210 | return (ret); |
191 | } | 211 | } |
192 | |||
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c index 87d7aaa0dd..d42bcdb6ea 100644 --- a/src/lib/libcrypto/asn1/f_string.c +++ b/src/lib/libcrypto/asn1/f_string.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 |
@@ -61,43 +61,50 @@ | |||
61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | 64 | int |
65 | i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | ||
65 | { | 66 | { |
66 | int i,n=0; | 67 | int i, n = 0; |
67 | static const char *h="0123456789ABCDEF"; | 68 | static const char *h = "0123456789ABCDEF"; |
68 | char buf[2]; | 69 | char buf[2]; |
69 | 70 | ||
70 | if (a == NULL) return(0); | 71 | if (a == NULL) |
72 | return (0); | ||
71 | 73 | ||
72 | if (a->length == 0) { | 74 | if (a->length == 0) { |
73 | if (BIO_write(bp,"0",1) != 1) goto err; | 75 | if (BIO_write(bp, "0", 1) != 1) |
74 | n=1; | 76 | goto err; |
77 | n = 1; | ||
75 | } else { | 78 | } else { |
76 | for (i=0; i<a->length; i++) { | 79 | for (i = 0; i < a->length; i++) { |
77 | if ((i != 0) && (i%35 == 0)) { | 80 | if ((i != 0) && (i % 35 == 0)) { |
78 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 81 | if (BIO_write(bp, "\\\n", 2) != 2) |
79 | n+=2; | 82 | goto err; |
83 | n += 2; | ||
80 | } | 84 | } |
81 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 85 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
82 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 86 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
83 | if (BIO_write(bp,buf,2) != 2) goto err; | 87 | if (BIO_write(bp, buf, 2) != 2) |
84 | n+=2; | 88 | goto err; |
89 | n += 2; | ||
85 | } | 90 | } |
86 | } | 91 | } |
87 | return(n); | 92 | return (n); |
93 | |||
88 | err: | 94 | err: |
89 | return(-1); | 95 | return (-1); |
90 | } | 96 | } |
91 | 97 | ||
92 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | 98 | int |
99 | a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | ||
93 | { | 100 | { |
94 | int ret=0; | 101 | int ret = 0; |
95 | int i,j,k,m,n,again,bufsize; | 102 | int i, j, k, m, n, again, bufsize; |
96 | unsigned char *s=NULL,*sp; | 103 | unsigned char *s = NULL, *sp; |
97 | unsigned char *bufp; | 104 | unsigned char *bufp; |
98 | int num=0,slen=0,first=1; | 105 | int num = 0, slen = 0, first = 1; |
99 | 106 | ||
100 | bufsize=BIO_gets(bp,buf,size); | 107 | bufsize = BIO_gets(bp, buf, size); |
101 | for (;;) { | 108 | for (;;) { |
102 | if (bufsize < 1) { | 109 | if (bufsize < 1) { |
103 | if (first) | 110 | if (first) |
@@ -105,83 +112,92 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
105 | else | 112 | else |
106 | goto err_sl; | 113 | goto err_sl; |
107 | } | 114 | } |
108 | first=0; | 115 | first = 0; |
109 | 116 | ||
110 | i=bufsize; | 117 | i = bufsize; |
111 | if (buf[i-1] == '\n') buf[--i]='\0'; | 118 | if (buf[i-1] == '\n') |
112 | if (i == 0) goto err_sl; | 119 | buf[--i] = '\0'; |
113 | if (buf[i-1] == '\r') buf[--i]='\0'; | 120 | if (i == 0) |
114 | if (i == 0) goto err_sl; | 121 | goto err_sl; |
115 | again=(buf[i-1] == '\\'); | 122 | if (buf[i-1] == '\r') |
123 | buf[--i] = '\0'; | ||
124 | if (i == 0) | ||
125 | goto err_sl; | ||
126 | again = (buf[i - 1] == '\\'); | ||
116 | 127 | ||
117 | for (j=i-1; j>0; j--) { | 128 | for (j = i - 1; j > 0; j--) { |
118 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 129 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
119 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 130 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
120 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 131 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
121 | i=j; | 132 | i = j; |
122 | break; | 133 | break; |
123 | } | 134 | } |
124 | } | 135 | } |
125 | buf[i]='\0'; | 136 | buf[i] = '\0'; |
126 | /* We have now cleared all the crap off the end of the | 137 | /* We have now cleared all the crap off the end of the |
127 | * line */ | 138 | * line */ |
128 | if (i < 2) goto err_sl; | 139 | if (i < 2) |
140 | goto err_sl; | ||
129 | 141 | ||
130 | bufp=(unsigned char *)buf; | 142 | bufp = (unsigned char *)buf; |
131 | 143 | ||
132 | k=0; | 144 | k = 0; |
133 | i-=again; | 145 | i -= again; |
134 | if (i%2 != 0) { | 146 | if (i % 2 != 0) { |
135 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | 147 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
148 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
136 | goto err; | 149 | goto err; |
137 | } | 150 | } |
138 | i/=2; | 151 | i /= 2; |
139 | if (num+i > slen) { | 152 | if (num + i > slen) { |
140 | if (s == NULL) | 153 | if (s == NULL) |
141 | sp=(unsigned char *)malloc( | 154 | sp = (unsigned char *)malloc( |
142 | (unsigned int)num+i*2); | 155 | (unsigned int)num + i * 2); |
143 | else | 156 | else |
144 | sp=(unsigned char *)realloc(s, | 157 | sp = (unsigned char *)realloc(s, |
145 | (unsigned int)num+i*2); | 158 | (unsigned int)num + i * 2); |
146 | if (sp == NULL) { | 159 | if (sp == NULL) { |
147 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | 160 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
148 | if (s != NULL) free(s); | 161 | ERR_R_MALLOC_FAILURE); |
162 | if (s != NULL) | ||
163 | free(s); | ||
149 | goto err; | 164 | goto err; |
150 | } | 165 | } |
151 | s=sp; | 166 | s = sp; |
152 | slen=num+i*2; | 167 | slen = num + i * 2; |
153 | } | 168 | } |
154 | for (j=0; j<i; j++,k+=2) { | 169 | for (j = 0; j < i; j++, k += 2) { |
155 | for (n=0; n<2; n++) { | 170 | for (n = 0; n < 2; n++) { |
156 | m=bufp[k+n]; | 171 | m = bufp[k + n]; |
157 | if ((m >= '0') && (m <= '9')) | 172 | if ((m >= '0') && (m <= '9')) |
158 | m-='0'; | 173 | m -= '0'; |
159 | else if ((m >= 'a') && (m <= 'f')) | 174 | else if ((m >= 'a') && (m <= 'f')) |
160 | m=m-'a'+10; | 175 | m = m - 'a' + 10; |
161 | else if ((m >= 'A') && (m <= 'F')) | 176 | else if ((m >= 'A') && (m <= 'F')) |
162 | m=m-'A'+10; | 177 | m = m - 'A' + 10; |
163 | else { | 178 | else { |
164 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | 179 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
180 | ASN1_R_NON_HEX_CHARACTERS); | ||
165 | goto err; | 181 | goto err; |
166 | } | 182 | } |
167 | s[num+j]<<=4; | 183 | s[num + j] <<= 4; |
168 | s[num+j]|=m; | 184 | s[num + j] |= m; |
169 | } | 185 | } |
170 | } | 186 | } |
171 | num+=i; | 187 | num += i; |
172 | if (again) | 188 | if (again) |
173 | bufsize=BIO_gets(bp,buf,size); | 189 | bufsize = BIO_gets(bp, buf, size); |
174 | else | 190 | else |
175 | break; | 191 | break; |
176 | } | 192 | } |
177 | bs->length=num; | 193 | bs->length = num; |
178 | bs->data=s; | 194 | bs->data = s; |
179 | ret=1; | 195 | ret = 1; |
196 | |||
180 | err: | 197 | err: |
181 | if (0) { | 198 | if (0) { |
182 | err_sl: | 199 | err_sl: |
183 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | 200 | ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE); |
184 | } | 201 | } |
185 | return(ret); | 202 | return (ret); |
186 | } | 203 | } |
187 | |||
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pr.c b/src/lib/libssl/src/crypto/asn1/d2i_pr.c index 5e6003ca5b..c356e3fda5 100644 --- a/src/lib/libssl/src/crypto/asn1/d2i_pr.c +++ b/src/lib/libssl/src/crypto/asn1/d2i_pr.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 |
@@ -68,18 +68,18 @@ | |||
68 | #include <openssl/asn1.h> | 68 | #include <openssl/asn1.h> |
69 | #include "asn1_locl.h" | 69 | #include "asn1_locl.h" |
70 | 70 | ||
71 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | 71 | EVP_PKEY * |
72 | long length) | 72 | d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) |
73 | { | 73 | { |
74 | EVP_PKEY *ret; | 74 | EVP_PKEY *ret; |
75 | 75 | ||
76 | if ((a == NULL) || (*a == NULL)) { | 76 | if ((a == NULL) || (*a == NULL)) { |
77 | if ((ret=EVP_PKEY_new()) == NULL) { | 77 | if ((ret = EVP_PKEY_new()) == NULL) { |
78 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | 78 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_EVP_LIB); |
79 | return(NULL); | 79 | return (NULL); |
80 | } | 80 | } |
81 | } else { | 81 | } else { |
82 | ret= *a; | 82 | ret = *a; |
83 | #ifndef OPENSSL_NO_ENGINE | 83 | #ifndef OPENSSL_NO_ENGINE |
84 | if (ret->engine) { | 84 | if (ret->engine) { |
85 | ENGINE_finish(ret->engine); | 85 | ENGINE_finish(ret->engine); |
@@ -89,40 +89,44 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
89 | } | 89 | } |
90 | 90 | ||
91 | if (!EVP_PKEY_set_type(ret, type)) { | 91 | if (!EVP_PKEY_set_type(ret, type)) { |
92 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 92 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
93 | goto err; | 93 | goto err; |
94 | } | 94 | } |
95 | 95 | ||
96 | if (!ret->ameth->old_priv_decode || | 96 | if (!ret->ameth->old_priv_decode || |
97 | !ret->ameth->old_priv_decode(ret, pp, length)) { | 97 | !ret->ameth->old_priv_decode(ret, pp, length)) { |
98 | if (ret->ameth->priv_decode) { | 98 | if (ret->ameth->priv_decode) { |
99 | PKCS8_PRIV_KEY_INFO *p8=NULL; | 99 | PKCS8_PRIV_KEY_INFO *p8 = NULL; |
100 | p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 100 | p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, length); |
101 | if (!p8) goto err; | 101 | if (!p8) |
102 | goto err; | ||
102 | EVP_PKEY_free(ret); | 103 | EVP_PKEY_free(ret); |
103 | ret = EVP_PKCS82PKEY(p8); | 104 | ret = EVP_PKCS82PKEY(p8); |
104 | PKCS8_PRIV_KEY_INFO_free(p8); | 105 | PKCS8_PRIV_KEY_INFO_free(p8); |
105 | |||
106 | } else { | 106 | } else { |
107 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | 107 | ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB); |
108 | goto err; | 108 | goto err; |
109 | } | 109 | } |
110 | } | 110 | } |
111 | if (a != NULL) (*a)=ret; | 111 | if (a != NULL) |
112 | return(ret); | 112 | (*a) = ret; |
113 | return (ret); | ||
114 | |||
113 | err: | 115 | err: |
114 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 116 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
115 | return(NULL); | 117 | EVP_PKEY_free(ret); |
118 | return (NULL); | ||
116 | } | 119 | } |
117 | 120 | ||
118 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | 121 | /* This works like d2i_PrivateKey() except it automatically works out the type */ |
119 | 122 | ||
120 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | 123 | EVP_PKEY * |
121 | long length) | 124 | d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length) |
122 | { | 125 | { |
123 | STACK_OF(ASN1_TYPE) *inkey; | 126 | STACK_OF(ASN1_TYPE) *inkey; |
124 | const unsigned char *p; | 127 | const unsigned char *p; |
125 | int keytype; | 128 | int keytype; |
129 | |||
126 | p = *pp; | 130 | p = *pp; |
127 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | 131 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): |
128 | * by analyzing it we can determine the passed structure: this | 132 | * by analyzing it we can determine the passed structure: this |
@@ -132,25 +136,27 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, | |||
132 | /* Since we only need to discern "traditional format" RSA and DSA | 136 | /* Since we only need to discern "traditional format" RSA and DSA |
133 | * keys we can just count the elements. | 137 | * keys we can just count the elements. |
134 | */ | 138 | */ |
135 | if(sk_ASN1_TYPE_num(inkey) == 6) | 139 | if (sk_ASN1_TYPE_num(inkey) == 6) |
136 | keytype = EVP_PKEY_DSA; | 140 | keytype = EVP_PKEY_DSA; |
137 | else if (sk_ASN1_TYPE_num(inkey) == 4) | 141 | else if (sk_ASN1_TYPE_num(inkey) == 4) |
138 | keytype = EVP_PKEY_EC; | 142 | keytype = EVP_PKEY_EC; |
139 | else if (sk_ASN1_TYPE_num(inkey) == 3) { | 143 | else if (sk_ASN1_TYPE_num(inkey) == 3) { |
140 | /* This seems to be PKCS8, not traditional format */ | 144 | /* This seems to be PKCS8, not traditional format */ |
141 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); | 145 | PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO( |
146 | NULL, pp, length); | ||
142 | EVP_PKEY *ret; | 147 | EVP_PKEY *ret; |
143 | 148 | ||
144 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | 149 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); |
145 | if (!p8) { | 150 | if (!p8) { |
146 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | 151 | ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY, |
152 | ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
147 | return NULL; | 153 | return NULL; |
148 | } | 154 | } |
149 | ret = EVP_PKCS82PKEY(p8); | 155 | ret = EVP_PKCS82PKEY(p8); |
150 | PKCS8_PRIV_KEY_INFO_free(p8); | 156 | PKCS8_PRIV_KEY_INFO_free(p8); |
151 | if (a) { | 157 | if (a) { |
152 | *a = ret; | 158 | *a = ret; |
153 | } | 159 | } |
154 | return ret; | 160 | return ret; |
155 | } else | 161 | } else |
156 | keytype = EVP_PKEY_RSA; | 162 | keytype = EVP_PKEY_RSA; |
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pu.c b/src/lib/libssl/src/crypto/asn1/d2i_pu.c index ccd03c066f..564f0945b5 100644 --- a/src/lib/libssl/src/crypto/asn1/d2i_pu.c +++ b/src/lib/libssl/src/crypto/asn1/d2i_pu.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 |
@@ -72,31 +72,31 @@ | |||
72 | #include <openssl/ec.h> | 72 | #include <openssl/ec.h> |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | 75 | EVP_PKEY * |
76 | long length) | 76 | d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) |
77 | { | 77 | { |
78 | EVP_PKEY *ret; | 78 | EVP_PKEY *ret; |
79 | 79 | ||
80 | if ((a == NULL) || (*a == NULL)) { | 80 | if ((a == NULL) || (*a == NULL)) { |
81 | if ((ret=EVP_PKEY_new()) == NULL) { | 81 | if ((ret = EVP_PKEY_new()) == NULL) { |
82 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 82 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); |
83 | return(NULL); | 83 | return (NULL); |
84 | } | 84 | } |
85 | } | 85 | } else |
86 | else ret= *a; | 86 | ret = *a; |
87 | 87 | ||
88 | if (!EVP_PKEY_set_type(ret, type)) { | 88 | if (!EVP_PKEY_set_type(ret, type)) { |
89 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | 89 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); |
90 | goto err; | 90 | goto err; |
91 | } | 91 | } |
92 | 92 | ||
93 | switch (EVP_PKEY_id(ret)) { | 93 | switch (EVP_PKEY_id(ret)) { |
94 | #ifndef OPENSSL_NO_RSA | 94 | #ifndef OPENSSL_NO_RSA |
95 | case EVP_PKEY_RSA: | 95 | case EVP_PKEY_RSA: |
96 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, | 96 | if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, |
97 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | 97 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ |
98 | { | 98 | { |
99 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 99 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
100 | goto err; | 100 | goto err; |
101 | } | 101 | } |
102 | break; | 102 | break; |
@@ -104,9 +104,9 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
104 | #ifndef OPENSSL_NO_DSA | 104 | #ifndef OPENSSL_NO_DSA |
105 | case EVP_PKEY_DSA: | 105 | case EVP_PKEY_DSA: |
106 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), | 106 | if (!d2i_DSAPublicKey(&(ret->pkey.dsa), |
107 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ | 107 | (const unsigned char **)pp,length)) /* TMP UGLY CAST */ |
108 | { | 108 | { |
109 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | 109 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
110 | goto err; | 110 | goto err; |
111 | } | 111 | } |
112 | break; | 112 | break; |
@@ -114,22 +114,23 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, | |||
114 | #ifndef OPENSSL_NO_EC | 114 | #ifndef OPENSSL_NO_EC |
115 | case EVP_PKEY_EC: | 115 | case EVP_PKEY_EC: |
116 | if (!o2i_ECPublicKey(&(ret->pkey.ec), | 116 | if (!o2i_ECPublicKey(&(ret->pkey.ec), |
117 | (const unsigned char **)pp, length)) | 117 | (const unsigned char **)pp, length)) { |
118 | { | ||
119 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); | 118 | ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); |
120 | goto err; | 119 | goto err; |
121 | } | 120 | } |
122 | break; | 121 | break; |
123 | #endif | 122 | #endif |
124 | default: | 123 | default: |
125 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | 124 | ASN1err(ASN1_F_D2I_PUBLICKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); |
126 | goto err; | 125 | goto err; |
127 | /* break; */ | 126 | /* break; */ |
128 | } | 127 | } |
129 | if (a != NULL) (*a)=ret; | 128 | if (a != NULL) |
130 | return(ret); | 129 | (*a) = ret; |
130 | return (ret); | ||
131 | |||
131 | err: | 132 | err: |
132 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | 133 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
133 | return(NULL); | 134 | EVP_PKEY_free(ret); |
135 | return (NULL); | ||
134 | } | 136 | } |
135 | |||
diff --git a/src/lib/libssl/src/crypto/asn1/evp_asn1.c b/src/lib/libssl/src/crypto/asn1/evp_asn1.c index d4ea675f89..4ff03de1f9 100644 --- a/src/lib/libssl/src/crypto/asn1/evp_asn1.c +++ b/src/lib/libssl/src/crypto/asn1/evp_asn1.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 |
@@ -61,84 +61,91 @@ | |||
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1_mac.h> |
63 | 63 | ||
64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | 64 | int |
65 | ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | ||
65 | { | 66 | { |
66 | ASN1_STRING *os; | 67 | ASN1_STRING *os; |
67 | 68 | ||
68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); | 69 | if ((os = M_ASN1_OCTET_STRING_new()) == NULL) |
69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); | 70 | return (0); |
70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); | 71 | if (!M_ASN1_OCTET_STRING_set(os, data, len)) |
71 | return(1); | 72 | return (0); |
73 | ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os); | ||
74 | return (1); | ||
72 | } | 75 | } |
73 | 76 | ||
74 | /* int max_len: for returned value */ | 77 | /* int max_len: for returned value */ |
75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | 78 | int |
76 | int max_len) | 79 | ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len) |
77 | { | 80 | { |
78 | int ret,num; | 81 | int ret, num; |
79 | unsigned char *p; | 82 | unsigned char *p; |
80 | 83 | ||
81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { | 84 | if ((a->type != V_ASN1_OCTET_STRING) || |
82 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 85 | (a->value.octet_string == NULL)) { |
83 | return(-1); | 86 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG); |
87 | return (-1); | ||
84 | } | 88 | } |
85 | p=M_ASN1_STRING_data(a->value.octet_string); | 89 | p = M_ASN1_STRING_data(a->value.octet_string); |
86 | ret=M_ASN1_STRING_length(a->value.octet_string); | 90 | ret = M_ASN1_STRING_length(a->value.octet_string); |
87 | if (ret < max_len) | 91 | if (ret < max_len) |
88 | num=ret; | 92 | num = ret; |
89 | else | 93 | else |
90 | num=max_len; | 94 | num = max_len; |
91 | memcpy(data,p,num); | 95 | memcpy(data, p, num); |
92 | return(ret); | 96 | return (ret); |
93 | } | 97 | } |
94 | 98 | ||
95 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | 99 | int |
96 | int len) | 100 | ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, |
101 | int len) | ||
97 | { | 102 | { |
98 | int n,size; | 103 | int n, size; |
99 | ASN1_OCTET_STRING os,*osp; | 104 | ASN1_OCTET_STRING os, *osp; |
100 | ASN1_INTEGER in; | 105 | ASN1_INTEGER in; |
101 | unsigned char *p; | 106 | unsigned char *p; |
102 | unsigned char buf[32]; /* when they have 256bit longs, | 107 | unsigned char buf[32]; /* when they have 256bit longs, |
103 | * I'll be in trouble */ | 108 | * I'll be in trouble */ |
104 | in.data=buf; | 109 | in.data = buf; |
105 | in.length=32; | 110 | in.length = 32; |
106 | os.data=data; | 111 | os.data = data; |
107 | os.type=V_ASN1_OCTET_STRING; | 112 | os.type = V_ASN1_OCTET_STRING; |
108 | os.length=len; | 113 | os.length = len; |
109 | ASN1_INTEGER_set(&in,num); | 114 | ASN1_INTEGER_set(&in, num); |
110 | n = i2d_ASN1_INTEGER(&in,NULL); | 115 | n = i2d_ASN1_INTEGER(&in, NULL); |
111 | n+=M_i2d_ASN1_OCTET_STRING(&os,NULL); | 116 | n += M_i2d_ASN1_OCTET_STRING(&os, NULL); |
112 | 117 | ||
113 | size=ASN1_object_size(1,n,V_ASN1_SEQUENCE); | 118 | size = ASN1_object_size(1, n, V_ASN1_SEQUENCE); |
114 | 119 | ||
115 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | 120 | if ((osp = ASN1_STRING_new()) == NULL) |
121 | return (0); | ||
116 | /* Grow the 'string' */ | 122 | /* Grow the 'string' */ |
117 | if (!ASN1_STRING_set(osp,NULL,size)) { | 123 | if (!ASN1_STRING_set(osp, NULL, size)) { |
118 | ASN1_STRING_free(osp); | 124 | ASN1_STRING_free(osp); |
119 | return(0); | 125 | return (0); |
120 | } | 126 | } |
121 | 127 | ||
122 | M_ASN1_STRING_length_set(osp, size); | 128 | M_ASN1_STRING_length_set(osp, size); |
123 | p=M_ASN1_STRING_data(osp); | 129 | p = M_ASN1_STRING_data(osp); |
124 | 130 | ||
125 | ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | 131 | ASN1_put_object(&p, 1,n, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); |
126 | i2d_ASN1_INTEGER(&in,&p); | 132 | i2d_ASN1_INTEGER(&in, &p); |
127 | M_i2d_ASN1_OCTET_STRING(&os,&p); | 133 | M_i2d_ASN1_OCTET_STRING(&os, &p); |
128 | 134 | ||
129 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); | 135 | ASN1_TYPE_set(a, V_ASN1_SEQUENCE, osp); |
130 | return(1); | 136 | return (1); |
131 | } | 137 | } |
132 | 138 | ||
133 | /* we return the actual length..., num may be missing, in which | 139 | /* we return the actual length..., num may be missing, in which |
134 | * case, set it to zero */ | 140 | * case, set it to zero */ |
135 | /* int max_len: for returned value */ | 141 | /* int max_len: for returned value */ |
136 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | 142 | int |
137 | int max_len) | 143 | ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, |
144 | int max_len) | ||
138 | { | 145 | { |
139 | int ret= -1,n; | 146 | int ret = -1, n; |
140 | ASN1_INTEGER *ai=NULL; | 147 | ASN1_INTEGER *ai = NULL; |
141 | ASN1_OCTET_STRING *os=NULL; | 148 | ASN1_OCTET_STRING *os = NULL; |
142 | const unsigned char *p; | 149 | const unsigned char *p; |
143 | long length; | 150 | long length; |
144 | ASN1_const_CTX c; | 151 | ASN1_const_CTX c; |
@@ -146,40 +153,45 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | |||
146 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { | 153 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { |
147 | goto err; | 154 | goto err; |
148 | } | 155 | } |
149 | p=M_ASN1_STRING_data(a->value.sequence); | 156 | p = M_ASN1_STRING_data(a->value.sequence); |
150 | length=M_ASN1_STRING_length(a->value.sequence); | 157 | length = M_ASN1_STRING_length(a->value.sequence); |
151 | 158 | ||
152 | c.pp= &p; | 159 | c.pp = &p; |
153 | c.p=p; | 160 | c.p = p; |
154 | c.max=p+length; | 161 | c.max = p + length; |
155 | c.error=ASN1_R_DATA_IS_WRONG; | 162 | c.error = ASN1_R_DATA_IS_WRONG; |
156 | 163 | ||
157 | M_ASN1_D2I_start_sequence(); | 164 | M_ASN1_D2I_start_sequence(); |
158 | c.q=c.p; | 165 | c.q = c.p; |
159 | if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; | 166 | if ((ai = d2i_ASN1_INTEGER(NULL, &c.p, c.slen)) == NULL) |
160 | c.slen-=(c.p-c.q); | 167 | goto err; |
161 | c.q=c.p; | 168 | c.slen -= (c.p - c.q); |
162 | if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; | 169 | c.q = c.p; |
163 | c.slen-=(c.p-c.q); | 170 | if ((os = d2i_ASN1_OCTET_STRING(NULL, &c.p, c.slen)) == NULL) |
164 | if (!M_ASN1_D2I_end_sequence()) goto err; | 171 | goto err; |
172 | c.slen -= (c.p - c.q); | ||
173 | if (!M_ASN1_D2I_end_sequence()) | ||
174 | goto err; | ||
165 | 175 | ||
166 | if (num != NULL) | 176 | if (num != NULL) |
167 | *num=ASN1_INTEGER_get(ai); | 177 | *num = ASN1_INTEGER_get(ai); |
168 | 178 | ||
169 | ret=M_ASN1_STRING_length(os); | 179 | ret = M_ASN1_STRING_length(os); |
170 | if (max_len > ret) | 180 | if (max_len > ret) |
171 | n=ret; | 181 | n = ret; |
172 | else | 182 | else |
173 | n=max_len; | 183 | n = max_len; |
174 | 184 | ||
175 | if (data != NULL) | 185 | if (data != NULL) |
176 | memcpy(data,M_ASN1_STRING_data(os),n); | 186 | memcpy(data, M_ASN1_STRING_data(os), n); |
177 | if (0) { | 187 | if (0) { |
178 | err: | 188 | err: |
179 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | 189 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, |
190 | ASN1_R_DATA_IS_WRONG); | ||
180 | } | 191 | } |
181 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 192 | if (os != NULL) |
182 | if (ai != NULL) M_ASN1_INTEGER_free(ai); | 193 | M_ASN1_OCTET_STRING_free(os); |
183 | return(ret); | 194 | if (ai != NULL) |
195 | M_ASN1_INTEGER_free(ai); | ||
196 | return (ret); | ||
184 | } | 197 | } |
185 | |||
diff --git a/src/lib/libssl/src/crypto/asn1/f_enum.c b/src/lib/libssl/src/crypto/asn1/f_enum.c index 4ccfbddf2a..e8736e5b72 100644 --- a/src/lib/libssl/src/crypto/asn1/f_enum.c +++ b/src/lib/libssl/src/crypto/asn1/f_enum.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,128 +63,145 @@ | |||
63 | 63 | ||
64 | /* Based on a_int.c: equivalent ENUMERATED functions */ | 64 | /* Based on a_int.c: equivalent ENUMERATED functions */ |
65 | 65 | ||
66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | 66 | int |
67 | i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | ||
67 | { | 68 | { |
68 | int i,n=0; | 69 | int i, n = 0; |
69 | static const char *h="0123456789ABCDEF"; | 70 | static const char *h = "0123456789ABCDEF"; |
70 | char buf[2]; | 71 | char buf[2]; |
71 | 72 | ||
72 | if (a == NULL) return(0); | 73 | if (a == NULL) |
74 | return (0); | ||
73 | 75 | ||
74 | if (a->length == 0) { | 76 | if (a->length == 0) { |
75 | if (BIO_write(bp,"00",2) != 2) goto err; | 77 | if (BIO_write(bp, "00", 2) != 2) |
76 | n=2; | 78 | goto err; |
79 | n = 2; | ||
77 | } else { | 80 | } else { |
78 | for (i=0; i<a->length; i++) { | 81 | for (i = 0; i < a->length; i++) { |
79 | if ((i != 0) && (i%35 == 0)) { | 82 | if ((i != 0) && (i % 35 == 0)) { |
80 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 83 | if (BIO_write(bp, "\\\n", 2) != 2) |
81 | n+=2; | 84 | goto err; |
85 | n += 2; | ||
82 | } | 86 | } |
83 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 87 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
84 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 88 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
85 | if (BIO_write(bp,buf,2) != 2) goto err; | 89 | if (BIO_write(bp, buf, 2) != 2) |
86 | n+=2; | 90 | goto err; |
91 | n += 2; | ||
87 | } | 92 | } |
88 | } | 93 | } |
89 | return(n); | 94 | return (n); |
95 | |||
90 | err: | 96 | err: |
91 | return(-1); | 97 | return (-1); |
92 | } | 98 | } |
93 | 99 | ||
94 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | 100 | int |
101 | a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | ||
95 | { | 102 | { |
96 | int ret=0; | 103 | int ret = 0; |
97 | int i,j,k,m,n,again,bufsize; | 104 | int i, j,k, m,n, again, bufsize; |
98 | unsigned char *s=NULL,*sp; | 105 | unsigned char *s = NULL, *sp; |
99 | unsigned char *bufp; | 106 | unsigned char *bufp; |
100 | int num=0,slen=0,first=1; | 107 | int num = 0, slen = 0, first = 1; |
101 | 108 | ||
102 | bs->type=V_ASN1_ENUMERATED; | 109 | bs->type = V_ASN1_ENUMERATED; |
103 | 110 | ||
104 | bufsize=BIO_gets(bp,buf,size); | 111 | bufsize = BIO_gets(bp, buf, size); |
105 | for (;;) { | 112 | for (;;) { |
106 | if (bufsize < 1) goto err_sl; | 113 | if (bufsize < 1) |
107 | i=bufsize; | 114 | goto err_sl; |
108 | if (buf[i-1] == '\n') buf[--i]='\0'; | 115 | i = bufsize; |
109 | if (i == 0) goto err_sl; | 116 | if (buf[i-1] == '\n') |
110 | if (buf[i-1] == '\r') buf[--i]='\0'; | 117 | buf[--i] = '\0'; |
111 | if (i == 0) goto err_sl; | 118 | if (i == 0) |
112 | again=(buf[i-1] == '\\'); | 119 | goto err_sl; |
120 | if (buf[i-1] == '\r') | ||
121 | buf[--i] = '\0'; | ||
122 | if (i == 0) | ||
123 | goto err_sl; | ||
124 | again = (buf[i - 1] == '\\'); | ||
113 | 125 | ||
114 | for (j=0; j<i; j++) { | 126 | for (j = 0; j < i; j++) { |
115 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 127 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
116 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 128 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
117 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 129 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
118 | i=j; | 130 | i = j; |
119 | break; | 131 | break; |
120 | } | 132 | } |
121 | } | 133 | } |
122 | buf[i]='\0'; | 134 | buf[i] = '\0'; |
123 | /* We have now cleared all the crap off the end of the | 135 | /* We have now cleared all the crap off the end of the |
124 | * line */ | 136 | * line */ |
125 | if (i < 2) goto err_sl; | 137 | if (i < 2) |
138 | goto err_sl; | ||
126 | 139 | ||
127 | bufp=(unsigned char *)buf; | 140 | bufp = (unsigned char *)buf; |
128 | if (first) { | 141 | if (first) { |
129 | first=0; | 142 | first = 0; |
130 | if ((bufp[0] == '0') && (buf[1] == '0')) { | 143 | if ((bufp[0] == '0') && (buf[1] == '0')) { |
131 | bufp+=2; | 144 | bufp += 2; |
132 | i-=2; | 145 | i -= 2; |
133 | } | 146 | } |
134 | } | 147 | } |
135 | k=0; | 148 | k = 0; |
136 | i-=again; | 149 | i -= again; |
137 | if (i%2 != 0) { | 150 | if (i % 2 != 0) { |
138 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); | 151 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, |
152 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
139 | goto err; | 153 | goto err; |
140 | } | 154 | } |
141 | i/=2; | 155 | i /= 2; |
142 | if (num+i > slen) { | 156 | if (num + i > slen) { |
143 | if (s == NULL) | 157 | if (s == NULL) |
144 | sp=(unsigned char *)malloc( | 158 | sp = (unsigned char *)malloc( |
145 | (unsigned int)num+i*2); | 159 | (unsigned int)num + i * 2); |
146 | else | 160 | else |
147 | sp=(unsigned char *)realloc(s, | 161 | sp = (unsigned char *)realloc(s, |
148 | (unsigned int)num+i*2); | 162 | (unsigned int)num + i * 2); |
149 | if (sp == NULL) { | 163 | if (sp == NULL) { |
150 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | 164 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, |
151 | if (s != NULL) free(s); | 165 | ERR_R_MALLOC_FAILURE); |
166 | if (s != NULL) | ||
167 | free(s); | ||
152 | goto err; | 168 | goto err; |
153 | } | 169 | } |
154 | s=sp; | 170 | s = sp; |
155 | slen=num+i*2; | 171 | slen = num + i * 2; |
156 | } | 172 | } |
157 | for (j=0; j<i; j++,k+=2) { | 173 | for (j = 0; j < i; j++, k += 2) { |
158 | for (n=0; n<2; n++) { | 174 | for (n = 0; n < 2; n++) { |
159 | m=bufp[k+n]; | 175 | m = bufp[k + n]; |
160 | if ((m >= '0') && (m <= '9')) | 176 | if ((m >= '0') && (m <= '9')) |
161 | m-='0'; | 177 | m -= '0'; |
162 | else if ((m >= 'a') && (m <= 'f')) | 178 | else if ((m >= 'a') && (m <= 'f')) |
163 | m=m-'a'+10; | 179 | m = m - 'a' + 10; |
164 | else if ((m >= 'A') && (m <= 'F')) | 180 | else if ((m >= 'A') && (m <= 'F')) |
165 | m=m-'A'+10; | 181 | m = m - 'A' + 10; |
166 | else { | 182 | else { |
167 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); | 183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, |
184 | ASN1_R_NON_HEX_CHARACTERS); | ||
168 | goto err; | 185 | goto err; |
169 | } | 186 | } |
170 | s[num+j]<<=4; | 187 | s[num + j] <<= 4; |
171 | s[num+j]|=m; | 188 | s[num + j] |= m; |
172 | } | 189 | } |
173 | } | 190 | } |
174 | num+=i; | 191 | num += i; |
175 | if (again) | 192 | if (again) |
176 | bufsize=BIO_gets(bp,buf,size); | 193 | bufsize = BIO_gets(bp, buf, size); |
177 | else | 194 | else |
178 | break; | 195 | break; |
179 | } | 196 | } |
180 | bs->length=num; | 197 | bs->length = num; |
181 | bs->data=s; | 198 | bs->data = s; |
182 | ret=1; | 199 | ret = 1; |
200 | |||
183 | err: | 201 | err: |
184 | if (0) { | 202 | if (0) { |
185 | err_sl: | 203 | err_sl: |
186 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); | 204 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ASN1_R_SHORT_LINE); |
187 | } | 205 | } |
188 | return(ret); | 206 | return (ret); |
189 | } | 207 | } |
190 | |||
diff --git a/src/lib/libssl/src/crypto/asn1/f_int.c b/src/lib/libssl/src/crypto/asn1/f_int.c index 6cea1f8485..f355dbacbe 100644 --- a/src/lib/libssl/src/crypto/asn1/f_int.c +++ b/src/lib/libssl/src/crypto/asn1/f_int.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 |
@@ -61,132 +61,151 @@ | |||
61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | 64 | int |
65 | i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | ||
65 | { | 66 | { |
66 | int i,n=0; | 67 | int i, n = 0; |
67 | static const char *h="0123456789ABCDEF"; | 68 | static const char *h = "0123456789ABCDEF"; |
68 | char buf[2]; | 69 | char buf[2]; |
69 | 70 | ||
70 | if (a == NULL) return(0); | 71 | if (a == NULL) |
72 | return (0); | ||
71 | 73 | ||
72 | if (a->type & V_ASN1_NEG) { | 74 | if (a->type & V_ASN1_NEG) { |
73 | if (BIO_write(bp, "-", 1) != 1) goto err; | 75 | if (BIO_write(bp, "-", 1) != 1) |
76 | goto err; | ||
74 | n = 1; | 77 | n = 1; |
75 | } | 78 | } |
76 | 79 | ||
77 | if (a->length == 0) { | 80 | if (a->length == 0) { |
78 | if (BIO_write(bp,"00",2) != 2) goto err; | 81 | if (BIO_write(bp, "00", 2) != 2) |
82 | goto err; | ||
79 | n += 2; | 83 | n += 2; |
80 | } else { | 84 | } else { |
81 | for (i=0; i<a->length; i++) { | 85 | for (i = 0; i < a->length; i++) { |
82 | if ((i != 0) && (i%35 == 0)) { | 86 | if ((i != 0) && (i % 35 == 0)) { |
83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 87 | if (BIO_write(bp, "\\\n", 2) != 2) |
84 | n+=2; | 88 | goto err; |
89 | n += 2; | ||
85 | } | 90 | } |
86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 91 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 92 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
88 | if (BIO_write(bp,buf,2) != 2) goto err; | 93 | if (BIO_write(bp, buf, 2) != 2) |
89 | n+=2; | 94 | goto err; |
95 | n += 2; | ||
90 | } | 96 | } |
91 | } | 97 | } |
92 | return(n); | 98 | return (n); |
99 | |||
93 | err: | 100 | err: |
94 | return(-1); | 101 | return (-1); |
95 | } | 102 | } |
96 | 103 | ||
97 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | 104 | int |
105 | a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | ||
98 | { | 106 | { |
99 | int ret=0; | 107 | int ret = 0; |
100 | int i,j,k,m,n,again,bufsize; | 108 | int i, j,k, m,n, again, bufsize; |
101 | unsigned char *s=NULL,*sp; | 109 | unsigned char *s = NULL, *sp; |
102 | unsigned char *bufp; | 110 | unsigned char *bufp; |
103 | int num=0,slen=0,first=1; | 111 | int num = 0, slen = 0, first = 1; |
104 | 112 | ||
105 | bs->type=V_ASN1_INTEGER; | 113 | bs->type = V_ASN1_INTEGER; |
106 | 114 | ||
107 | bufsize=BIO_gets(bp,buf,size); | 115 | bufsize = BIO_gets(bp, buf, size); |
108 | for (;;) { | 116 | for (;;) { |
109 | if (bufsize < 1) goto err_sl; | 117 | if (bufsize < 1) |
110 | i=bufsize; | 118 | goto err_sl; |
111 | if (buf[i-1] == '\n') buf[--i]='\0'; | 119 | i = bufsize; |
112 | if (i == 0) goto err_sl; | 120 | if (buf[i - 1] == '\n') |
113 | if (buf[i-1] == '\r') buf[--i]='\0'; | 121 | buf[--i] = '\0'; |
114 | if (i == 0) goto err_sl; | 122 | if (i == 0) |
115 | again=(buf[i-1] == '\\'); | 123 | goto err_sl; |
124 | if (buf[i - 1] == '\r') | ||
125 | buf[--i] = '\0'; | ||
126 | if (i == 0) | ||
127 | goto err_sl; | ||
128 | again = (buf[i - 1] == '\\'); | ||
116 | 129 | ||
117 | for (j=0; j<i; j++) { | 130 | for (j = 0; j < i; j++) { |
118 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 131 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
119 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 132 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
120 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 133 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
121 | i=j; | 134 | i = j; |
122 | break; | 135 | break; |
123 | } | 136 | } |
124 | } | 137 | } |
125 | buf[i]='\0'; | 138 | buf[i] = '\0'; |
126 | /* We have now cleared all the crap off the end of the | 139 | /* We have now cleared all the crap off the end of the |
127 | * line */ | 140 | * line */ |
128 | if (i < 2) goto err_sl; | 141 | if (i < 2) |
142 | goto err_sl; | ||
129 | 143 | ||
130 | bufp=(unsigned char *)buf; | 144 | bufp = (unsigned char *)buf; |
131 | if (first) { | 145 | if (first) { |
132 | first=0; | 146 | first = 0; |
133 | if ((bufp[0] == '0') && (buf[1] == '0')) { | 147 | if ((bufp[0] == '0') && (buf[1] == '0')) { |
134 | bufp+=2; | 148 | bufp += 2; |
135 | i-=2; | 149 | i -= 2; |
136 | } | 150 | } |
137 | } | 151 | } |
138 | k=0; | 152 | k = 0; |
139 | i-=again; | 153 | i -= again; |
140 | if (i%2 != 0) { | 154 | if (i % 2 != 0) { |
141 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | 155 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, |
156 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
142 | goto err; | 157 | goto err; |
143 | } | 158 | } |
144 | i/=2; | 159 | i /= 2; |
145 | if (num+i > slen) { | 160 | if (num + i > slen) { |
146 | if (s == NULL) | 161 | if (s == NULL) |
147 | sp=(unsigned char *)malloc( | 162 | sp = (unsigned char *)malloc( |
148 | (unsigned int)num+i*2); | 163 | (unsigned int)num + i * 2); |
149 | else | 164 | else |
150 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | 165 | sp = OPENSSL_realloc_clean(s, slen, |
166 | num + i * 2); | ||
151 | if (sp == NULL) { | 167 | if (sp == NULL) { |
152 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 168 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, |
153 | if (s != NULL) free(s); | 169 | ERR_R_MALLOC_FAILURE); |
170 | if (s != NULL) | ||
171 | free(s); | ||
154 | goto err; | 172 | goto err; |
155 | } | 173 | } |
156 | s=sp; | 174 | s = sp; |
157 | slen=num+i*2; | 175 | slen = num + i * 2; |
158 | } | 176 | } |
159 | for (j=0; j<i; j++,k+=2) { | 177 | for (j = 0; j < i; j++, k += 2) { |
160 | for (n=0; n<2; n++) { | 178 | for (n = 0; n < 2; n++) { |
161 | m=bufp[k+n]; | 179 | m = bufp[k + n]; |
162 | if ((m >= '0') && (m <= '9')) | 180 | if ((m >= '0') && (m <= '9')) |
163 | m-='0'; | 181 | m -= '0'; |
164 | else if ((m >= 'a') && (m <= 'f')) | 182 | else if ((m >= 'a') && (m <= 'f')) |
165 | m=m-'a'+10; | 183 | m = m - 'a' + 10; |
166 | else if ((m >= 'A') && (m <= 'F')) | 184 | else if ((m >= 'A') && (m <= 'F')) |
167 | m=m-'A'+10; | 185 | m = m - 'A' + 10; |
168 | else { | 186 | else { |
169 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | 187 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, |
188 | ASN1_R_NON_HEX_CHARACTERS); | ||
170 | goto err; | 189 | goto err; |
171 | } | 190 | } |
172 | s[num+j]<<=4; | 191 | s[num + j] <<= 4; |
173 | s[num+j]|=m; | 192 | s[num + j] |= m; |
174 | } | 193 | } |
175 | } | 194 | } |
176 | num+=i; | 195 | num += i; |
177 | if (again) | 196 | if (again) |
178 | bufsize=BIO_gets(bp,buf,size); | 197 | bufsize = BIO_gets(bp, buf, size); |
179 | else | 198 | else |
180 | break; | 199 | break; |
181 | } | 200 | } |
182 | bs->length=num; | 201 | bs->length = num; |
183 | bs->data=s; | 202 | bs->data = s; |
184 | ret=1; | 203 | ret = 1; |
204 | |||
185 | err: | 205 | err: |
186 | if (0) { | 206 | if (0) { |
187 | err_sl: | 207 | err_sl: |
188 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | 208 | ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE); |
189 | } | 209 | } |
190 | return(ret); | 210 | return (ret); |
191 | } | 211 | } |
192 | |||
diff --git a/src/lib/libssl/src/crypto/asn1/f_string.c b/src/lib/libssl/src/crypto/asn1/f_string.c index 87d7aaa0dd..d42bcdb6ea 100644 --- a/src/lib/libssl/src/crypto/asn1/f_string.c +++ b/src/lib/libssl/src/crypto/asn1/f_string.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 |
@@ -61,43 +61,50 @@ | |||
61 | #include <openssl/buffer.h> | 61 | #include <openssl/buffer.h> |
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | 63 | ||
64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | 64 | int |
65 | i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | ||
65 | { | 66 | { |
66 | int i,n=0; | 67 | int i, n = 0; |
67 | static const char *h="0123456789ABCDEF"; | 68 | static const char *h = "0123456789ABCDEF"; |
68 | char buf[2]; | 69 | char buf[2]; |
69 | 70 | ||
70 | if (a == NULL) return(0); | 71 | if (a == NULL) |
72 | return (0); | ||
71 | 73 | ||
72 | if (a->length == 0) { | 74 | if (a->length == 0) { |
73 | if (BIO_write(bp,"0",1) != 1) goto err; | 75 | if (BIO_write(bp, "0", 1) != 1) |
74 | n=1; | 76 | goto err; |
77 | n = 1; | ||
75 | } else { | 78 | } else { |
76 | for (i=0; i<a->length; i++) { | 79 | for (i = 0; i < a->length; i++) { |
77 | if ((i != 0) && (i%35 == 0)) { | 80 | if ((i != 0) && (i % 35 == 0)) { |
78 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 81 | if (BIO_write(bp, "\\\n", 2) != 2) |
79 | n+=2; | 82 | goto err; |
83 | n += 2; | ||
80 | } | 84 | } |
81 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | 85 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; |
82 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | 86 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; |
83 | if (BIO_write(bp,buf,2) != 2) goto err; | 87 | if (BIO_write(bp, buf, 2) != 2) |
84 | n+=2; | 88 | goto err; |
89 | n += 2; | ||
85 | } | 90 | } |
86 | } | 91 | } |
87 | return(n); | 92 | return (n); |
93 | |||
88 | err: | 94 | err: |
89 | return(-1); | 95 | return (-1); |
90 | } | 96 | } |
91 | 97 | ||
92 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | 98 | int |
99 | a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | ||
93 | { | 100 | { |
94 | int ret=0; | 101 | int ret = 0; |
95 | int i,j,k,m,n,again,bufsize; | 102 | int i, j, k, m, n, again, bufsize; |
96 | unsigned char *s=NULL,*sp; | 103 | unsigned char *s = NULL, *sp; |
97 | unsigned char *bufp; | 104 | unsigned char *bufp; |
98 | int num=0,slen=0,first=1; | 105 | int num = 0, slen = 0, first = 1; |
99 | 106 | ||
100 | bufsize=BIO_gets(bp,buf,size); | 107 | bufsize = BIO_gets(bp, buf, size); |
101 | for (;;) { | 108 | for (;;) { |
102 | if (bufsize < 1) { | 109 | if (bufsize < 1) { |
103 | if (first) | 110 | if (first) |
@@ -105,83 +112,92 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | |||
105 | else | 112 | else |
106 | goto err_sl; | 113 | goto err_sl; |
107 | } | 114 | } |
108 | first=0; | 115 | first = 0; |
109 | 116 | ||
110 | i=bufsize; | 117 | i = bufsize; |
111 | if (buf[i-1] == '\n') buf[--i]='\0'; | 118 | if (buf[i-1] == '\n') |
112 | if (i == 0) goto err_sl; | 119 | buf[--i] = '\0'; |
113 | if (buf[i-1] == '\r') buf[--i]='\0'; | 120 | if (i == 0) |
114 | if (i == 0) goto err_sl; | 121 | goto err_sl; |
115 | again=(buf[i-1] == '\\'); | 122 | if (buf[i-1] == '\r') |
123 | buf[--i] = '\0'; | ||
124 | if (i == 0) | ||
125 | goto err_sl; | ||
126 | again = (buf[i - 1] == '\\'); | ||
116 | 127 | ||
117 | for (j=i-1; j>0; j--) { | 128 | for (j = i - 1; j > 0; j--) { |
118 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 129 | if (!(((buf[j] >= '0') && (buf[j] <= '9')) || |
119 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 130 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
120 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { | 131 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
121 | i=j; | 132 | i = j; |
122 | break; | 133 | break; |
123 | } | 134 | } |
124 | } | 135 | } |
125 | buf[i]='\0'; | 136 | buf[i] = '\0'; |
126 | /* We have now cleared all the crap off the end of the | 137 | /* We have now cleared all the crap off the end of the |
127 | * line */ | 138 | * line */ |
128 | if (i < 2) goto err_sl; | 139 | if (i < 2) |
140 | goto err_sl; | ||
129 | 141 | ||
130 | bufp=(unsigned char *)buf; | 142 | bufp = (unsigned char *)buf; |
131 | 143 | ||
132 | k=0; | 144 | k = 0; |
133 | i-=again; | 145 | i -= again; |
134 | if (i%2 != 0) { | 146 | if (i % 2 != 0) { |
135 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | 147 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
148 | ASN1_R_ODD_NUMBER_OF_CHARS); | ||
136 | goto err; | 149 | goto err; |
137 | } | 150 | } |
138 | i/=2; | 151 | i /= 2; |
139 | if (num+i > slen) { | 152 | if (num + i > slen) { |
140 | if (s == NULL) | 153 | if (s == NULL) |
141 | sp=(unsigned char *)malloc( | 154 | sp = (unsigned char *)malloc( |
142 | (unsigned int)num+i*2); | 155 | (unsigned int)num + i * 2); |
143 | else | 156 | else |
144 | sp=(unsigned char *)realloc(s, | 157 | sp = (unsigned char *)realloc(s, |
145 | (unsigned int)num+i*2); | 158 | (unsigned int)num + i * 2); |
146 | if (sp == NULL) { | 159 | if (sp == NULL) { |
147 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | 160 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
148 | if (s != NULL) free(s); | 161 | ERR_R_MALLOC_FAILURE); |
162 | if (s != NULL) | ||
163 | free(s); | ||
149 | goto err; | 164 | goto err; |
150 | } | 165 | } |
151 | s=sp; | 166 | s = sp; |
152 | slen=num+i*2; | 167 | slen = num + i * 2; |
153 | } | 168 | } |
154 | for (j=0; j<i; j++,k+=2) { | 169 | for (j = 0; j < i; j++, k += 2) { |
155 | for (n=0; n<2; n++) { | 170 | for (n = 0; n < 2; n++) { |
156 | m=bufp[k+n]; | 171 | m = bufp[k + n]; |
157 | if ((m >= '0') && (m <= '9')) | 172 | if ((m >= '0') && (m <= '9')) |
158 | m-='0'; | 173 | m -= '0'; |
159 | else if ((m >= 'a') && (m <= 'f')) | 174 | else if ((m >= 'a') && (m <= 'f')) |
160 | m=m-'a'+10; | 175 | m = m - 'a' + 10; |
161 | else if ((m >= 'A') && (m <= 'F')) | 176 | else if ((m >= 'A') && (m <= 'F')) |
162 | m=m-'A'+10; | 177 | m = m - 'A' + 10; |
163 | else { | 178 | else { |
164 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | 179 | ASN1err(ASN1_F_A2I_ASN1_STRING, |
180 | ASN1_R_NON_HEX_CHARACTERS); | ||
165 | goto err; | 181 | goto err; |
166 | } | 182 | } |
167 | s[num+j]<<=4; | 183 | s[num + j] <<= 4; |
168 | s[num+j]|=m; | 184 | s[num + j] |= m; |
169 | } | 185 | } |
170 | } | 186 | } |
171 | num+=i; | 187 | num += i; |
172 | if (again) | 188 | if (again) |
173 | bufsize=BIO_gets(bp,buf,size); | 189 | bufsize = BIO_gets(bp, buf, size); |
174 | else | 190 | else |
175 | break; | 191 | break; |
176 | } | 192 | } |
177 | bs->length=num; | 193 | bs->length = num; |
178 | bs->data=s; | 194 | bs->data = s; |
179 | ret=1; | 195 | ret = 1; |
196 | |||
180 | err: | 197 | err: |
181 | if (0) { | 198 | if (0) { |
182 | err_sl: | 199 | err_sl: |
183 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | 200 | ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE); |
184 | } | 201 | } |
185 | return(ret); | 202 | return (ret); |
186 | } | 203 | } |
187 | |||