summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c4
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c24
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c54
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c141
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c191
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c108
-rw-r--r--src/lib/libcrypto/asn1/a_int.c347
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c196
-rw-r--r--src/lib/libcrypto/asn1/a_object.c287
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c34
-rw-r--r--src/lib/libcrypto/asn1/a_print.c91
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_bitstr.c4
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_digest.c24
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_dup.c54
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_enum.c141
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_gentm.c191
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_i2d_fp.c108
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_int.c347
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_mbstr.c196
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_object.c287
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_octet.c34
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_print.c91
22 files changed, 1626 insertions, 1328 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index 5633cfca1c..c578ce6279 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -69,7 +69,7 @@ ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
69int 69int
70i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) 70i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
71{ 71{
72 int ret, j,bits, len; 72 int ret, j, bits, len;
73 unsigned char *p, *d; 73 unsigned char *p, *d;
74 74
75 if (a == NULL) 75 if (a == NULL)
@@ -198,7 +198,7 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
198 if (a == NULL) 198 if (a == NULL)
199 return 0; 199 return 0;
200 200
201 a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ 201 a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear, set on write */
202 202
203 if ((a->length < (w + 1)) || (a->data == NULL)) { 203 if ((a->length < (w + 1)) || (a->data == NULL)) {
204 if (!value) 204 if (!value)
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
index e87d4396df..76a62f7c00 100644
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ b/src/lib/libcrypto/asn1/a_digest.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
@@ -70,17 +70,19 @@
70#include <openssl/buffer.h> 70#include <openssl/buffer.h>
71#include <openssl/x509.h> 71#include <openssl/x509.h>
72 72
73int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, 73int
74 unsigned char *md, unsigned int *len) 74ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
75 unsigned char *md, unsigned int *len)
75{ 76{
76 int i; 77 int i;
77 unsigned char *str = NULL; 78 unsigned char *str = NULL;
78 79
79 i=ASN1_item_i2d(asn,&str, it); 80 i = ASN1_item_i2d(asn, &str, it);
80 if (!str) return(0); 81 if (!str)
82 return (0);
81 83
82 if (!EVP_Digest(str, i, md, len, type, NULL)) 84 if (!EVP_Digest(str, i, md, len, type, NULL))
83 return 0; 85 return 0;
84 free(str); 86 free(str);
85 return(1); 87 return (1);
86} 88}
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
index 409bdcf2d1..5f5c4951ea 100644
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ b/src/lib/libcrypto/asn1/a_dup.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
@@ -62,28 +62,29 @@
62 62
63#ifndef NO_OLD_ASN1 63#ifndef NO_OLD_ASN1
64 64
65void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) 65void *
66ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
66{ 67{
67 unsigned char *b,*p; 68 unsigned char *b, *p;
68 const unsigned char *p2; 69 const unsigned char *p2;
69 int i; 70 int i;
70 char *ret; 71 char *ret;
71 72
72 if (x == NULL) 73 if (x == NULL)
73 return(NULL); 74 return (NULL);
74 75
75 i=i2d(x,NULL); 76 i = i2d(x, NULL);
76 b=malloc(i+10); 77 b = malloc(i + 10);
77 if (b == NULL) { 78 if (b == NULL) {
78 ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); 79 ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE);
79 return(NULL); 80 return (NULL);
80 } 81 }
81 p= b; 82 p = b;
82 i=i2d(x,&p); 83 i = i2d(x, &p);
83 p2= b; 84 p2 = b;
84 ret=d2i(NULL,&p2,i); 85 ret = d2i(NULL, &p2, i);
85 free(b); 86 free(b);
86 return(ret); 87 return (ret);
87} 88}
88 89
89#endif 90#endif
@@ -93,7 +94,8 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
93 * the underlying structure instead of doing and encode and decode. 94 * the underlying structure instead of doing and encode and decode.
94 */ 95 */
95 96
96void *ASN1_item_dup(const ASN1_ITEM *it, void *x) 97void *
98ASN1_item_dup(const ASN1_ITEM *it, void *x)
97{ 99{
98 unsigned char *b = NULL; 100 unsigned char *b = NULL;
99 const unsigned char *p; 101 const unsigned char *p;
@@ -101,15 +103,15 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
101 void *ret; 103 void *ret;
102 104
103 if (x == NULL) 105 if (x == NULL)
104 return(NULL); 106 return (NULL);
105 107
106 i=ASN1_item_i2d(x,&b,it); 108 i = ASN1_item_i2d(x, &b, it);
107 if (b == NULL) { 109 if (b == NULL) {
108 ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); 110 ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
109 return(NULL); 111 return (NULL);
110 } 112 }
111 p= b; 113 p = b;
112 ret=ASN1_item_d2i(NULL,&p,i, it); 114 ret = ASN1_item_d2i(NULL, &p, i, it);
113 free(b); 115 free(b);
114 return(ret); 116 return (ret);
115} 117}
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index 70cea0aad2..5e6f7589cf 100644
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ b/src/lib/libcrypto/asn1/a_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
@@ -61,114 +61,125 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63 63
64/* 64/*
65 * Code for ENUMERATED type: identical to INTEGER apart from a different tag. 65 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
66 * for comments on encoding see a_int.c 66 * for comments on encoding see a_int.c
67 */ 67 */
68 68
69int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) 69int
70ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
70{ 71{
71 int j,k; 72 int j, k;
72 unsigned int i; 73 unsigned int i;
73 unsigned char buf[sizeof(long)+1]; 74 unsigned char buf[sizeof(long) + 1];
74 long d; 75 long d;
75 76
76 a->type=V_ASN1_ENUMERATED; 77 a->type = V_ASN1_ENUMERATED;
77 if (a->length < (int)(sizeof(long)+1)) { 78 if (a->length < (int)(sizeof(long) + 1)) {
78 if (a->data != NULL) 79 if (a->data != NULL)
79 free(a->data); 80 free(a->data);
80 if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) 81 if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
81 memset((char *)a->data,0,sizeof(long)+1); 82 memset((char *)a->data, 0, sizeof(long) + 1);
82 } 83 }
83 if (a->data == NULL) { 84 if (a->data == NULL) {
84 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); 85 ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
85 return(0); 86 return (0);
86 } 87 }
87 d=v; 88 d = v;
88 if (d < 0) { 89 if (d < 0) {
89 d= -d; 90 d = -d;
90 a->type=V_ASN1_NEG_ENUMERATED; 91 a->type = V_ASN1_NEG_ENUMERATED;
91 } 92 }
92 93
93 for (i=0; i<sizeof(long); i++) { 94 for (i = 0; i < sizeof(long); i++) {
94 if (d == 0) break; 95 if (d == 0)
95 buf[i]=(int)d&0xff; 96 break;
96 d>>=8; 97 buf[i] = (int)d & 0xff;
98 d >>= 8;
97 } 99 }
98 j=0; 100 j = 0;
99 for (k=i-1; k >=0; k--) 101 for (k = i - 1; k >=0; k--)
100 a->data[j++]=buf[k]; 102 a->data[j++] = buf[k];
101 a->length=j; 103 a->length = j;
102 return(1); 104 return (1);
103} 105}
104 106
105long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) 107long
108ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
106{ 109{
107 int neg=0,i; 110 int neg = 0, i;
108 long r=0; 111 long r = 0;
109 112
110 if (a == NULL) return(0L); 113 if (a == NULL)
111 i=a->type; 114 return (0L);
115 i = a->type;
112 if (i == V_ASN1_NEG_ENUMERATED) 116 if (i == V_ASN1_NEG_ENUMERATED)
113 neg=1; 117 neg = 1;
114 else if (i != V_ASN1_ENUMERATED) 118 else if (i != V_ASN1_ENUMERATED)
115 return -1; 119 return -1;
116 120
117 if (a->length > (int)sizeof(long)) { 121 if (a->length > (int)sizeof(long)) {
118 /* hmm... a bit ugly */ 122 /* hmm... a bit ugly */
119 return(0xffffffffL); 123 return (0xffffffffL);
120 } 124 }
121 if (a->data == NULL) 125 if (a->data == NULL)
122 return 0; 126 return 0;
123 127
124 for (i=0; i<a->length; i++) { 128 for (i = 0; i < a->length; i++) {
125 r<<=8; 129 r <<= 8;
126 r|=(unsigned char)a->data[i]; 130 r |= (unsigned char)a->data[i];
127 } 131 }
128 if (neg) r= -r; 132 if (neg)
129 return(r); 133 r = -r;
134 return (r);
130} 135}
131 136
132ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) 137ASN1_ENUMERATED *
138BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
133{ 139{
134 ASN1_ENUMERATED *ret; 140 ASN1_ENUMERATED *ret;
135 int len,j; 141 int len, j;
136 142
137 if (ai == NULL) 143 if (ai == NULL)
138 ret=M_ASN1_ENUMERATED_new(); 144 ret = M_ASN1_ENUMERATED_new();
139 else 145 else
140 ret=ai; 146 ret = ai;
141 if (ret == NULL) { 147 if (ret == NULL) {
142 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); 148 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_NESTED_ASN1_ERROR);
143 goto err; 149 goto err;
144 } 150 }
145 if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; 151 if (BN_is_negative(bn))
146 else ret->type=V_ASN1_ENUMERATED; 152 ret->type = V_ASN1_NEG_ENUMERATED;
147 j=BN_num_bits(bn); 153 else
148 len=((j == 0)?0:((j/8)+1)); 154 ret->type = V_ASN1_ENUMERATED;
149 if (ret->length < len+4) { 155 j = BN_num_bits(bn);
150 unsigned char *new_data=realloc(ret->data, len+4); 156 len = ((j == 0) ? 0 : ((j / 8) + 1));
151 if (!new_data) 157 if (ret->length < len + 4) {
152 { 158 unsigned char *new_data = realloc(ret->data, len + 4);
153 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); 159 if (!new_data) {
160 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
154 goto err; 161 goto err;
155 } 162 }
156 ret->data=new_data; 163 ret->data = new_data;
157 } 164 }
158 165
159 ret->length=BN_bn2bin(bn,ret->data); 166 ret->length = BN_bn2bin(bn, ret->data);
160 return(ret); 167 return (ret);
168
161err: 169err:
162 if (ret != ai) M_ASN1_ENUMERATED_free(ret); 170 if (ret != ai)
163 return(NULL); 171 M_ASN1_ENUMERATED_free(ret);
172 return (NULL);
164} 173}
165 174
166BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) 175BIGNUM *
176ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
167{ 177{
168 BIGNUM *ret; 178 BIGNUM *ret;
169 179
170 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 180 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
171 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); 181 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN, ASN1_R_BN_LIB);
172 else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); 182 else if (ai->type == V_ASN1_NEG_ENUMERATED)
173 return(ret); 183 BN_set_negative(ret, 1);
184 return (ret);
174} 185}
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
index 2ef6e6bc22..56f8992424 100644
--- a/src/lib/libcrypto/asn1/a_gentm.c
+++ b/src/lib/libcrypto/asn1/a_gentm.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
@@ -48,8 +48,8 @@
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -66,170 +66,187 @@
66 66
67#if 0 67#if 0
68 68
69int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) 69int
70i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
70{ 71{
71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 72 return(i2d_ASN1_bytes((ASN1_STRING *)a, pp,
72 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); 73 V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL));
73} 74}
74 75
75 76
76ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, 77ASN1_GENERALIZEDTIME *
77 unsigned char **pp, long length) 78d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, unsigned char **pp,
79 long length)
78{ 80{
79 ASN1_GENERALIZEDTIME *ret=NULL; 81 ASN1_GENERALIZEDTIME *ret = NULL;
80 82
81 ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, 83 ret = (ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
82 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); 84 V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL);
83 if (ret == NULL) 85 if (ret == NULL) {
84 { 86 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ERR_R_NESTED_ASN1_ERROR);
85 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); 87 return (NULL);
86 return(NULL);
87 } 88 }
88 if (!ASN1_GENERALIZEDTIME_check(ret)) 89 if (!ASN1_GENERALIZEDTIME_check(ret)) {
89 { 90 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ASN1_R_INVALID_TIME_FORMAT);
90 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
91 goto err; 91 goto err;
92 } 92 }
93 93
94 return(ret); 94 return (ret);
95
95err: 96err:
96 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 97 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
97 M_ASN1_GENERALIZEDTIME_free(ret); 98 M_ASN1_GENERALIZEDTIME_free(ret);
98 return(NULL); 99 return (NULL);
99} 100}
100 101
101#endif 102#endif
102 103
103int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) 104int
105ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
104{ 106{
105 static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; 107 static const int min[9] = {0, 0, 1, 1, 0, 0, 0, 0, 0};
106 static const int max[9]={99, 99,12,31,23,59,59,12,59}; 108 static const int max[9] = {99, 99, 12, 31, 23, 59, 59, 12, 59};
107 char *a; 109 char *a;
108 int n,i,l,o; 110 int n, i, l, o;
109 111
110 if (d->type != V_ASN1_GENERALIZEDTIME) return(0); 112 if (d->type != V_ASN1_GENERALIZEDTIME)
111 l=d->length; 113 return (0);
112 a=(char *)d->data; 114 l = d->length;
113 o=0; 115 a = (char *)d->data;
116 o = 0;
114 /* GENERALIZEDTIME is similar to UTCTIME except the year is 117 /* GENERALIZEDTIME is similar to UTCTIME except the year is
115 * represented as YYYY. This stuff treats everything as a two digit 118 * represented as YYYY. This stuff treats everything as a two digit
116 * field so make first two fields 00 to 99 119 * field so make first two fields 00 to 99
117 */ 120 */
118 if (l < 13) goto err; 121 if (l < 13)
119 for (i=0; i<7; i++) { 122 goto err;
123 for (i = 0; i < 7; i++) {
120 if ((i == 6) && ((a[o] == 'Z') || 124 if ((i == 6) && ((a[o] == 'Z') ||
121 (a[o] == '+') || (a[o] == '-'))) 125 (a[o] == '+') || (a[o] == '-'))) {
122 { i++; break; } 126 i++;
123 if ((a[o] < '0') || (a[o] > '9')) goto err; 127 break;
128 }
129 if ((a[o] < '0') || (a[o] > '9'))
130 goto err;
124 n= a[o]-'0'; 131 n= a[o]-'0';
125 if (++o > l) goto err; 132 if (++o > l)
133 goto err;
126 134
127 if ((a[o] < '0') || (a[o] > '9')) goto err; 135 if ((a[o] < '0') || (a[o] > '9'))
128 n=(n*10)+ a[o]-'0'; 136 goto err;
129 if (++o > l) goto err; 137 n = (n * 10)+ a[o] - '0';
138 if (++o > l)
139 goto err;
130 140
131 if ((n < min[i]) || (n > max[i])) goto err; 141 if ((n < min[i]) || (n > max[i]))
142 goto err;
132 } 143 }
133 /* Optional fractional seconds: decimal point followed by one 144 /* Optional fractional seconds: decimal point followed by one
134 * or more digits. 145 * or more digits.
135 */ 146 */
136 if (a[o] == '.') 147 if (a[o] == '.') {
137 { 148 if (++o > l)
138 if (++o > l) goto err; 149 goto err;
139 i = o; 150 i = o;
140 while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) 151 while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
141 o++; 152 o++;
142 /* Must have at least one digit after decimal point */ 153 /* Must have at least one digit after decimal point */
143 if (i == o) goto err; 154 if (i == o)
155 goto err;
144 } 156 }
145 157
146 if (a[o] == 'Z') 158 if (a[o] == 'Z')
147 o++; 159 o++;
148 else if ((a[o] == '+') || (a[o] == '-')) { 160 else if ((a[o] == '+') || (a[o] == '-')) {
149 o++; 161 o++;
150 if (o+4 > l) goto err; 162 if (o + 4 > l)
151 for (i=7; i<9; i++) { 163 goto err;
152 if ((a[o] < '0') || (a[o] > '9')) goto err; 164 for (i = 7; i < 9; i++) {
153 n= a[o]-'0'; 165 if ((a[o] < '0') || (a[o] > '9'))
166 goto err;
167 n = a[o] - '0';
154 o++; 168 o++;
155 if ((a[o] < '0') || (a[o] > '9')) goto err; 169 if ((a[o] < '0') || (a[o] > '9'))
156 n=(n*10)+ a[o]-'0'; 170 goto err;
157 if ((n < min[i]) || (n > max[i])) goto err; 171 n = (n * 10) + a[o] - '0';
172 if ((n < min[i]) || (n > max[i]))
173 goto err;
158 o++; 174 o++;
159 } 175 }
160 } else { 176 } else {
161 /* Missing time zone information. */ 177 /* Missing time zone information. */
162 goto err; 178 goto err;
163 } 179 }
164 return(o == l); 180 return (o == l);
165err: 181err:
166 return(0); 182 return (0);
167} 183}
168 184
169int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) 185int
186ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
170{ 187{
171 ASN1_GENERALIZEDTIME t; 188 ASN1_GENERALIZEDTIME t;
172 189
173 t.type=V_ASN1_GENERALIZEDTIME; 190 t.type = V_ASN1_GENERALIZEDTIME;
174 t.length=strlen(str); 191 t.length = strlen(str);
175 t.data=(unsigned char *)str; 192 t.data = (unsigned char *)str;
176 if (ASN1_GENERALIZEDTIME_check(&t)) { 193 if (ASN1_GENERALIZEDTIME_check(&t)) {
177 if (s != NULL) { 194 if (s != NULL) {
178 if (!ASN1_STRING_set((ASN1_STRING *)s, 195 if (!ASN1_STRING_set((ASN1_STRING *)s,
179 (unsigned char *)str,t.length)) 196 (unsigned char *)str, t.length))
180 return 0; 197 return 0;
181 s->type=V_ASN1_GENERALIZEDTIME; 198 s->type = V_ASN1_GENERALIZEDTIME;
182 } 199 }
183 return(1); 200 return (1);
184 } 201 } else
185 else 202 return (0);
186 return(0);
187} 203}
188 204
189ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, 205ASN1_GENERALIZEDTIME *
190 time_t t) 206ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, time_t t)
191{ 207{
192 return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); 208 return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
193} 209}
194 210
195ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, 211ASN1_GENERALIZEDTIME *
196 time_t t, int offset_day, long offset_sec) 212ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day,
213 long offset_sec)
197{ 214{
198 char *p; 215 char *p;
199 struct tm *ts; 216 struct tm *ts;
200 struct tm data; 217 struct tm data;
201 size_t len = 20; 218 size_t len = 20;
202 219
203 if (s == NULL) 220 if (s == NULL)
204 s=M_ASN1_GENERALIZEDTIME_new(); 221 s = M_ASN1_GENERALIZEDTIME_new();
205 if (s == NULL) 222 if (s == NULL)
206 return(NULL); 223 return (NULL);
207 224
208 ts=OPENSSL_gmtime(&t, &data); 225 ts = OPENSSL_gmtime(&t, &data);
209 if (ts == NULL) 226 if (ts == NULL)
210 return(NULL); 227 return (NULL);
211 228
212 if (offset_day || offset_sec) { 229 if (offset_day || offset_sec) {
213 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) 230 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
214 return NULL; 231 return NULL;
215 } 232 }
216 233
217 p=(char *)s->data; 234 p = (char *)s->data;
218 if ((p == NULL) || ((size_t)s->length < len)) { 235 if ((p == NULL) || ((size_t)s->length < len)) {
219 p=malloc(len); 236 p = malloc(len);
220 if (p == NULL) { 237 if (p == NULL) {
221 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, 238 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
222 ERR_R_MALLOC_FAILURE); 239 ERR_R_MALLOC_FAILURE);
223 return(NULL); 240 return (NULL);
224 } 241 }
225 if (s->data != NULL) 242 if (s->data != NULL)
226 free(s->data); 243 free(s->data);
227 s->data=(unsigned char *)p; 244 s->data = (unsigned char *)p;
228 } 245 }
229 246
230 (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, 247 (void) snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
231 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 248 ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
232 s->length=strlen(p); 249 s->length = strlen(p);
233 s->type=V_ASN1_GENERALIZEDTIME; 250 s->type = V_ASN1_GENERALIZEDTIME;
234 return(s); 251 return (s);
235} 252}
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
index 93e6d8351b..082ba1b3a8 100644
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.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
@@ -64,92 +64,98 @@
64#ifndef NO_OLD_ASN1 64#ifndef NO_OLD_ASN1
65 65
66#ifndef OPENSSL_NO_FP_API 66#ifndef OPENSSL_NO_FP_API
67int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) 67int
68ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
68{ 69{
69 BIO *b; 70 BIO *b;
70 int ret; 71 int ret;
71 72
72 if ((b=BIO_new(BIO_s_file())) == NULL) { 73 if ((b = BIO_new(BIO_s_file())) == NULL) {
73 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); 74 ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB);
74 return(0); 75 return (0);
75 } 76 }
76 BIO_set_fp(b,out,BIO_NOCLOSE); 77 BIO_set_fp(b, out, BIO_NOCLOSE);
77 ret=ASN1_i2d_bio(i2d,b,x); 78 ret = ASN1_i2d_bio(i2d, b, x);
78 BIO_free(b); 79 BIO_free(b);
79 return(ret); 80 return (ret);
80} 81}
81#endif 82#endif
82 83
83int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) 84int
85ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
84{ 86{
85 char *b; 87 char *b;
86 unsigned char *p; 88 unsigned char *p;
87 int i,j=0,n,ret=1; 89 int i, j = 0, n, ret = 1;
88 90
89 n=i2d(x,NULL); 91 n = i2d(x, NULL);
90 b=(char *)malloc(n); 92 b = (char *)malloc(n);
91 if (b == NULL) { 93 if (b == NULL) {
92 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); 94 ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
93 return(0); 95 return (0);
94 } 96 }
95 97
96 p=(unsigned char *)b; 98 p = (unsigned char *)b;
97 i2d(x,&p); 99 i2d(x, &p);
98 100
99 for (;;) { 101 for (;;) {
100 i=BIO_write(out,&(b[j]),n); 102 i = BIO_write(out, &(b[j]), n);
101 if (i == n) break; 103 if (i == n)
104 break;
102 if (i <= 0) { 105 if (i <= 0) {
103 ret=0; 106 ret = 0;
104 break; 107 break;
105 } 108 }
106 j+=i; 109 j += i;
107 n-=i; 110 n -= i;
108 } 111 }
109 free(b); 112 free(b);
110 return(ret); 113 return (ret);
111} 114}
112 115
113#endif 116#endif
114 117
115#ifndef OPENSSL_NO_FP_API 118#ifndef OPENSSL_NO_FP_API
116int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) 119int
120ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
117{ 121{
118 BIO *b; 122 BIO *b;
119 int ret; 123 int ret;
120 124
121 if ((b=BIO_new(BIO_s_file())) == NULL) { 125 if ((b = BIO_new(BIO_s_file())) == NULL) {
122 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); 126 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
123 return(0); 127 return (0);
124 } 128 }
125 BIO_set_fp(b,out,BIO_NOCLOSE); 129 BIO_set_fp(b, out, BIO_NOCLOSE);
126 ret=ASN1_item_i2d_bio(it,b,x); 130 ret = ASN1_item_i2d_bio(it, b, x);
127 BIO_free(b); 131 BIO_free(b);
128 return(ret); 132 return (ret);
129} 133}
130#endif 134#endif
131 135
132int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) 136int
137ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
133{ 138{
134 unsigned char *b = NULL; 139 unsigned char *b = NULL;
135 int i,j=0,n,ret=1; 140 int i, j = 0, n, ret = 1;
136 141
137 n = ASN1_item_i2d(x, &b, it); 142 n = ASN1_item_i2d(x, &b, it);
138 if (b == NULL) { 143 if (b == NULL) {
139 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); 144 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE);
140 return(0); 145 return (0);
141 } 146 }
142 147
143 for (;;) { 148 for (;;) {
144 i=BIO_write(out,&(b[j]),n); 149 i = BIO_write(out, &(b[j]), n);
145 if (i == n) break; 150 if (i == n)
151 break;
146 if (i <= 0) { 152 if (i <= 0) {
147 ret=0; 153 ret = 0;
148 break; 154 break;
149 } 155 }
150 j+=i; 156 j += i;
151 n-=i; 157 n -= i;
152 } 158 }
153 free(b); 159 free(b);
154 return(ret); 160 return (ret);
155} 161}
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index cc2b985fa1..ef47eb106b 100644
--- a/src/lib/libcrypto/asn1/a_int.c
+++ b/src/lib/libcrypto/asn1/a_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,12 +61,17 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63 63
64ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) 64ASN1_INTEGER *
65{ return M_ASN1_INTEGER_dup(x);} 65ASN1_INTEGER_dup(const ASN1_INTEGER *x)
66{
67 return M_ASN1_INTEGER_dup(x);
68}
66 69
67int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) 70int
68{ 71ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
72{
69 int neg, ret; 73 int neg, ret;
74
70 /* Compare signs */ 75 /* Compare signs */
71 neg = x->type & V_ASN1_NEG; 76 neg = x->type & V_ASN1_NEG;
72 if (neg != (y->type & V_ASN1_NEG)) { 77 if (neg != (y->type & V_ASN1_NEG)) {
@@ -83,23 +88,23 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
83 else 88 else
84 return ret; 89 return ret;
85} 90}
86
87 91
88/* 92
93/*
89 * This converts an ASN1 INTEGER into its content encoding. 94 * This converts an ASN1 INTEGER into its content encoding.
90 * The internal representation is an ASN1_STRING whose data is a big endian 95 * The internal representation is an ASN1_STRING whose data is a big endian
91 * representation of the value, ignoring the sign. The sign is determined by 96 * representation of the value, ignoring the sign. The sign is determined by
92 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. 97 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
93 * 98 *
94 * Positive integers are no problem: they are almost the same as the DER 99 * Positive integers are no problem: they are almost the same as the DER
95 * encoding, except if the first byte is >= 0x80 we need to add a zero pad. 100 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
96 * 101 *
97 * Negative integers are a bit trickier... 102 * Negative integers are a bit trickier...
98 * The DER representation of negative integers is in 2s complement form. 103 * The DER representation of negative integers is in 2s complement form.
99 * The internal form is converted by complementing each octet and finally 104 * The internal form is converted by complementing each octet and finally
100 * adding one to the result. This can be done less messily with a little trick. 105 * adding one to the result. This can be done less messily with a little trick.
101 * If the internal form has trailing zeroes then they will become FF by the 106 * If the internal form has trailing zeroes then they will become FF by the
102 * complement and 0 by the add one (due to carry) so just copy as many trailing 107 * complement and 0 by the add one (due to carry) so just copy as many trailing
103 * zeros to the destination as there are in the source. The carry will add one 108 * zeros to the destination as there are in the source. The carry will add one
104 * to the last none zero octet: so complement this octet and add one and finally 109 * to the last none zero octet: so complement this octet and add one and finally
105 * complement any left over until you get to the start of the string. 110 * complement any left over until you get to the start of the string.
@@ -110,102 +115,109 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
110 * followed by optional zeros isn't padded. 115 * followed by optional zeros isn't padded.
111 */ 116 */
112 117
113int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) 118int
119i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
114{ 120{
115 int pad=0,ret,i,neg; 121 int pad = 0, ret, i, neg;
116 unsigned char *p,*n,pb=0; 122 unsigned char *p, *n, pb = 0;
117 123
118 if (a == NULL) return(0); 124 if (a == NULL)
119 neg=a->type & V_ASN1_NEG; 125 return (0);
126 neg = a->type & V_ASN1_NEG;
120 if (a->length == 0) 127 if (a->length == 0)
121 ret=1; 128 ret = 1;
122 else { 129 else {
123 ret=a->length; 130 ret = a->length;
124 i=a->data[0]; 131 i = a->data[0];
125 if (!neg && (i > 127)) { 132 if (!neg && (i > 127)) {
126 pad=1; 133 pad = 1;
127 pb=0; 134 pb = 0;
128 } else if(neg) { 135 } else if (neg) {
129 if(i>128) { 136 if (i > 128) {
130 pad=1; 137 pad = 1;
131 pb=0xFF; 138 pb = 0xFF;
132 } else if(i == 128) { 139 } else if (i == 128) {
133 /* 140 /*
134 * Special case: if any other bytes non zero we pad: 141 * Special case: if any other bytes non zero we pad:
135 * otherwise we don't. 142 * otherwise we don't.
136 */ 143 */
137 for(i = 1; i < a->length; i++) if(a->data[i]) { 144 for (i = 1; i < a->length; i++) if (a->data[i]) {
138 pad=1; 145 pad = 1;
139 pb=0xFF; 146 pb = 0xFF;
140 break; 147 break;
148 }
141 } 149 }
142 } 150 }
151 ret += pad;
143 } 152 }
144 ret+=pad; 153 if (pp == NULL)
145 } 154 return (ret);
146 if (pp == NULL) return(ret);
147 p= *pp; 155 p= *pp;
148 156
149 if (pad) *(p++)=pb; 157 if (pad)
150 if (a->length == 0) *(p++)=0; 158 *(p++) = pb;
151 else if (!neg) memcpy(p,a->data,(unsigned int)a->length); 159 if (a->length == 0)
160 *(p++) = 0;
161 else if (!neg)
162 memcpy(p, a->data, (unsigned int)a->length);
152 else { 163 else {
153 /* Begin at the end of the encoding */ 164 /* Begin at the end of the encoding */
154 n=a->data + a->length - 1; 165 n = a->data + a->length - 1;
155 p += a->length - 1; 166 p += a->length - 1;
156 i = a->length; 167 i = a->length;
157 /* Copy zeros to destination as long as source is zero */ 168 /* Copy zeros to destination as long as source is zero */
158 while(!*n) { 169 while (!*n) {
159 *(p--) = 0; 170 *(p--) = 0;
160 n--; 171 n--;
161 i--; 172 i--;
162 } 173 }
163 /* Complement and increment next octet */ 174 /* Complement and increment next octet */
164 *(p--) = ((*(n--)) ^ 0xff) + 1; 175 *(p--) = ((*(n--)) ^ 0xff) + 1;
165 i--; 176 i--;
166 /* Complement any octets left */ 177 /* Complement any octets left */
167 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; 178 for(; i > 0; i--)
168} 179 *(p--) = *(n--) ^ 0xff;
180 }
169 181
170 *pp+=ret; 182 *pp += ret;
171 return(ret); 183 return (ret);
172} 184}
173 185
174/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ 186/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
175 187
176ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, 188ASN1_INTEGER *
177 long len) 189c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
178{ 190{
179 ASN1_INTEGER *ret=NULL; 191 ASN1_INTEGER *ret = NULL;
180 const unsigned char *p, *pend; 192 const unsigned char *p, *pend;
181 unsigned char *to,*s; 193 unsigned char *to, *s;
182 int i; 194 int i;
183 195
184 if ((a == NULL) || ((*a) == NULL)) { 196 if ((a == NULL) || ((*a) == NULL)) {
185 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); 197 if ((ret = M_ASN1_INTEGER_new()) == NULL)
186 ret->type=V_ASN1_INTEGER; 198 return (NULL);
187 } 199 ret->type = V_ASN1_INTEGER;
188 else 200 } else
189 ret=(*a); 201 ret = (*a);
190 202
191 p= *pp; 203 p= *pp;
192 pend = p + len; 204 pend = p + len;
193 205
194 /* We must malloc stuff, even for 0 bytes otherwise it 206 /* We must malloc stuff, even for 0 bytes otherwise it
195 * signifies a missing NULL parameter. */ 207 * signifies a missing NULL parameter. */
196 s=(unsigned char *)malloc((int)len+1); 208 s = (unsigned char *)malloc((int)len + 1);
197 if (s == NULL) { 209 if (s == NULL) {
198 i=ERR_R_MALLOC_FAILURE; 210 i = ERR_R_MALLOC_FAILURE;
199 goto err; 211 goto err;
200 } 212 }
201 to=s; 213 to = s;
202 if(!len) { 214 if (!len) {
203 /* Strictly speaking this is an illegal INTEGER but we 215 /* Strictly speaking this is an illegal INTEGER but we
204 * tolerate it. 216 * tolerate it.
205 */ 217 */
206 ret->type=V_ASN1_INTEGER; 218 ret->type = V_ASN1_INTEGER;
207 } else if (*p & 0x80) /* a negative number */ { 219 } else if (*p & 0x80) /* a negative number */ {
208 ret->type=V_ASN1_NEG_INTEGER; 220 ret->type = V_ASN1_NEG_INTEGER;
209 if ((*p == 0xff) && (len != 1)) { 221 if ((*p == 0xff) && (len != 1)) {
210 p++; 222 p++;
211 len--; 223 len--;
@@ -225,35 +237,39 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
225 * a 1. This is treated separately because it is the only case 237 * a 1. This is treated separately because it is the only case
226 * where the number of bytes is larger than len. 238 * where the number of bytes is larger than len.
227 */ 239 */
228 if(!i) { 240 if (!i) {
229 *s = 1; 241 *s = 1;
230 s[len] = 0; 242 s[len] = 0;
231 len++; 243 len++;
232 } else { 244 } else {
233 *(to--) = (*(p--) ^ 0xff) + 1; 245 *(to--) = (*(p--) ^ 0xff) + 1;
234 i--; 246 i--;
235 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; 247 for(; i > 0; i--)
248 *(to--) = *(p--) ^ 0xff;
236 } 249 }
237 } else { 250 } else {
238 ret->type=V_ASN1_INTEGER; 251 ret->type = V_ASN1_INTEGER;
239 if ((*p == 0) && (len != 1)) { 252 if ((*p == 0) && (len != 1)) {
240 p++; 253 p++;
241 len--; 254 len--;
242 } 255 }
243 memcpy(s,p,(int)len); 256 memcpy(s, p, (int)len);
244 } 257 }
245 258
246 if (ret->data != NULL) free(ret->data); 259 if (ret->data != NULL)
247 ret->data=s; 260 free(ret->data);
248 ret->length=(int)len; 261 ret->data = s;
249 if (a != NULL) (*a)=ret; 262 ret->length = (int)len;
250 *pp=pend; 263 if (a != NULL)
251 return(ret); 264 (*a) = ret;
265 *pp = pend;
266 return (ret);
267
252err: 268err:
253 ASN1err(ASN1_F_C2I_ASN1_INTEGER,i); 269 ASN1err(ASN1_F_C2I_ASN1_INTEGER, i);
254 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 270 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
255 M_ASN1_INTEGER_free(ret); 271 M_ASN1_INTEGER_free(ret);
256 return(NULL); 272 return (NULL);
257} 273}
258 274
259 275
@@ -262,112 +278,120 @@ err:
262 * with its MSB set as negative (it doesn't add a padding zero). 278 * with its MSB set as negative (it doesn't add a padding zero).
263 */ 279 */
264 280
265ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, 281ASN1_INTEGER *
266 long length) 282d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
267{ 283{
268 ASN1_INTEGER *ret=NULL; 284 ASN1_INTEGER *ret = NULL;
269 const unsigned char *p; 285 const unsigned char *p;
270 unsigned char *s; 286 unsigned char *s;
271 long len; 287 long len;
272 int inf,tag,xclass; 288 int inf, tag, xclass;
273 int i; 289 int i;
274 290
275 if ((a == NULL) || ((*a) == NULL)) { 291 if ((a == NULL) || ((*a) == NULL)) {
276 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); 292 if ((ret = M_ASN1_INTEGER_new()) == NULL)
277 ret->type=V_ASN1_INTEGER; 293 return (NULL);
294 ret->type = V_ASN1_INTEGER;
278 } else 295 } else
279 ret=(*a); 296 ret = (*a);
280 297
281 p= *pp; 298 p = *pp;
282 inf=ASN1_get_object(&p,&len,&tag,&xclass,length); 299 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
283 if (inf & 0x80) { 300 if (inf & 0x80) {
284 i=ASN1_R_BAD_OBJECT_HEADER; 301 i = ASN1_R_BAD_OBJECT_HEADER;
285 goto err; 302 goto err;
286 } 303 }
287 304
288 if (tag != V_ASN1_INTEGER) { 305 if (tag != V_ASN1_INTEGER) {
289 i=ASN1_R_EXPECTING_AN_INTEGER; 306 i = ASN1_R_EXPECTING_AN_INTEGER;
290 goto err; 307 goto err;
291 } 308 }
292 309
293 /* We must malloc stuff, even for 0 bytes otherwise it 310 /* We must malloc stuff, even for 0 bytes otherwise it
294 * signifies a missing NULL parameter. */ 311 * signifies a missing NULL parameter. */
295 s=(unsigned char *)malloc((int)len+1); 312 s = (unsigned char *)malloc((int)len + 1);
296 if (s == NULL) { 313 if (s == NULL) {
297 i=ERR_R_MALLOC_FAILURE; 314 i = ERR_R_MALLOC_FAILURE;
298 goto err; 315 goto err;
299 } 316 }
300 ret->type=V_ASN1_INTEGER; 317 ret->type = V_ASN1_INTEGER;
301 if(len) { 318 if (len) {
302 if ((*p == 0) && (len != 1)) { 319 if ((*p == 0) && (len != 1)) {
303 p++; 320 p++;
304 len--; 321 len--;
305 } 322 }
306 memcpy(s,p,(int)len); 323 memcpy(s, p, (int)len);
307 p+=len; 324 p += len;
308 } 325 }
309 326
310 if (ret->data != NULL) free(ret->data); 327 if (ret->data != NULL)
311 ret->data=s; 328 free(ret->data);
312 ret->length=(int)len; 329 ret->data = s;
313 if (a != NULL) (*a)=ret; 330 ret->length = (int)len;
314 *pp=p; 331 if (a != NULL)
315 return(ret); 332 (*a) = ret;
333 *pp = p;
334 return (ret);
335
316err: 336err:
317 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); 337 ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i);
318 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 338 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
319 M_ASN1_INTEGER_free(ret); 339 M_ASN1_INTEGER_free(ret);
320 return(NULL); 340 return (NULL);
321} 341}
322 342
323int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) 343int
344ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
324{ 345{
325 int j,k; 346 int j, k;
326 unsigned int i; 347 unsigned int i;
327 unsigned char buf[sizeof(long)+1]; 348 unsigned char buf[sizeof(long) + 1];
328 long d; 349 long d;
329 350
330 a->type=V_ASN1_INTEGER; 351 a->type = V_ASN1_INTEGER;
331 if (a->length < (int)(sizeof(long)+1)) { 352 if (a->length < (int)(sizeof(long) + 1)) {
332 if (a->data != NULL) 353 if (a->data != NULL)
333 free(a->data); 354 free(a->data);
334 if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) 355 if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
335 memset((char *)a->data,0,sizeof(long)+1); 356 memset((char *)a->data, 0, sizeof(long) + 1);
336 } 357 }
337 if (a->data == NULL) { 358 if (a->data == NULL) {
338 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); 359 ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
339 return(0); 360 return (0);
340 } 361 }
341 d=v; 362 d = v;
342 if (d < 0) { 363 if (d < 0) {
343 d= -d; 364 d = -d;
344 a->type=V_ASN1_NEG_INTEGER; 365 a->type = V_ASN1_NEG_INTEGER;
345 } 366 }
346 367
347 for (i=0; i<sizeof(long); i++) { 368 for (i = 0; i < sizeof(long); i++) {
348 if (d == 0) break; 369 if (d == 0)
349 buf[i]=(int)d&0xff; 370 break;
350 d>>=8; 371 buf[i] = (int)d & 0xff;
372 d >>= 8;
351 } 373 }
352 j=0; 374 j = 0;
353 for (k=i-1; k >=0; k--) 375 for (k = i - 1; k >= 0; k--)
354 a->data[j++]=buf[k]; 376 a->data[j++] = buf[k];
355 a->length=j; 377 a->length = j;
356 return(1); 378 return (1);
357} 379}
358 380
359long ASN1_INTEGER_get(const ASN1_INTEGER *a) 381long
382ASN1_INTEGER_get(const ASN1_INTEGER *a)
360{ 383{
361 int neg=0,i; 384 int neg = 0, i;
362 long r=0; 385 long r = 0;
363 386
364 if (a == NULL) return(0L); 387 if (a == NULL)
365 i=a->type; 388 return (0L);
389 i = a->type;
366 if (i == V_ASN1_NEG_INTEGER) 390 if (i == V_ASN1_NEG_INTEGER)
367 neg=1; 391 neg = 1;
368 else if (i != V_ASN1_INTEGER) 392 else if (i != V_ASN1_INTEGER)
369 return -1; 393 return -1;
370 394
371 if (a->length > (int)sizeof(long)) { 395 if (a->length > (int)sizeof(long)) {
372 /* hmm... a bit ugly, return all ones */ 396 /* hmm... a bit ugly, return all ones */
373 return -1; 397 return -1;
@@ -375,61 +399,68 @@ long ASN1_INTEGER_get(const ASN1_INTEGER *a)
375 if (a->data == NULL) 399 if (a->data == NULL)
376 return 0; 400 return 0;
377 401
378 for (i=0; i<a->length; i++) { 402 for (i = 0; i < a->length; i++) {
379 r<<=8; 403 r <<= 8;
380 r|=(unsigned char)a->data[i]; 404 r |= (unsigned char)a->data[i];
381 } 405 }
382 if (neg) r= -r; 406 if (neg)
383 return(r); 407 r = -r;
408 return (r);
384} 409}
385 410
386ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) 411ASN1_INTEGER *
412BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
387{ 413{
388 ASN1_INTEGER *ret; 414 ASN1_INTEGER *ret;
389 int len,j; 415 int len, j;
390 416
391 if (ai == NULL) 417 if (ai == NULL)
392 ret=M_ASN1_INTEGER_new(); 418 ret = M_ASN1_INTEGER_new();
393 else 419 else
394 ret=ai; 420 ret = ai;
395 if (ret == NULL) { 421 if (ret == NULL) {
396 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); 422 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR);
397 goto err; 423 goto err;
398 } 424 }
399 if (BN_is_negative(bn)) 425 if (BN_is_negative(bn))
400 ret->type = V_ASN1_NEG_INTEGER; 426 ret->type = V_ASN1_NEG_INTEGER;
401 else ret->type=V_ASN1_INTEGER; 427 else
402 j=BN_num_bits(bn); 428 ret->type = V_ASN1_INTEGER;
403 len=((j == 0)?0:((j/8)+1)); 429 j = BN_num_bits(bn);
404 if (ret->length < len+4) { 430 len = ((j == 0) ? 0 : ((j / 8) + 1));
405 unsigned char *new_data=realloc(ret->data, len+4); 431 if (ret->length < len + 4) {
432 unsigned char *new_data = realloc(ret->data, len + 4);
406 if (!new_data) { 433 if (!new_data) {
407 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); 434 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
408 goto err; 435 goto err;
409 } 436 }
410 ret->data=new_data; 437 ret->data = new_data;
411 } 438 }
412 ret->length=BN_bn2bin(bn,ret->data); 439 ret->length = BN_bn2bin(bn, ret->data);
440
413 /* Correct zero case */ 441 /* Correct zero case */
414 if(!ret->length) { 442 if (!ret->length) {
415 ret->data[0] = 0; 443 ret->data[0] = 0;
416 ret->length = 1; 444 ret->length = 1;
417 } 445 }
418 return(ret); 446 return (ret);
447
419err: 448err:
420 if (ret != ai) M_ASN1_INTEGER_free(ret); 449 if (ret != ai)
421 return(NULL); 450 M_ASN1_INTEGER_free(ret);
451 return (NULL);
422} 452}
423 453
424BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) 454BIGNUM *
455ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
425{ 456{
426 BIGNUM *ret; 457 BIGNUM *ret;
427 458
428 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 459 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
429 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); 460 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN, ASN1_R_BN_LIB);
430 else if(ai->type == V_ASN1_NEG_INTEGER) 461 else if (ai->type == V_ASN1_NEG_INTEGER)
431 BN_set_negative(ret, 1); 462 BN_set_negative(ret, 1);
432 return(ret); 463 return (ret);
433} 464}
434 465
435IMPLEMENT_STACK_OF(ASN1_INTEGER) 466IMPLEMENT_STACK_OF(ASN1_INTEGER)
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
index f6d8da8b3c..5a909d6ae2 100644
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -62,7 +62,7 @@
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63 63
64static int traverse_string(const unsigned char *p, int len, int inform, 64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg); 65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg); 66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg); 67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg); 68static int type_str(unsigned long value, void *arg);
@@ -80,15 +80,17 @@ static int is_printable(unsigned long value);
80 * The 'ncopy' form checks minimum and maximum size limits too. 80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */ 81 */
82 82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, 83int
84 int inform, unsigned long mask) 84ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
85 int inform, unsigned long mask)
85{ 86{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0); 87 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87} 88}
88 89
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, 90int
90 int inform, unsigned long mask, 91ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
91 long minsize, long maxsize) 92 int inform, unsigned long mask,
93 long minsize, long maxsize)
92{ 94{
93 int str_type; 95 int str_type;
94 int ret; 96 int ret;
@@ -98,59 +100,62 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
98 unsigned char *p; 100 unsigned char *p;
99 int nchar; 101 int nchar;
100 char strbuf[32]; 102 char strbuf[32];
101 int (*cpyfunc)(unsigned long,void *) = NULL; 103 int (*cpyfunc)(unsigned long, void *) = NULL;
102 if(len == -1) len = strlen((const char *)in); 104
103 if(!mask) mask = DIRSTRING_TYPE; 105 if (len == -1)
106 len = strlen((const char *)in);
107 if (!mask)
108 mask = DIRSTRING_TYPE;
104 109
105 /* First do a string check and work out the number of characters */ 110 /* First do a string check and work out the number of characters */
106 switch(inform) { 111 switch (inform) {
107 112
108 case MBSTRING_BMP: 113 case MBSTRING_BMP:
109 if(len & 1) { 114 if (len & 1) {
110 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 115 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
111 ASN1_R_INVALID_BMPSTRING_LENGTH); 116 ASN1_R_INVALID_BMPSTRING_LENGTH);
112 return -1; 117 return -1;
113 } 118 }
114 nchar = len >> 1; 119 nchar = len >> 1;
115 break; 120 break;
116 121
117 case MBSTRING_UNIV: 122 case MBSTRING_UNIV:
118 if(len & 3) { 123 if (len & 3) {
119 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 124 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH); 125 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
121 return -1; 126 return -1;
122 } 127 }
123 nchar = len >> 2; 128 nchar = len >> 2;
124 break; 129 break;
125 130
126 case MBSTRING_UTF8: 131 case MBSTRING_UTF8:
127 nchar = 0; 132 nchar = 0;
128 /* This counts the characters and does utf8 syntax checking */ 133 /* This counts the characters and does utf8 syntax checking */
129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar); 134 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
130 if(ret < 0) { 135 if (ret < 0) {
131 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 136 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
132 ASN1_R_INVALID_UTF8STRING); 137 ASN1_R_INVALID_UTF8STRING);
133 return -1; 138 return -1;
134 } 139 }
135 break; 140 break;
136 141
137 case MBSTRING_ASC: 142 case MBSTRING_ASC:
138 nchar = len; 143 nchar = len;
139 break; 144 break;
140 145
141 default: 146 default:
142 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT); 147 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT);
143 return -1; 148 return -1;
144 } 149 }
145 150
146 if((minsize > 0) && (nchar < minsize)) { 151 if ((minsize > 0) && (nchar < minsize)) {
147 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT); 152 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT);
148 (void) snprintf(strbuf, sizeof strbuf, "%ld", minsize); 153 (void) snprintf(strbuf, sizeof strbuf, "%ld", minsize);
149 ERR_add_error_data(2, "minsize=", strbuf); 154 ERR_add_error_data(2, "minsize=", strbuf);
150 return -1; 155 return -1;
151 } 156 }
152 157
153 if((maxsize > 0) && (nchar > maxsize)) { 158 if ((maxsize > 0) && (nchar > maxsize)) {
154 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG); 159 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG);
155 (void) snprintf(strbuf, sizeof strbuf, "%ld", maxsize); 160 (void) snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
156 ERR_add_error_data(2, "maxsize=", strbuf); 161 ERR_add_error_data(2, "maxsize=", strbuf);
@@ -158,7 +163,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
158 } 163 }
159 164
160 /* Now work out minimal type (if any) */ 165 /* Now work out minimal type (if any) */
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) { 166 if (traverse_string(in, len, inform, type_str, &mask) < 0) {
162 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS); 167 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS);
163 return -1; 168 return -1;
164 } 169 }
@@ -166,24 +171,28 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
166 171
167 /* Now work out output format and string type */ 172 /* Now work out output format and string type */
168 outform = MBSTRING_ASC; 173 outform = MBSTRING_ASC;
169 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING; 174 if (mask & B_ASN1_PRINTABLESTRING)
170 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING; 175 str_type = V_ASN1_PRINTABLESTRING;
171 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING; 176 else if (mask & B_ASN1_IA5STRING)
172 else if(mask & B_ASN1_BMPSTRING) { 177 str_type = V_ASN1_IA5STRING;
178 else if (mask & B_ASN1_T61STRING)
179 str_type = V_ASN1_T61STRING;
180 else if (mask & B_ASN1_BMPSTRING) {
173 str_type = V_ASN1_BMPSTRING; 181 str_type = V_ASN1_BMPSTRING;
174 outform = MBSTRING_BMP; 182 outform = MBSTRING_BMP;
175 } else if(mask & B_ASN1_UNIVERSALSTRING) { 183 } else if (mask & B_ASN1_UNIVERSALSTRING) {
176 str_type = V_ASN1_UNIVERSALSTRING; 184 str_type = V_ASN1_UNIVERSALSTRING;
177 outform = MBSTRING_UNIV; 185 outform = MBSTRING_UNIV;
178 } else { 186 } else {
179 str_type = V_ASN1_UTF8STRING; 187 str_type = V_ASN1_UTF8STRING;
180 outform = MBSTRING_UTF8; 188 outform = MBSTRING_UTF8;
181 } 189 }
182 if(!out) return str_type; 190 if (!out)
183 if(*out) { 191 return str_type;
192 if (*out) {
184 free_out = 0; 193 free_out = 0;
185 dest = *out; 194 dest = *out;
186 if(dest->data) { 195 if (dest->data) {
187 dest->length = 0; 196 dest->length = 0;
188 free(dest->data); 197 free(dest->data);
189 dest->data = NULL; 198 dest->data = NULL;
@@ -192,75 +201,78 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
192 } else { 201 } else {
193 free_out = 1; 202 free_out = 1;
194 dest = ASN1_STRING_type_new(str_type); 203 dest = ASN1_STRING_type_new(str_type);
195 if(!dest) { 204 if (!dest) {
196 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 205 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
197 ERR_R_MALLOC_FAILURE); 206 ERR_R_MALLOC_FAILURE);
198 return -1; 207 return -1;
199 } 208 }
200 *out = dest; 209 *out = dest;
201 } 210 }
202 /* If both the same type just copy across */ 211 /* If both the same type just copy across */
203 if(inform == outform) { 212 if (inform == outform) {
204 if(!ASN1_STRING_set(dest, in, len)) { 213 if (!ASN1_STRING_set(dest, in, len)) {
205 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 214 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
215 ERR_R_MALLOC_FAILURE);
206 return -1; 216 return -1;
207 } 217 }
208 return str_type; 218 return str_type;
209 } 219 }
210 220
211 /* Work out how much space the destination will need */ 221 /* Work out how much space the destination will need */
212 switch(outform) { 222 switch (outform) {
213 case MBSTRING_ASC: 223 case MBSTRING_ASC:
214 outlen = nchar; 224 outlen = nchar;
215 cpyfunc = cpy_asc; 225 cpyfunc = cpy_asc;
216 break; 226 break;
217 227
218 case MBSTRING_BMP: 228 case MBSTRING_BMP:
219 outlen = nchar << 1; 229 outlen = nchar << 1;
220 cpyfunc = cpy_bmp; 230 cpyfunc = cpy_bmp;
221 break; 231 break;
222 232
223 case MBSTRING_UNIV: 233 case MBSTRING_UNIV:
224 outlen = nchar << 2; 234 outlen = nchar << 2;
225 cpyfunc = cpy_univ; 235 cpyfunc = cpy_univ;
226 break; 236 break;
227 237
228 case MBSTRING_UTF8: 238 case MBSTRING_UTF8:
229 outlen = 0; 239 outlen = 0;
230 traverse_string(in, len, inform, out_utf8, &outlen); 240 traverse_string(in, len, inform, out_utf8, &outlen);
231 cpyfunc = cpy_utf8; 241 cpyfunc = cpy_utf8;
232 break; 242 break;
233 } 243 }
234 if(!(p = malloc(outlen + 1))) { 244 if (!(p = malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest); 245 if (free_out)
236 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 246 ASN1_STRING_free(dest);
247 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE);
237 return -1; 248 return -1;
238 } 249 }
239 dest->length = outlen; 250 dest->length = outlen;
240 dest->data = p; 251 dest->data = p;
241 p[outlen] = 0; 252 p[outlen] = 0;
242 traverse_string(in, len, inform, cpyfunc, &p); 253 traverse_string(in, len, inform, cpyfunc, &p);
243 return str_type; 254 return str_type;
244} 255}
245 256
246/* This function traverses a string and passes the value of each character 257/* This function traverses a string and passes the value of each character
247 * to an optional function along with a void * argument. 258 * to an optional function along with a void * argument.
248 */ 259 */
249 260
250static int traverse_string(const unsigned char *p, int len, int inform, 261static int
251 int (*rfunc)(unsigned long value, void *in), void *arg) 262traverse_string(const unsigned char *p, int len, int inform,
263 int (*rfunc)(unsigned long value, void *in), void *arg)
252{ 264{
253 unsigned long value; 265 unsigned long value;
254 int ret; 266 int ret;
255 while(len) { 267 while (len) {
256 if(inform == MBSTRING_ASC) { 268 if (inform == MBSTRING_ASC) {
257 value = *p++; 269 value = *p++;
258 len--; 270 len--;
259 } else if(inform == MBSTRING_BMP) { 271 } else if (inform == MBSTRING_BMP) {
260 value = *p++ << 8; 272 value = *p++ << 8;
261 value |= *p++; 273 value |= *p++;
262 len -= 2; 274 len -= 2;
263 } else if(inform == MBSTRING_UNIV) { 275 } else if (inform == MBSTRING_UNIV) {
264 value = ((unsigned long)*p++) << 24; 276 value = ((unsigned long)*p++) << 24;
265 value |= ((unsigned long)*p++) << 16; 277 value |= ((unsigned long)*p++) << 16;
266 value |= *p++ << 8; 278 value |= *p++ << 8;
@@ -268,13 +280,14 @@ static int traverse_string(const unsigned char *p, int len, int inform,
268 len -= 4; 280 len -= 4;
269 } else { 281 } else {
270 ret = UTF8_getc(p, len, &value); 282 ret = UTF8_getc(p, len, &value);
271 if(ret < 0) return -1; 283 if (ret < 0) return -1;
272 len -= ret; 284 len -= ret;
273 p += ret; 285 p += ret;
274 } 286 }
275 if(rfunc) { 287 if (rfunc) {
276 ret = rfunc(value, arg); 288 ret = rfunc(value, arg);
277 if(ret <= 0) return ret; 289 if (ret <= 0)
290 return ret;
278 } 291 }
279 } 292 }
280 return 1; 293 return 1;
@@ -284,7 +297,8 @@ static int traverse_string(const unsigned char *p, int len, int inform,
284 297
285/* Just count number of characters */ 298/* Just count number of characters */
286 299
287static int in_utf8(unsigned long value, void *arg) 300static int
301in_utf8(unsigned long value, void *arg)
288{ 302{
289 int *nchar; 303 int *nchar;
290 nchar = arg; 304 nchar = arg;
@@ -294,7 +308,8 @@ static int in_utf8(unsigned long value, void *arg)
294 308
295/* Determine size of output as a UTF8 String */ 309/* Determine size of output as a UTF8 String */
296 310
297static int out_utf8(unsigned long value, void *arg) 311static int
312out_utf8(unsigned long value, void *arg)
298{ 313{
299 int *outlen; 314 int *outlen;
300 outlen = arg; 315 outlen = arg;
@@ -306,28 +321,33 @@ static int out_utf8(unsigned long value, void *arg)
306 * supplied "mask". 321 * supplied "mask".
307 */ 322 */
308 323
309static int type_str(unsigned long value, void *arg) 324static int
325type_str(unsigned long value, void *arg)
310{ 326{
311 unsigned long types; 327 unsigned long types;
328
312 types = *((unsigned long *)arg); 329 types = *((unsigned long *)arg);
313 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) 330 if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
314 types &= ~B_ASN1_PRINTABLESTRING; 331 types &= ~B_ASN1_PRINTABLESTRING;
315 if((types & B_ASN1_IA5STRING) && (value > 127)) 332 if ((types & B_ASN1_IA5STRING) && (value > 127))
316 types &= ~B_ASN1_IA5STRING; 333 types &= ~B_ASN1_IA5STRING;
317 if((types & B_ASN1_T61STRING) && (value > 0xff)) 334 if ((types & B_ASN1_T61STRING) && (value > 0xff))
318 types &= ~B_ASN1_T61STRING; 335 types &= ~B_ASN1_T61STRING;
319 if((types & B_ASN1_BMPSTRING) && (value > 0xffff)) 336 if ((types & B_ASN1_BMPSTRING) && (value > 0xffff))
320 types &= ~B_ASN1_BMPSTRING; 337 types &= ~B_ASN1_BMPSTRING;
321 if(!types) return -1; 338 if (!types)
339 return -1;
322 *((unsigned long *)arg) = types; 340 *((unsigned long *)arg) = types;
323 return 1; 341 return 1;
324} 342}
325 343
326/* Copy one byte per character ASCII like strings */ 344/* Copy one byte per character ASCII like strings */
327 345
328static int cpy_asc(unsigned long value, void *arg) 346static int
347cpy_asc(unsigned long value, void *arg)
329{ 348{
330 unsigned char **p, *q; 349 unsigned char **p, *q;
350
331 p = arg; 351 p = arg;
332 q = *p; 352 q = *p;
333 *q = (unsigned char) value; 353 *q = (unsigned char) value;
@@ -337,9 +357,11 @@ static int cpy_asc(unsigned long value, void *arg)
337 357
338/* Copy two byte per character BMPStrings */ 358/* Copy two byte per character BMPStrings */
339 359
340static int cpy_bmp(unsigned long value, void *arg) 360static int
361cpy_bmp(unsigned long value, void *arg)
341{ 362{
342 unsigned char **p, *q; 363 unsigned char **p, *q;
364
343 p = arg; 365 p = arg;
344 q = *p; 366 q = *p;
345 *q++ = (unsigned char) ((value >> 8) & 0xff); 367 *q++ = (unsigned char) ((value >> 8) & 0xff);
@@ -350,9 +372,11 @@ static int cpy_bmp(unsigned long value, void *arg)
350 372
351/* Copy four byte per character UniversalStrings */ 373/* Copy four byte per character UniversalStrings */
352 374
353static int cpy_univ(unsigned long value, void *arg) 375static int
376cpy_univ(unsigned long value, void *arg)
354{ 377{
355 unsigned char **p, *q; 378 unsigned char **p, *q;
379
356 p = arg; 380 p = arg;
357 q = *p; 381 q = *p;
358 *q++ = (unsigned char) ((value >> 24) & 0xff); 382 *q++ = (unsigned char) ((value >> 24) & 0xff);
@@ -365,9 +389,11 @@ static int cpy_univ(unsigned long value, void *arg)
365 389
366/* Copy to a UTF8String */ 390/* Copy to a UTF8String */
367 391
368static int cpy_utf8(unsigned long value, void *arg) 392static int
393cpy_utf8(unsigned long value, void *arg)
369{ 394{
370 unsigned char **p; 395 unsigned char **p;
396
371 int ret; 397 int ret;
372 p = arg; 398 p = arg;
373 /* We already know there is enough room so pass 0xff as the length */ 399 /* We already know there is enough room so pass 0xff as the length */
@@ -377,17 +403,23 @@ static int cpy_utf8(unsigned long value, void *arg)
377} 403}
378 404
379/* Return 1 if the character is permitted in a PrintableString */ 405/* Return 1 if the character is permitted in a PrintableString */
380static int is_printable(unsigned long value) 406static int
407is_printable(unsigned long value)
381{ 408{
382 int ch; 409 int ch;
383 if(value > 0x7f) return 0; 410
384 ch = (int) value; 411 if (value > 0x7f) return 0;
385 /* Note: we can't use 'isalnum' because certain accented 412 ch = (int)value;
413 /* Note: we can't use 'isalnum' because certain accented
386 * characters may count as alphanumeric in some environments. 414 * characters may count as alphanumeric in some environments.
387 */ 415 */
388 if((ch >= 'a') && (ch <= 'z')) return 1; 416 if ((ch >= 'a') && (ch <= 'z'))
389 if((ch >= 'A') && (ch <= 'Z')) return 1; 417 return 1;
390 if((ch >= '0') && (ch <= '9')) return 1; 418 if ((ch >= 'A') && (ch <= 'Z'))
391 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; 419 return 1;
420 if ((ch >= '0') && (ch <= '9'))
421 return 1;
422 if ((ch == ' ') || strchr("'()+,-./:=?", ch))
423 return 1;
392 return 0; 424 return 0;
393} 425}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index e73b1223de..293b269c21 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.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
@@ -64,28 +64,32 @@
64#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include <openssl/bn.h> 65#include <openssl/bn.h>
66 66
67int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) 67int
68i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
68{ 69{
69 unsigned char *p; 70 unsigned char *p;
70 int objsize; 71 int objsize;
71 72
72 if ((a == NULL) || (a->data == NULL)) return(0); 73 if ((a == NULL) || (a->data == NULL))
74 return (0);
73 75
74 objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); 76 objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
75 if (pp == NULL) return objsize; 77 if (pp == NULL)
78 return objsize;
76 79
77 p= *pp; 80 p = *pp;
78 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); 81 ASN1_put_object(&p, 0,a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
79 memcpy(p,a->data,a->length); 82 memcpy(p, a->data, a->length);
80 p+=a->length; 83 p += a->length;
81 84
82 *pp=p; 85 *pp = p;
83 return(objsize); 86 return (objsize);
84} 87}
85 88
86int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) 89int
90a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
87{ 91{
88 int i,first,len=0,c, use_bn; 92 int i, first, len = 0, c, use_bn;
89 char ftmp[24], *tmp = ftmp; 93 char ftmp[24], *tmp = ftmp;
90 int tmpsize = sizeof ftmp; 94 int tmpsize = sizeof ftmp;
91 const char *p; 95 const char *p;
@@ -93,42 +97,46 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
93 BIGNUM *bl = NULL; 97 BIGNUM *bl = NULL;
94 98
95 if (num == 0) 99 if (num == 0)
96 return(0); 100 return (0);
97 else if (num == -1) 101 else if (num == -1)
98 num=strlen(buf); 102 num = strlen(buf);
99 103
100 p=buf; 104 p = buf;
101 c= *(p++); 105 c = *(p++);
102 num--; 106 num--;
103 if ((c >= '0') && (c <= '2')) { 107 if ((c >= '0') && (c <= '2')) {
104 first= c-'0'; 108 first= c-'0';
105 } else { 109 } else {
106 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); 110 ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE);
107 goto err; 111 goto err;
108 } 112 }
109 113
110 if (num <= 0) { 114 if (num <= 0) {
111 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); 115 ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER);
112 goto err; 116 goto err;
113 } 117 }
114 c= *(p++); 118 c = *(p++);
115 num--; 119 num--;
116 for (;;) { 120 for (;;) {
117 if (num <= 0) break; 121 if (num <= 0)
122 break;
118 if ((c != '.') && (c != ' ')) { 123 if ((c != '.') && (c != ' ')) {
119 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); 124 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
125 ASN1_R_INVALID_SEPARATOR);
120 goto err; 126 goto err;
121 } 127 }
122 l=0; 128 l = 0;
123 use_bn = 0; 129 use_bn = 0;
124 for (;;) { 130 for (;;) {
125 if (num <= 0) break; 131 if (num <= 0)
132 break;
126 num--; 133 num--;
127 c= *(p++); 134 c = *(p++);
128 if ((c == ' ') || (c == '.')) 135 if ((c == ' ') || (c == '.'))
129 break; 136 break;
130 if ((c < '0') || (c > '9')) { 137 if ((c < '0') || (c > '9')) {
131 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); 138 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
139 ASN1_R_INVALID_DIGIT);
132 goto err; 140 goto err;
133 } 141 }
134 if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { 142 if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
@@ -139,30 +147,29 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
139 goto err; 147 goto err;
140 } 148 }
141 if (use_bn) { 149 if (use_bn) {
142 if (!BN_mul_word(bl, 10L) 150 if (!BN_mul_word(bl, 10L) ||
143 || !BN_add_word(bl, c-'0')) 151 !BN_add_word(bl, c-'0'))
144 goto err; 152 goto err;
145 } 153 } else
146 else 154 l = l * 10L + (long)(c - '0');
147 l=l*10L+(long)(c-'0');
148 } 155 }
149 if (len == 0) { 156 if (len == 0) {
150 if ((first < 2) && (l >= 40)) { 157 if ((first < 2) && (l >= 40)) {
151 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); 158 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
159 ASN1_R_SECOND_NUMBER_TOO_LARGE);
152 goto err; 160 goto err;
153 } 161 }
154 if (use_bn) { 162 if (use_bn) {
155 if (!BN_add_word(bl, first * 40)) 163 if (!BN_add_word(bl, first * 40))
156 goto err; 164 goto err;
157 } 165 } else
158 else 166 l += (long)first * 40;
159 l+=(long)first*40;
160 } 167 }
161 i=0; 168 i = 0;
162 if (use_bn) { 169 if (use_bn) {
163 int blsize; 170 int blsize;
164 blsize = BN_num_bits(bl); 171 blsize = BN_num_bits(bl);
165 blsize = (blsize + 6)/7; 172 blsize = (blsize + 6) / 7;
166 if (blsize > tmpsize) { 173 if (blsize > tmpsize) {
167 if (tmp != ftmp) 174 if (tmp != ftmp)
168 free(tmp); 175 free(tmp);
@@ -171,108 +178,118 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
171 if (!tmp) 178 if (!tmp)
172 goto err; 179 goto err;
173 } 180 }
174 while(blsize--) 181 while (blsize--)
175 tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); 182 tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
176 } else { 183 } else {
177 184
178 for (;;) { 185 for (;;) {
179 tmp[i++]=(unsigned char)l&0x7f; 186 tmp[i++] = (unsigned char)l & 0x7f;
180 l>>=7L; 187 l >>= 7L;
181 if (l == 0L) break; 188 if (l == 0L)
189 break;
182 } 190 }
183 191
184 } 192 }
185 if (out != NULL) { 193 if (out != NULL) {
186 if (len+i > olen) { 194 if (len + i > olen) {
187 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); 195 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
196 ASN1_R_BUFFER_TOO_SMALL);
188 goto err; 197 goto err;
189 } 198 }
190 while (--i > 0) 199 while (--i > 0)
191 out[len++]=tmp[i]|0x80; 200 out[len++] = tmp[i]|0x80;
192 out[len++]=tmp[0]; 201 out[len++] = tmp[0];
193 } 202 } else
194 else 203 len += i;
195 len+=i;
196 } 204 }
197 if (tmp != ftmp) 205 if (tmp != ftmp)
198 free(tmp); 206 free(tmp);
199 if (bl) 207 if (bl)
200 BN_free(bl); 208 BN_free(bl);
201 return(len); 209 return (len);
210
202err: 211err:
203 if (tmp != ftmp) 212 if (tmp != ftmp)
204 free(tmp); 213 free(tmp);
205 if (bl) 214 if (bl)
206 BN_free(bl); 215 BN_free(bl);
207 return(0); 216 return (0);
208} 217}
209 218
210int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) 219int
220i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
211{ 221{
212 return OBJ_obj2txt(buf, buf_len, a, 0); 222 return OBJ_obj2txt(buf, buf_len, a, 0);
213} 223}
214 224
215int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) 225int
226i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
216{ 227{
217 char buf[80], *p = buf; 228 char buf[80], *p = buf;
218 int i; 229 int i;
219 230
220 if ((a == NULL) || (a->data == NULL)) 231 if ((a == NULL) || (a->data == NULL))
221 return(BIO_write(bp,"NULL",4)); 232 return(BIO_write(bp, "NULL",4));
222 i=i2t_ASN1_OBJECT(buf,sizeof buf,a); 233 i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
223 if (i > (int)(sizeof(buf) - 1)) { 234 if (i > (int)(sizeof(buf) - 1)) {
224 p = malloc(i + 1); 235 p = malloc(i + 1);
225 if (!p) 236 if (!p)
226 return -1; 237 return -1;
227 i2t_ASN1_OBJECT(p,i + 1,a); 238 i2t_ASN1_OBJECT(p, i + 1, a);
228 } 239 }
229 if (i <= 0) 240 if (i <= 0)
230 return BIO_write(bp, "<INVALID>", 9); 241 return BIO_write(bp, "<INVALID>", 9);
231 BIO_write(bp,p,i); 242 BIO_write(bp, p, i);
232 if (p != buf) 243 if (p != buf)
233 free(p); 244 free(p);
234 return(i); 245 return (i);
235} 246}
236 247
237ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, 248ASN1_OBJECT *
238 long length) 249d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length)
239{ 250{
240 const unsigned char *p; 251 const unsigned char *p;
241 long len; 252 long len;
242 int tag,xclass; 253 int tag, xclass;
243 int inf,i; 254 int inf, i;
244 ASN1_OBJECT *ret = NULL; 255 ASN1_OBJECT *ret = NULL;
245 p= *pp; 256
246 inf=ASN1_get_object(&p,&len,&tag,&xclass,length); 257 p = *pp;
258 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
247 if (inf & 0x80) { 259 if (inf & 0x80) {
248 i=ASN1_R_BAD_OBJECT_HEADER; 260 i = ASN1_R_BAD_OBJECT_HEADER;
249 goto err; 261 goto err;
250 } 262 }
251 263
252 if (tag != V_ASN1_OBJECT) { 264 if (tag != V_ASN1_OBJECT) {
253 i=ASN1_R_EXPECTING_AN_OBJECT; 265 i = ASN1_R_EXPECTING_AN_OBJECT;
254 goto err; 266 goto err;
255 } 267 }
256 ret = c2i_ASN1_OBJECT(a, &p, len); 268 ret = c2i_ASN1_OBJECT(a, &p, len);
257 if(ret) *pp = p; 269 if (ret)
270 *pp = p;
258 return ret; 271 return ret;
272
259err: 273err:
260 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); 274 ASN1err(ASN1_F_D2I_ASN1_OBJECT, i);
261 return(NULL); 275 return (NULL);
262} 276}
263ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, 277
264 long len) 278ASN1_OBJECT *
279c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
265{ 280{
266 ASN1_OBJECT *ret=NULL; 281 ASN1_OBJECT *ret = NULL;
267 const unsigned char *p; 282 const unsigned char *p;
268 unsigned char *data; 283 unsigned char *data;
269 int i; 284 int i;
285
270 /* Sanity check OID encoding: can't have leading 0x80 in 286 /* Sanity check OID encoding: can't have leading 0x80 in
271 * subidentifiers, see: X.690 8.19.2 287 * subidentifiers, see: X.690 8.19.2
272 */ 288 */
273 for (i = 0, p = *pp; i < len; i++, p++) { 289 for (i = 0, p = *pp; i < len; i++, p++) {
274 if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { 290 if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
275 ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); 291 ASN1err(ASN1_F_C2I_ASN1_OBJECT,
292 ASN1_R_INVALID_OBJECT_ENCODING);
276 return NULL; 293 return NULL;
277 } 294 }
278 } 295 }
@@ -280,92 +297,106 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
280 /* only the ASN1_OBJECTs from the 'table' will have values 297 /* only the ASN1_OBJECTs from the 'table' will have values
281 * for ->sn or ->ln */ 298 * for ->sn or ->ln */
282 if ((a == NULL) || ((*a) == NULL) || 299 if ((a == NULL) || ((*a) == NULL) ||
283 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { 300 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
284 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); 301 if ((ret = ASN1_OBJECT_new()) == NULL)
285 } 302 return (NULL);
286 else ret=(*a); 303 } else
304 ret = (*a);
287 305
288 p= *pp; 306 p = *pp;
289 /* detach data from object */ 307 /* detach data from object */
290 data = (unsigned char *)ret->data; 308 data = (unsigned char *)ret->data;
291 ret->data = NULL; 309 ret->data = NULL;
292 /* once detached we can change it */ 310 /* once detached we can change it */
293 if ((data == NULL) || (ret->length < len)) { 311 if ((data == NULL) || (ret->length < len)) {
294 ret->length=0; 312 ret->length = 0;
295 if (data != NULL) free(data); 313 if (data != NULL)
296 data=(unsigned char *)malloc(len ? (int)len : 1); 314 free(data);
297 if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } 315 data = (unsigned char *)malloc(len ? (int)len : 1);
298 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; 316 if (data == NULL) {
317 i = ERR_R_MALLOC_FAILURE;
318 goto err;
319 }
320 ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
299 } 321 }
300 memcpy(data,p,(int)len); 322 memcpy(data, p, (int)len);
301 /* reattach data to object, after which it remains const */ 323 /* reattach data to object, after which it remains const */
302 ret->data =data; 324 ret->data = data;
303 ret->length=(int)len; 325 ret->length = (int)len;
304 ret->sn=NULL; 326 ret->sn = NULL;
305 ret->ln=NULL; 327 ret->ln = NULL;
306 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ 328 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
307 p+=len; 329 p += len;
330
331 if (a != NULL)
332 (*a) = ret;
333 *pp = p;
334 return (ret);
308 335
309 if (a != NULL) (*a)=ret;
310 *pp=p;
311 return(ret);
312err: 336err:
313 ASN1err(ASN1_F_C2I_ASN1_OBJECT,i); 337 ASN1err(ASN1_F_C2I_ASN1_OBJECT, i);
314 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 338 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
315 ASN1_OBJECT_free(ret); 339 ASN1_OBJECT_free(ret);
316 return(NULL); 340 return (NULL);
317} 341}
318 342
319ASN1_OBJECT *ASN1_OBJECT_new(void) 343ASN1_OBJECT *
344ASN1_OBJECT_new(void)
320{ 345{
321 ASN1_OBJECT *ret; 346 ASN1_OBJECT *ret;
322 347
323 ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); 348 ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
324 if (ret == NULL) { 349 if (ret == NULL) {
325 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); 350 ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
326 return(NULL); 351 return (NULL);
327 } 352 }
328 ret->length=0; 353 ret->length = 0;
329 ret->data=NULL; 354 ret->data = NULL;
330 ret->nid=0; 355 ret->nid = 0;
331 ret->sn=NULL; 356 ret->sn = NULL;
332 ret->ln=NULL; 357 ret->ln = NULL;
333 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; 358 ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
334 return(ret); 359 return (ret);
335} 360}
336 361
337void ASN1_OBJECT_free(ASN1_OBJECT *a) 362void
363ASN1_OBJECT_free(ASN1_OBJECT *a)
338{ 364{
339 if (a == NULL) return; 365 if (a == NULL)
366 return;
340 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) { 367 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
341#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ 368#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
342 if (a->sn != NULL) free((void *)a->sn); 369 if (a->sn != NULL)
343 if (a->ln != NULL) free((void *)a->ln); 370 free((void *)a->sn);
371 if (a->ln != NULL)
372 free((void *)a->ln);
344#endif 373#endif
345 a->sn=a->ln=NULL; 374 a->sn = a->ln = NULL;
346 } 375 }
347 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { 376 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
348 if (a->data != NULL) free((void *)a->data); 377 if (a->data != NULL)
349 a->data=NULL; 378 free((void *)a->data);
350 a->length=0; 379 a->data = NULL;
380 a->length = 0;
351 } 381 }
352 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) 382 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
353 free(a); 383 free(a);
354} 384}
355 385
356ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, 386ASN1_OBJECT *
357 const char *sn, const char *ln) 387ASN1_OBJECT_create(int nid, unsigned char *data, int len,
388 const char *sn, const char *ln)
358{ 389{
359 ASN1_OBJECT o; 390 ASN1_OBJECT o;
360 391
361 o.sn=sn; 392 o.sn = sn;
362 o.ln=ln; 393 o.ln = ln;
363 o.data=data; 394 o.data = data;
364 o.nid=nid; 395 o.nid = nid;
365 o.length=len; 396 o.length = len;
366 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 397 o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
367 ASN1_OBJECT_FLAG_DYNAMIC_DATA; 398 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
368 return(OBJ_dup(&o)); 399 return (OBJ_dup(&o));
369} 400}
370 401
371IMPLEMENT_STACK_OF(ASN1_OBJECT) 402IMPLEMENT_STACK_OF(ASN1_OBJECT)
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
index e8725e44f1..74f849cf12 100644
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ b/src/lib/libcrypto/asn1/a_octet.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
@@ -60,12 +60,20 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) 63ASN1_OCTET_STRING *
64{ return M_ASN1_OCTET_STRING_dup(x); } 64ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
65 65{
66int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b) 66 return M_ASN1_OCTET_STRING_dup(x);
67{ return M_ASN1_OCTET_STRING_cmp(a, b); } 67}
68 68
69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len) 69int
70{ return M_ASN1_OCTET_STRING_set(x, d, len); } 70ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
71{
72 return M_ASN1_OCTET_STRING_cmp(a, b);
73}
71 74
75int
76ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
77{
78 return M_ASN1_OCTET_STRING_set(x, d, len);
79}
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
index 9e421dba66..3e9a7c0f40 100644
--- a/src/lib/libcrypto/asn1/a_print.c
+++ b/src/lib/libcrypto/asn1/a_print.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
@@ -60,57 +60,66 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63int ASN1_PRINTABLE_type(const unsigned char *s, int len) 63int
64ASN1_PRINTABLE_type(const unsigned char *s, int len)
64{ 65{
65 int c; 66 int c;
66 int ia5=0; 67 int ia5 = 0;
67 int t61=0; 68 int t61 = 0;
68 69
69 if (len <= 0) len= -1; 70 if (len <= 0)
70 if (s == NULL) return(V_ASN1_PRINTABLESTRING); 71 len = -1;
72 if (s == NULL)
73 return (V_ASN1_PRINTABLESTRING);
71 74
72 while ((*s) && (len-- != 0)) { 75 while ((*s) && (len-- != 0)) {
73 c= *(s++); 76 c= *(s++);
74 if (!( ((c >= 'a') && (c <= 'z')) || 77 if (!(((c >= 'a') && (c <= 'z')) ||
75 ((c >= 'A') && (c <= 'Z')) || 78 ((c >= 'A') && (c <= 'Z')) ||
76 (c == ' ') || 79 (c == ' ') ||
77 ((c >= '0') && (c <= '9')) || 80 ((c >= '0') && (c <= '9')) ||
78 (c == ' ') || (c == '\'') || 81 (c == ' ') || (c == '\'') ||
79 (c == '(') || (c == ')') || 82 (c == '(') || (c == ')') ||
80 (c == '+') || (c == ',') || 83 (c == '+') || (c == ',') ||
81 (c == '-') || (c == '.') || 84 (c == '-') || (c == '.') ||
82 (c == '/') || (c == ':') || 85 (c == '/') || (c == ':') ||
83 (c == '=') || (c == '?'))) 86 (c == '=') || (c == '?')))
84 ia5=1; 87 ia5 = 1;
85 if (c&0x80) 88 if (c & 0x80)
86 t61=1; 89 t61 = 1;
87 } 90 }
88 if (t61) return(V_ASN1_T61STRING); 91 if (t61)
89 if (ia5) return(V_ASN1_IA5STRING); 92 return (V_ASN1_T61STRING);
90 return(V_ASN1_PRINTABLESTRING); 93 if (ia5)
94 return (V_ASN1_IA5STRING);
95 return (V_ASN1_PRINTABLESTRING);
91} 96}
92 97
93int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) 98int
99ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
94{ 100{
95 int i; 101 int i;
96 unsigned char *p; 102 unsigned char *p;
97 103
98 if (s->type != V_ASN1_UNIVERSALSTRING) return(0); 104 if (s->type != V_ASN1_UNIVERSALSTRING)
99 if ((s->length%4) != 0) return(0); 105 return (0);
100 p=s->data; 106 if ((s->length % 4) != 0)
101 for (i=0; i<s->length; i+=4) { 107 return (0);
108 p = s->data;
109 for (i = 0; i < s->length; i += 4) {
102 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) 110 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
103 break; 111 break;
104 else 112 else
105 p+=4; 113 p += 4;
106 } 114 }
107 if (i < s->length) return(0); 115 if (i < s->length)
108 p=s->data; 116 return (0);
109 for (i=3; i<s->length; i+=4) { 117 p = s->data;
110 *(p++)=s->data[i]; 118 for (i = 3; i < s->length; i += 4) {
119 *(p++) = s->data[i];
111 } 120 }
112 *(p)='\0'; 121 *(p) = '\0';
113 s->length/=4; 122 s->length /= 4;
114 s->type=ASN1_PRINTABLE_type(s->data,s->length); 123 s->type = ASN1_PRINTABLE_type(s->data, s->length);
115 return(1); 124 return (1);
116} 125}
diff --git a/src/lib/libssl/src/crypto/asn1/a_bitstr.c b/src/lib/libssl/src/crypto/asn1/a_bitstr.c
index 5633cfca1c..c578ce6279 100644
--- a/src/lib/libssl/src/crypto/asn1/a_bitstr.c
+++ b/src/lib/libssl/src/crypto/asn1/a_bitstr.c
@@ -69,7 +69,7 @@ ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
69int 69int
70i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) 70i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
71{ 71{
72 int ret, j,bits, len; 72 int ret, j, bits, len;
73 unsigned char *p, *d; 73 unsigned char *p, *d;
74 74
75 if (a == NULL) 75 if (a == NULL)
@@ -198,7 +198,7 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
198 if (a == NULL) 198 if (a == NULL)
199 return 0; 199 return 0;
200 200
201 a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ 201 a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear, set on write */
202 202
203 if ((a->length < (w + 1)) || (a->data == NULL)) { 203 if ((a->length < (w + 1)) || (a->data == NULL)) {
204 if (!value) 204 if (!value)
diff --git a/src/lib/libssl/src/crypto/asn1/a_digest.c b/src/lib/libssl/src/crypto/asn1/a_digest.c
index e87d4396df..76a62f7c00 100644
--- a/src/lib/libssl/src/crypto/asn1/a_digest.c
+++ b/src/lib/libssl/src/crypto/asn1/a_digest.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
@@ -70,17 +70,19 @@
70#include <openssl/buffer.h> 70#include <openssl/buffer.h>
71#include <openssl/x509.h> 71#include <openssl/x509.h>
72 72
73int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, 73int
74 unsigned char *md, unsigned int *len) 74ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
75 unsigned char *md, unsigned int *len)
75{ 76{
76 int i; 77 int i;
77 unsigned char *str = NULL; 78 unsigned char *str = NULL;
78 79
79 i=ASN1_item_i2d(asn,&str, it); 80 i = ASN1_item_i2d(asn, &str, it);
80 if (!str) return(0); 81 if (!str)
82 return (0);
81 83
82 if (!EVP_Digest(str, i, md, len, type, NULL)) 84 if (!EVP_Digest(str, i, md, len, type, NULL))
83 return 0; 85 return 0;
84 free(str); 86 free(str);
85 return(1); 87 return (1);
86} 88}
diff --git a/src/lib/libssl/src/crypto/asn1/a_dup.c b/src/lib/libssl/src/crypto/asn1/a_dup.c
index 409bdcf2d1..5f5c4951ea 100644
--- a/src/lib/libssl/src/crypto/asn1/a_dup.c
+++ b/src/lib/libssl/src/crypto/asn1/a_dup.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
@@ -62,28 +62,29 @@
62 62
63#ifndef NO_OLD_ASN1 63#ifndef NO_OLD_ASN1
64 64
65void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) 65void *
66ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
66{ 67{
67 unsigned char *b,*p; 68 unsigned char *b, *p;
68 const unsigned char *p2; 69 const unsigned char *p2;
69 int i; 70 int i;
70 char *ret; 71 char *ret;
71 72
72 if (x == NULL) 73 if (x == NULL)
73 return(NULL); 74 return (NULL);
74 75
75 i=i2d(x,NULL); 76 i = i2d(x, NULL);
76 b=malloc(i+10); 77 b = malloc(i + 10);
77 if (b == NULL) { 78 if (b == NULL) {
78 ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); 79 ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE);
79 return(NULL); 80 return (NULL);
80 } 81 }
81 p= b; 82 p = b;
82 i=i2d(x,&p); 83 i = i2d(x, &p);
83 p2= b; 84 p2 = b;
84 ret=d2i(NULL,&p2,i); 85 ret = d2i(NULL, &p2, i);
85 free(b); 86 free(b);
86 return(ret); 87 return (ret);
87} 88}
88 89
89#endif 90#endif
@@ -93,7 +94,8 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
93 * the underlying structure instead of doing and encode and decode. 94 * the underlying structure instead of doing and encode and decode.
94 */ 95 */
95 96
96void *ASN1_item_dup(const ASN1_ITEM *it, void *x) 97void *
98ASN1_item_dup(const ASN1_ITEM *it, void *x)
97{ 99{
98 unsigned char *b = NULL; 100 unsigned char *b = NULL;
99 const unsigned char *p; 101 const unsigned char *p;
@@ -101,15 +103,15 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
101 void *ret; 103 void *ret;
102 104
103 if (x == NULL) 105 if (x == NULL)
104 return(NULL); 106 return (NULL);
105 107
106 i=ASN1_item_i2d(x,&b,it); 108 i = ASN1_item_i2d(x, &b, it);
107 if (b == NULL) { 109 if (b == NULL) {
108 ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); 110 ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
109 return(NULL); 111 return (NULL);
110 } 112 }
111 p= b; 113 p = b;
112 ret=ASN1_item_d2i(NULL,&p,i, it); 114 ret = ASN1_item_d2i(NULL, &p, i, it);
113 free(b); 115 free(b);
114 return(ret); 116 return (ret);
115} 117}
diff --git a/src/lib/libssl/src/crypto/asn1/a_enum.c b/src/lib/libssl/src/crypto/asn1/a_enum.c
index 70cea0aad2..5e6f7589cf 100644
--- a/src/lib/libssl/src/crypto/asn1/a_enum.c
+++ b/src/lib/libssl/src/crypto/asn1/a_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
@@ -61,114 +61,125 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63 63
64/* 64/*
65 * Code for ENUMERATED type: identical to INTEGER apart from a different tag. 65 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
66 * for comments on encoding see a_int.c 66 * for comments on encoding see a_int.c
67 */ 67 */
68 68
69int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) 69int
70ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
70{ 71{
71 int j,k; 72 int j, k;
72 unsigned int i; 73 unsigned int i;
73 unsigned char buf[sizeof(long)+1]; 74 unsigned char buf[sizeof(long) + 1];
74 long d; 75 long d;
75 76
76 a->type=V_ASN1_ENUMERATED; 77 a->type = V_ASN1_ENUMERATED;
77 if (a->length < (int)(sizeof(long)+1)) { 78 if (a->length < (int)(sizeof(long) + 1)) {
78 if (a->data != NULL) 79 if (a->data != NULL)
79 free(a->data); 80 free(a->data);
80 if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) 81 if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
81 memset((char *)a->data,0,sizeof(long)+1); 82 memset((char *)a->data, 0, sizeof(long) + 1);
82 } 83 }
83 if (a->data == NULL) { 84 if (a->data == NULL) {
84 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); 85 ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
85 return(0); 86 return (0);
86 } 87 }
87 d=v; 88 d = v;
88 if (d < 0) { 89 if (d < 0) {
89 d= -d; 90 d = -d;
90 a->type=V_ASN1_NEG_ENUMERATED; 91 a->type = V_ASN1_NEG_ENUMERATED;
91 } 92 }
92 93
93 for (i=0; i<sizeof(long); i++) { 94 for (i = 0; i < sizeof(long); i++) {
94 if (d == 0) break; 95 if (d == 0)
95 buf[i]=(int)d&0xff; 96 break;
96 d>>=8; 97 buf[i] = (int)d & 0xff;
98 d >>= 8;
97 } 99 }
98 j=0; 100 j = 0;
99 for (k=i-1; k >=0; k--) 101 for (k = i - 1; k >=0; k--)
100 a->data[j++]=buf[k]; 102 a->data[j++] = buf[k];
101 a->length=j; 103 a->length = j;
102 return(1); 104 return (1);
103} 105}
104 106
105long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) 107long
108ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
106{ 109{
107 int neg=0,i; 110 int neg = 0, i;
108 long r=0; 111 long r = 0;
109 112
110 if (a == NULL) return(0L); 113 if (a == NULL)
111 i=a->type; 114 return (0L);
115 i = a->type;
112 if (i == V_ASN1_NEG_ENUMERATED) 116 if (i == V_ASN1_NEG_ENUMERATED)
113 neg=1; 117 neg = 1;
114 else if (i != V_ASN1_ENUMERATED) 118 else if (i != V_ASN1_ENUMERATED)
115 return -1; 119 return -1;
116 120
117 if (a->length > (int)sizeof(long)) { 121 if (a->length > (int)sizeof(long)) {
118 /* hmm... a bit ugly */ 122 /* hmm... a bit ugly */
119 return(0xffffffffL); 123 return (0xffffffffL);
120 } 124 }
121 if (a->data == NULL) 125 if (a->data == NULL)
122 return 0; 126 return 0;
123 127
124 for (i=0; i<a->length; i++) { 128 for (i = 0; i < a->length; i++) {
125 r<<=8; 129 r <<= 8;
126 r|=(unsigned char)a->data[i]; 130 r |= (unsigned char)a->data[i];
127 } 131 }
128 if (neg) r= -r; 132 if (neg)
129 return(r); 133 r = -r;
134 return (r);
130} 135}
131 136
132ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) 137ASN1_ENUMERATED *
138BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
133{ 139{
134 ASN1_ENUMERATED *ret; 140 ASN1_ENUMERATED *ret;
135 int len,j; 141 int len, j;
136 142
137 if (ai == NULL) 143 if (ai == NULL)
138 ret=M_ASN1_ENUMERATED_new(); 144 ret = M_ASN1_ENUMERATED_new();
139 else 145 else
140 ret=ai; 146 ret = ai;
141 if (ret == NULL) { 147 if (ret == NULL) {
142 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); 148 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_NESTED_ASN1_ERROR);
143 goto err; 149 goto err;
144 } 150 }
145 if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; 151 if (BN_is_negative(bn))
146 else ret->type=V_ASN1_ENUMERATED; 152 ret->type = V_ASN1_NEG_ENUMERATED;
147 j=BN_num_bits(bn); 153 else
148 len=((j == 0)?0:((j/8)+1)); 154 ret->type = V_ASN1_ENUMERATED;
149 if (ret->length < len+4) { 155 j = BN_num_bits(bn);
150 unsigned char *new_data=realloc(ret->data, len+4); 156 len = ((j == 0) ? 0 : ((j / 8) + 1));
151 if (!new_data) 157 if (ret->length < len + 4) {
152 { 158 unsigned char *new_data = realloc(ret->data, len + 4);
153 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); 159 if (!new_data) {
160 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
154 goto err; 161 goto err;
155 } 162 }
156 ret->data=new_data; 163 ret->data = new_data;
157 } 164 }
158 165
159 ret->length=BN_bn2bin(bn,ret->data); 166 ret->length = BN_bn2bin(bn, ret->data);
160 return(ret); 167 return (ret);
168
161err: 169err:
162 if (ret != ai) M_ASN1_ENUMERATED_free(ret); 170 if (ret != ai)
163 return(NULL); 171 M_ASN1_ENUMERATED_free(ret);
172 return (NULL);
164} 173}
165 174
166BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) 175BIGNUM *
176ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
167{ 177{
168 BIGNUM *ret; 178 BIGNUM *ret;
169 179
170 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 180 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
171 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); 181 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN, ASN1_R_BN_LIB);
172 else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); 182 else if (ai->type == V_ASN1_NEG_ENUMERATED)
173 return(ret); 183 BN_set_negative(ret, 1);
184 return (ret);
174} 185}
diff --git a/src/lib/libssl/src/crypto/asn1/a_gentm.c b/src/lib/libssl/src/crypto/asn1/a_gentm.c
index 2ef6e6bc22..56f8992424 100644
--- a/src/lib/libssl/src/crypto/asn1/a_gentm.c
+++ b/src/lib/libssl/src/crypto/asn1/a_gentm.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
@@ -48,8 +48,8 @@
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -66,170 +66,187 @@
66 66
67#if 0 67#if 0
68 68
69int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) 69int
70i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
70{ 71{
71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 72 return(i2d_ASN1_bytes((ASN1_STRING *)a, pp,
72 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); 73 V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL));
73} 74}
74 75
75 76
76ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, 77ASN1_GENERALIZEDTIME *
77 unsigned char **pp, long length) 78d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, unsigned char **pp,
79 long length)
78{ 80{
79 ASN1_GENERALIZEDTIME *ret=NULL; 81 ASN1_GENERALIZEDTIME *ret = NULL;
80 82
81 ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, 83 ret = (ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
82 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); 84 V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL);
83 if (ret == NULL) 85 if (ret == NULL) {
84 { 86 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ERR_R_NESTED_ASN1_ERROR);
85 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); 87 return (NULL);
86 return(NULL);
87 } 88 }
88 if (!ASN1_GENERALIZEDTIME_check(ret)) 89 if (!ASN1_GENERALIZEDTIME_check(ret)) {
89 { 90 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ASN1_R_INVALID_TIME_FORMAT);
90 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
91 goto err; 91 goto err;
92 } 92 }
93 93
94 return(ret); 94 return (ret);
95
95err: 96err:
96 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 97 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
97 M_ASN1_GENERALIZEDTIME_free(ret); 98 M_ASN1_GENERALIZEDTIME_free(ret);
98 return(NULL); 99 return (NULL);
99} 100}
100 101
101#endif 102#endif
102 103
103int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) 104int
105ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
104{ 106{
105 static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; 107 static const int min[9] = {0, 0, 1, 1, 0, 0, 0, 0, 0};
106 static const int max[9]={99, 99,12,31,23,59,59,12,59}; 108 static const int max[9] = {99, 99, 12, 31, 23, 59, 59, 12, 59};
107 char *a; 109 char *a;
108 int n,i,l,o; 110 int n, i, l, o;
109 111
110 if (d->type != V_ASN1_GENERALIZEDTIME) return(0); 112 if (d->type != V_ASN1_GENERALIZEDTIME)
111 l=d->length; 113 return (0);
112 a=(char *)d->data; 114 l = d->length;
113 o=0; 115 a = (char *)d->data;
116 o = 0;
114 /* GENERALIZEDTIME is similar to UTCTIME except the year is 117 /* GENERALIZEDTIME is similar to UTCTIME except the year is
115 * represented as YYYY. This stuff treats everything as a two digit 118 * represented as YYYY. This stuff treats everything as a two digit
116 * field so make first two fields 00 to 99 119 * field so make first two fields 00 to 99
117 */ 120 */
118 if (l < 13) goto err; 121 if (l < 13)
119 for (i=0; i<7; i++) { 122 goto err;
123 for (i = 0; i < 7; i++) {
120 if ((i == 6) && ((a[o] == 'Z') || 124 if ((i == 6) && ((a[o] == 'Z') ||
121 (a[o] == '+') || (a[o] == '-'))) 125 (a[o] == '+') || (a[o] == '-'))) {
122 { i++; break; } 126 i++;
123 if ((a[o] < '0') || (a[o] > '9')) goto err; 127 break;
128 }
129 if ((a[o] < '0') || (a[o] > '9'))
130 goto err;
124 n= a[o]-'0'; 131 n= a[o]-'0';
125 if (++o > l) goto err; 132 if (++o > l)
133 goto err;
126 134
127 if ((a[o] < '0') || (a[o] > '9')) goto err; 135 if ((a[o] < '0') || (a[o] > '9'))
128 n=(n*10)+ a[o]-'0'; 136 goto err;
129 if (++o > l) goto err; 137 n = (n * 10)+ a[o] - '0';
138 if (++o > l)
139 goto err;
130 140
131 if ((n < min[i]) || (n > max[i])) goto err; 141 if ((n < min[i]) || (n > max[i]))
142 goto err;
132 } 143 }
133 /* Optional fractional seconds: decimal point followed by one 144 /* Optional fractional seconds: decimal point followed by one
134 * or more digits. 145 * or more digits.
135 */ 146 */
136 if (a[o] == '.') 147 if (a[o] == '.') {
137 { 148 if (++o > l)
138 if (++o > l) goto err; 149 goto err;
139 i = o; 150 i = o;
140 while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) 151 while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
141 o++; 152 o++;
142 /* Must have at least one digit after decimal point */ 153 /* Must have at least one digit after decimal point */
143 if (i == o) goto err; 154 if (i == o)
155 goto err;
144 } 156 }
145 157
146 if (a[o] == 'Z') 158 if (a[o] == 'Z')
147 o++; 159 o++;
148 else if ((a[o] == '+') || (a[o] == '-')) { 160 else if ((a[o] == '+') || (a[o] == '-')) {
149 o++; 161 o++;
150 if (o+4 > l) goto err; 162 if (o + 4 > l)
151 for (i=7; i<9; i++) { 163 goto err;
152 if ((a[o] < '0') || (a[o] > '9')) goto err; 164 for (i = 7; i < 9; i++) {
153 n= a[o]-'0'; 165 if ((a[o] < '0') || (a[o] > '9'))
166 goto err;
167 n = a[o] - '0';
154 o++; 168 o++;
155 if ((a[o] < '0') || (a[o] > '9')) goto err; 169 if ((a[o] < '0') || (a[o] > '9'))
156 n=(n*10)+ a[o]-'0'; 170 goto err;
157 if ((n < min[i]) || (n > max[i])) goto err; 171 n = (n * 10) + a[o] - '0';
172 if ((n < min[i]) || (n > max[i]))
173 goto err;
158 o++; 174 o++;
159 } 175 }
160 } else { 176 } else {
161 /* Missing time zone information. */ 177 /* Missing time zone information. */
162 goto err; 178 goto err;
163 } 179 }
164 return(o == l); 180 return (o == l);
165err: 181err:
166 return(0); 182 return (0);
167} 183}
168 184
169int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) 185int
186ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
170{ 187{
171 ASN1_GENERALIZEDTIME t; 188 ASN1_GENERALIZEDTIME t;
172 189
173 t.type=V_ASN1_GENERALIZEDTIME; 190 t.type = V_ASN1_GENERALIZEDTIME;
174 t.length=strlen(str); 191 t.length = strlen(str);
175 t.data=(unsigned char *)str; 192 t.data = (unsigned char *)str;
176 if (ASN1_GENERALIZEDTIME_check(&t)) { 193 if (ASN1_GENERALIZEDTIME_check(&t)) {
177 if (s != NULL) { 194 if (s != NULL) {
178 if (!ASN1_STRING_set((ASN1_STRING *)s, 195 if (!ASN1_STRING_set((ASN1_STRING *)s,
179 (unsigned char *)str,t.length)) 196 (unsigned char *)str, t.length))
180 return 0; 197 return 0;
181 s->type=V_ASN1_GENERALIZEDTIME; 198 s->type = V_ASN1_GENERALIZEDTIME;
182 } 199 }
183 return(1); 200 return (1);
184 } 201 } else
185 else 202 return (0);
186 return(0);
187} 203}
188 204
189ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, 205ASN1_GENERALIZEDTIME *
190 time_t t) 206ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, time_t t)
191{ 207{
192 return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); 208 return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
193} 209}
194 210
195ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, 211ASN1_GENERALIZEDTIME *
196 time_t t, int offset_day, long offset_sec) 212ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day,
213 long offset_sec)
197{ 214{
198 char *p; 215 char *p;
199 struct tm *ts; 216 struct tm *ts;
200 struct tm data; 217 struct tm data;
201 size_t len = 20; 218 size_t len = 20;
202 219
203 if (s == NULL) 220 if (s == NULL)
204 s=M_ASN1_GENERALIZEDTIME_new(); 221 s = M_ASN1_GENERALIZEDTIME_new();
205 if (s == NULL) 222 if (s == NULL)
206 return(NULL); 223 return (NULL);
207 224
208 ts=OPENSSL_gmtime(&t, &data); 225 ts = OPENSSL_gmtime(&t, &data);
209 if (ts == NULL) 226 if (ts == NULL)
210 return(NULL); 227 return (NULL);
211 228
212 if (offset_day || offset_sec) { 229 if (offset_day || offset_sec) {
213 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) 230 if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
214 return NULL; 231 return NULL;
215 } 232 }
216 233
217 p=(char *)s->data; 234 p = (char *)s->data;
218 if ((p == NULL) || ((size_t)s->length < len)) { 235 if ((p == NULL) || ((size_t)s->length < len)) {
219 p=malloc(len); 236 p = malloc(len);
220 if (p == NULL) { 237 if (p == NULL) {
221 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, 238 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
222 ERR_R_MALLOC_FAILURE); 239 ERR_R_MALLOC_FAILURE);
223 return(NULL); 240 return (NULL);
224 } 241 }
225 if (s->data != NULL) 242 if (s->data != NULL)
226 free(s->data); 243 free(s->data);
227 s->data=(unsigned char *)p; 244 s->data = (unsigned char *)p;
228 } 245 }
229 246
230 (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, 247 (void) snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
231 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 248 ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
232 s->length=strlen(p); 249 s->length = strlen(p);
233 s->type=V_ASN1_GENERALIZEDTIME; 250 s->type = V_ASN1_GENERALIZEDTIME;
234 return(s); 251 return (s);
235} 252}
diff --git a/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c b/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c
index 93e6d8351b..082ba1b3a8 100644
--- a/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c
+++ b/src/lib/libssl/src/crypto/asn1/a_i2d_fp.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
@@ -64,92 +64,98 @@
64#ifndef NO_OLD_ASN1 64#ifndef NO_OLD_ASN1
65 65
66#ifndef OPENSSL_NO_FP_API 66#ifndef OPENSSL_NO_FP_API
67int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) 67int
68ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
68{ 69{
69 BIO *b; 70 BIO *b;
70 int ret; 71 int ret;
71 72
72 if ((b=BIO_new(BIO_s_file())) == NULL) { 73 if ((b = BIO_new(BIO_s_file())) == NULL) {
73 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); 74 ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB);
74 return(0); 75 return (0);
75 } 76 }
76 BIO_set_fp(b,out,BIO_NOCLOSE); 77 BIO_set_fp(b, out, BIO_NOCLOSE);
77 ret=ASN1_i2d_bio(i2d,b,x); 78 ret = ASN1_i2d_bio(i2d, b, x);
78 BIO_free(b); 79 BIO_free(b);
79 return(ret); 80 return (ret);
80} 81}
81#endif 82#endif
82 83
83int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) 84int
85ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
84{ 86{
85 char *b; 87 char *b;
86 unsigned char *p; 88 unsigned char *p;
87 int i,j=0,n,ret=1; 89 int i, j = 0, n, ret = 1;
88 90
89 n=i2d(x,NULL); 91 n = i2d(x, NULL);
90 b=(char *)malloc(n); 92 b = (char *)malloc(n);
91 if (b == NULL) { 93 if (b == NULL) {
92 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); 94 ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
93 return(0); 95 return (0);
94 } 96 }
95 97
96 p=(unsigned char *)b; 98 p = (unsigned char *)b;
97 i2d(x,&p); 99 i2d(x, &p);
98 100
99 for (;;) { 101 for (;;) {
100 i=BIO_write(out,&(b[j]),n); 102 i = BIO_write(out, &(b[j]), n);
101 if (i == n) break; 103 if (i == n)
104 break;
102 if (i <= 0) { 105 if (i <= 0) {
103 ret=0; 106 ret = 0;
104 break; 107 break;
105 } 108 }
106 j+=i; 109 j += i;
107 n-=i; 110 n -= i;
108 } 111 }
109 free(b); 112 free(b);
110 return(ret); 113 return (ret);
111} 114}
112 115
113#endif 116#endif
114 117
115#ifndef OPENSSL_NO_FP_API 118#ifndef OPENSSL_NO_FP_API
116int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) 119int
120ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
117{ 121{
118 BIO *b; 122 BIO *b;
119 int ret; 123 int ret;
120 124
121 if ((b=BIO_new(BIO_s_file())) == NULL) { 125 if ((b = BIO_new(BIO_s_file())) == NULL) {
122 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); 126 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
123 return(0); 127 return (0);
124 } 128 }
125 BIO_set_fp(b,out,BIO_NOCLOSE); 129 BIO_set_fp(b, out, BIO_NOCLOSE);
126 ret=ASN1_item_i2d_bio(it,b,x); 130 ret = ASN1_item_i2d_bio(it, b, x);
127 BIO_free(b); 131 BIO_free(b);
128 return(ret); 132 return (ret);
129} 133}
130#endif 134#endif
131 135
132int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) 136int
137ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
133{ 138{
134 unsigned char *b = NULL; 139 unsigned char *b = NULL;
135 int i,j=0,n,ret=1; 140 int i, j = 0, n, ret = 1;
136 141
137 n = ASN1_item_i2d(x, &b, it); 142 n = ASN1_item_i2d(x, &b, it);
138 if (b == NULL) { 143 if (b == NULL) {
139 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); 144 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE);
140 return(0); 145 return (0);
141 } 146 }
142 147
143 for (;;) { 148 for (;;) {
144 i=BIO_write(out,&(b[j]),n); 149 i = BIO_write(out, &(b[j]), n);
145 if (i == n) break; 150 if (i == n)
151 break;
146 if (i <= 0) { 152 if (i <= 0) {
147 ret=0; 153 ret = 0;
148 break; 154 break;
149 } 155 }
150 j+=i; 156 j += i;
151 n-=i; 157 n -= i;
152 } 158 }
153 free(b); 159 free(b);
154 return(ret); 160 return (ret);
155} 161}
diff --git a/src/lib/libssl/src/crypto/asn1/a_int.c b/src/lib/libssl/src/crypto/asn1/a_int.c
index cc2b985fa1..ef47eb106b 100644
--- a/src/lib/libssl/src/crypto/asn1/a_int.c
+++ b/src/lib/libssl/src/crypto/asn1/a_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,12 +61,17 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63 63
64ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) 64ASN1_INTEGER *
65{ return M_ASN1_INTEGER_dup(x);} 65ASN1_INTEGER_dup(const ASN1_INTEGER *x)
66{
67 return M_ASN1_INTEGER_dup(x);
68}
66 69
67int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) 70int
68{ 71ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
72{
69 int neg, ret; 73 int neg, ret;
74
70 /* Compare signs */ 75 /* Compare signs */
71 neg = x->type & V_ASN1_NEG; 76 neg = x->type & V_ASN1_NEG;
72 if (neg != (y->type & V_ASN1_NEG)) { 77 if (neg != (y->type & V_ASN1_NEG)) {
@@ -83,23 +88,23 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
83 else 88 else
84 return ret; 89 return ret;
85} 90}
86
87 91
88/* 92
93/*
89 * This converts an ASN1 INTEGER into its content encoding. 94 * This converts an ASN1 INTEGER into its content encoding.
90 * The internal representation is an ASN1_STRING whose data is a big endian 95 * The internal representation is an ASN1_STRING whose data is a big endian
91 * representation of the value, ignoring the sign. The sign is determined by 96 * representation of the value, ignoring the sign. The sign is determined by
92 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. 97 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
93 * 98 *
94 * Positive integers are no problem: they are almost the same as the DER 99 * Positive integers are no problem: they are almost the same as the DER
95 * encoding, except if the first byte is >= 0x80 we need to add a zero pad. 100 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
96 * 101 *
97 * Negative integers are a bit trickier... 102 * Negative integers are a bit trickier...
98 * The DER representation of negative integers is in 2s complement form. 103 * The DER representation of negative integers is in 2s complement form.
99 * The internal form is converted by complementing each octet and finally 104 * The internal form is converted by complementing each octet and finally
100 * adding one to the result. This can be done less messily with a little trick. 105 * adding one to the result. This can be done less messily with a little trick.
101 * If the internal form has trailing zeroes then they will become FF by the 106 * If the internal form has trailing zeroes then they will become FF by the
102 * complement and 0 by the add one (due to carry) so just copy as many trailing 107 * complement and 0 by the add one (due to carry) so just copy as many trailing
103 * zeros to the destination as there are in the source. The carry will add one 108 * zeros to the destination as there are in the source. The carry will add one
104 * to the last none zero octet: so complement this octet and add one and finally 109 * to the last none zero octet: so complement this octet and add one and finally
105 * complement any left over until you get to the start of the string. 110 * complement any left over until you get to the start of the string.
@@ -110,102 +115,109 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
110 * followed by optional zeros isn't padded. 115 * followed by optional zeros isn't padded.
111 */ 116 */
112 117
113int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) 118int
119i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
114{ 120{
115 int pad=0,ret,i,neg; 121 int pad = 0, ret, i, neg;
116 unsigned char *p,*n,pb=0; 122 unsigned char *p, *n, pb = 0;
117 123
118 if (a == NULL) return(0); 124 if (a == NULL)
119 neg=a->type & V_ASN1_NEG; 125 return (0);
126 neg = a->type & V_ASN1_NEG;
120 if (a->length == 0) 127 if (a->length == 0)
121 ret=1; 128 ret = 1;
122 else { 129 else {
123 ret=a->length; 130 ret = a->length;
124 i=a->data[0]; 131 i = a->data[0];
125 if (!neg && (i > 127)) { 132 if (!neg && (i > 127)) {
126 pad=1; 133 pad = 1;
127 pb=0; 134 pb = 0;
128 } else if(neg) { 135 } else if (neg) {
129 if(i>128) { 136 if (i > 128) {
130 pad=1; 137 pad = 1;
131 pb=0xFF; 138 pb = 0xFF;
132 } else if(i == 128) { 139 } else if (i == 128) {
133 /* 140 /*
134 * Special case: if any other bytes non zero we pad: 141 * Special case: if any other bytes non zero we pad:
135 * otherwise we don't. 142 * otherwise we don't.
136 */ 143 */
137 for(i = 1; i < a->length; i++) if(a->data[i]) { 144 for (i = 1; i < a->length; i++) if (a->data[i]) {
138 pad=1; 145 pad = 1;
139 pb=0xFF; 146 pb = 0xFF;
140 break; 147 break;
148 }
141 } 149 }
142 } 150 }
151 ret += pad;
143 } 152 }
144 ret+=pad; 153 if (pp == NULL)
145 } 154 return (ret);
146 if (pp == NULL) return(ret);
147 p= *pp; 155 p= *pp;
148 156
149 if (pad) *(p++)=pb; 157 if (pad)
150 if (a->length == 0) *(p++)=0; 158 *(p++) = pb;
151 else if (!neg) memcpy(p,a->data,(unsigned int)a->length); 159 if (a->length == 0)
160 *(p++) = 0;
161 else if (!neg)
162 memcpy(p, a->data, (unsigned int)a->length);
152 else { 163 else {
153 /* Begin at the end of the encoding */ 164 /* Begin at the end of the encoding */
154 n=a->data + a->length - 1; 165 n = a->data + a->length - 1;
155 p += a->length - 1; 166 p += a->length - 1;
156 i = a->length; 167 i = a->length;
157 /* Copy zeros to destination as long as source is zero */ 168 /* Copy zeros to destination as long as source is zero */
158 while(!*n) { 169 while (!*n) {
159 *(p--) = 0; 170 *(p--) = 0;
160 n--; 171 n--;
161 i--; 172 i--;
162 } 173 }
163 /* Complement and increment next octet */ 174 /* Complement and increment next octet */
164 *(p--) = ((*(n--)) ^ 0xff) + 1; 175 *(p--) = ((*(n--)) ^ 0xff) + 1;
165 i--; 176 i--;
166 /* Complement any octets left */ 177 /* Complement any octets left */
167 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; 178 for(; i > 0; i--)
168} 179 *(p--) = *(n--) ^ 0xff;
180 }
169 181
170 *pp+=ret; 182 *pp += ret;
171 return(ret); 183 return (ret);
172} 184}
173 185
174/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ 186/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
175 187
176ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, 188ASN1_INTEGER *
177 long len) 189c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
178{ 190{
179 ASN1_INTEGER *ret=NULL; 191 ASN1_INTEGER *ret = NULL;
180 const unsigned char *p, *pend; 192 const unsigned char *p, *pend;
181 unsigned char *to,*s; 193 unsigned char *to, *s;
182 int i; 194 int i;
183 195
184 if ((a == NULL) || ((*a) == NULL)) { 196 if ((a == NULL) || ((*a) == NULL)) {
185 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); 197 if ((ret = M_ASN1_INTEGER_new()) == NULL)
186 ret->type=V_ASN1_INTEGER; 198 return (NULL);
187 } 199 ret->type = V_ASN1_INTEGER;
188 else 200 } else
189 ret=(*a); 201 ret = (*a);
190 202
191 p= *pp; 203 p= *pp;
192 pend = p + len; 204 pend = p + len;
193 205
194 /* We must malloc stuff, even for 0 bytes otherwise it 206 /* We must malloc stuff, even for 0 bytes otherwise it
195 * signifies a missing NULL parameter. */ 207 * signifies a missing NULL parameter. */
196 s=(unsigned char *)malloc((int)len+1); 208 s = (unsigned char *)malloc((int)len + 1);
197 if (s == NULL) { 209 if (s == NULL) {
198 i=ERR_R_MALLOC_FAILURE; 210 i = ERR_R_MALLOC_FAILURE;
199 goto err; 211 goto err;
200 } 212 }
201 to=s; 213 to = s;
202 if(!len) { 214 if (!len) {
203 /* Strictly speaking this is an illegal INTEGER but we 215 /* Strictly speaking this is an illegal INTEGER but we
204 * tolerate it. 216 * tolerate it.
205 */ 217 */
206 ret->type=V_ASN1_INTEGER; 218 ret->type = V_ASN1_INTEGER;
207 } else if (*p & 0x80) /* a negative number */ { 219 } else if (*p & 0x80) /* a negative number */ {
208 ret->type=V_ASN1_NEG_INTEGER; 220 ret->type = V_ASN1_NEG_INTEGER;
209 if ((*p == 0xff) && (len != 1)) { 221 if ((*p == 0xff) && (len != 1)) {
210 p++; 222 p++;
211 len--; 223 len--;
@@ -225,35 +237,39 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
225 * a 1. This is treated separately because it is the only case 237 * a 1. This is treated separately because it is the only case
226 * where the number of bytes is larger than len. 238 * where the number of bytes is larger than len.
227 */ 239 */
228 if(!i) { 240 if (!i) {
229 *s = 1; 241 *s = 1;
230 s[len] = 0; 242 s[len] = 0;
231 len++; 243 len++;
232 } else { 244 } else {
233 *(to--) = (*(p--) ^ 0xff) + 1; 245 *(to--) = (*(p--) ^ 0xff) + 1;
234 i--; 246 i--;
235 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; 247 for(; i > 0; i--)
248 *(to--) = *(p--) ^ 0xff;
236 } 249 }
237 } else { 250 } else {
238 ret->type=V_ASN1_INTEGER; 251 ret->type = V_ASN1_INTEGER;
239 if ((*p == 0) && (len != 1)) { 252 if ((*p == 0) && (len != 1)) {
240 p++; 253 p++;
241 len--; 254 len--;
242 } 255 }
243 memcpy(s,p,(int)len); 256 memcpy(s, p, (int)len);
244 } 257 }
245 258
246 if (ret->data != NULL) free(ret->data); 259 if (ret->data != NULL)
247 ret->data=s; 260 free(ret->data);
248 ret->length=(int)len; 261 ret->data = s;
249 if (a != NULL) (*a)=ret; 262 ret->length = (int)len;
250 *pp=pend; 263 if (a != NULL)
251 return(ret); 264 (*a) = ret;
265 *pp = pend;
266 return (ret);
267
252err: 268err:
253 ASN1err(ASN1_F_C2I_ASN1_INTEGER,i); 269 ASN1err(ASN1_F_C2I_ASN1_INTEGER, i);
254 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 270 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
255 M_ASN1_INTEGER_free(ret); 271 M_ASN1_INTEGER_free(ret);
256 return(NULL); 272 return (NULL);
257} 273}
258 274
259 275
@@ -262,112 +278,120 @@ err:
262 * with its MSB set as negative (it doesn't add a padding zero). 278 * with its MSB set as negative (it doesn't add a padding zero).
263 */ 279 */
264 280
265ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, 281ASN1_INTEGER *
266 long length) 282d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
267{ 283{
268 ASN1_INTEGER *ret=NULL; 284 ASN1_INTEGER *ret = NULL;
269 const unsigned char *p; 285 const unsigned char *p;
270 unsigned char *s; 286 unsigned char *s;
271 long len; 287 long len;
272 int inf,tag,xclass; 288 int inf, tag, xclass;
273 int i; 289 int i;
274 290
275 if ((a == NULL) || ((*a) == NULL)) { 291 if ((a == NULL) || ((*a) == NULL)) {
276 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); 292 if ((ret = M_ASN1_INTEGER_new()) == NULL)
277 ret->type=V_ASN1_INTEGER; 293 return (NULL);
294 ret->type = V_ASN1_INTEGER;
278 } else 295 } else
279 ret=(*a); 296 ret = (*a);
280 297
281 p= *pp; 298 p = *pp;
282 inf=ASN1_get_object(&p,&len,&tag,&xclass,length); 299 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
283 if (inf & 0x80) { 300 if (inf & 0x80) {
284 i=ASN1_R_BAD_OBJECT_HEADER; 301 i = ASN1_R_BAD_OBJECT_HEADER;
285 goto err; 302 goto err;
286 } 303 }
287 304
288 if (tag != V_ASN1_INTEGER) { 305 if (tag != V_ASN1_INTEGER) {
289 i=ASN1_R_EXPECTING_AN_INTEGER; 306 i = ASN1_R_EXPECTING_AN_INTEGER;
290 goto err; 307 goto err;
291 } 308 }
292 309
293 /* We must malloc stuff, even for 0 bytes otherwise it 310 /* We must malloc stuff, even for 0 bytes otherwise it
294 * signifies a missing NULL parameter. */ 311 * signifies a missing NULL parameter. */
295 s=(unsigned char *)malloc((int)len+1); 312 s = (unsigned char *)malloc((int)len + 1);
296 if (s == NULL) { 313 if (s == NULL) {
297 i=ERR_R_MALLOC_FAILURE; 314 i = ERR_R_MALLOC_FAILURE;
298 goto err; 315 goto err;
299 } 316 }
300 ret->type=V_ASN1_INTEGER; 317 ret->type = V_ASN1_INTEGER;
301 if(len) { 318 if (len) {
302 if ((*p == 0) && (len != 1)) { 319 if ((*p == 0) && (len != 1)) {
303 p++; 320 p++;
304 len--; 321 len--;
305 } 322 }
306 memcpy(s,p,(int)len); 323 memcpy(s, p, (int)len);
307 p+=len; 324 p += len;
308 } 325 }
309 326
310 if (ret->data != NULL) free(ret->data); 327 if (ret->data != NULL)
311 ret->data=s; 328 free(ret->data);
312 ret->length=(int)len; 329 ret->data = s;
313 if (a != NULL) (*a)=ret; 330 ret->length = (int)len;
314 *pp=p; 331 if (a != NULL)
315 return(ret); 332 (*a) = ret;
333 *pp = p;
334 return (ret);
335
316err: 336err:
317 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); 337 ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i);
318 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 338 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
319 M_ASN1_INTEGER_free(ret); 339 M_ASN1_INTEGER_free(ret);
320 return(NULL); 340 return (NULL);
321} 341}
322 342
323int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) 343int
344ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
324{ 345{
325 int j,k; 346 int j, k;
326 unsigned int i; 347 unsigned int i;
327 unsigned char buf[sizeof(long)+1]; 348 unsigned char buf[sizeof(long) + 1];
328 long d; 349 long d;
329 350
330 a->type=V_ASN1_INTEGER; 351 a->type = V_ASN1_INTEGER;
331 if (a->length < (int)(sizeof(long)+1)) { 352 if (a->length < (int)(sizeof(long) + 1)) {
332 if (a->data != NULL) 353 if (a->data != NULL)
333 free(a->data); 354 free(a->data);
334 if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) 355 if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
335 memset((char *)a->data,0,sizeof(long)+1); 356 memset((char *)a->data, 0, sizeof(long) + 1);
336 } 357 }
337 if (a->data == NULL) { 358 if (a->data == NULL) {
338 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); 359 ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
339 return(0); 360 return (0);
340 } 361 }
341 d=v; 362 d = v;
342 if (d < 0) { 363 if (d < 0) {
343 d= -d; 364 d = -d;
344 a->type=V_ASN1_NEG_INTEGER; 365 a->type = V_ASN1_NEG_INTEGER;
345 } 366 }
346 367
347 for (i=0; i<sizeof(long); i++) { 368 for (i = 0; i < sizeof(long); i++) {
348 if (d == 0) break; 369 if (d == 0)
349 buf[i]=(int)d&0xff; 370 break;
350 d>>=8; 371 buf[i] = (int)d & 0xff;
372 d >>= 8;
351 } 373 }
352 j=0; 374 j = 0;
353 for (k=i-1; k >=0; k--) 375 for (k = i - 1; k >= 0; k--)
354 a->data[j++]=buf[k]; 376 a->data[j++] = buf[k];
355 a->length=j; 377 a->length = j;
356 return(1); 378 return (1);
357} 379}
358 380
359long ASN1_INTEGER_get(const ASN1_INTEGER *a) 381long
382ASN1_INTEGER_get(const ASN1_INTEGER *a)
360{ 383{
361 int neg=0,i; 384 int neg = 0, i;
362 long r=0; 385 long r = 0;
363 386
364 if (a == NULL) return(0L); 387 if (a == NULL)
365 i=a->type; 388 return (0L);
389 i = a->type;
366 if (i == V_ASN1_NEG_INTEGER) 390 if (i == V_ASN1_NEG_INTEGER)
367 neg=1; 391 neg = 1;
368 else if (i != V_ASN1_INTEGER) 392 else if (i != V_ASN1_INTEGER)
369 return -1; 393 return -1;
370 394
371 if (a->length > (int)sizeof(long)) { 395 if (a->length > (int)sizeof(long)) {
372 /* hmm... a bit ugly, return all ones */ 396 /* hmm... a bit ugly, return all ones */
373 return -1; 397 return -1;
@@ -375,61 +399,68 @@ long ASN1_INTEGER_get(const ASN1_INTEGER *a)
375 if (a->data == NULL) 399 if (a->data == NULL)
376 return 0; 400 return 0;
377 401
378 for (i=0; i<a->length; i++) { 402 for (i = 0; i < a->length; i++) {
379 r<<=8; 403 r <<= 8;
380 r|=(unsigned char)a->data[i]; 404 r |= (unsigned char)a->data[i];
381 } 405 }
382 if (neg) r= -r; 406 if (neg)
383 return(r); 407 r = -r;
408 return (r);
384} 409}
385 410
386ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) 411ASN1_INTEGER *
412BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
387{ 413{
388 ASN1_INTEGER *ret; 414 ASN1_INTEGER *ret;
389 int len,j; 415 int len, j;
390 416
391 if (ai == NULL) 417 if (ai == NULL)
392 ret=M_ASN1_INTEGER_new(); 418 ret = M_ASN1_INTEGER_new();
393 else 419 else
394 ret=ai; 420 ret = ai;
395 if (ret == NULL) { 421 if (ret == NULL) {
396 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); 422 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR);
397 goto err; 423 goto err;
398 } 424 }
399 if (BN_is_negative(bn)) 425 if (BN_is_negative(bn))
400 ret->type = V_ASN1_NEG_INTEGER; 426 ret->type = V_ASN1_NEG_INTEGER;
401 else ret->type=V_ASN1_INTEGER; 427 else
402 j=BN_num_bits(bn); 428 ret->type = V_ASN1_INTEGER;
403 len=((j == 0)?0:((j/8)+1)); 429 j = BN_num_bits(bn);
404 if (ret->length < len+4) { 430 len = ((j == 0) ? 0 : ((j / 8) + 1));
405 unsigned char *new_data=realloc(ret->data, len+4); 431 if (ret->length < len + 4) {
432 unsigned char *new_data = realloc(ret->data, len + 4);
406 if (!new_data) { 433 if (!new_data) {
407 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); 434 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
408 goto err; 435 goto err;
409 } 436 }
410 ret->data=new_data; 437 ret->data = new_data;
411 } 438 }
412 ret->length=BN_bn2bin(bn,ret->data); 439 ret->length = BN_bn2bin(bn, ret->data);
440
413 /* Correct zero case */ 441 /* Correct zero case */
414 if(!ret->length) { 442 if (!ret->length) {
415 ret->data[0] = 0; 443 ret->data[0] = 0;
416 ret->length = 1; 444 ret->length = 1;
417 } 445 }
418 return(ret); 446 return (ret);
447
419err: 448err:
420 if (ret != ai) M_ASN1_INTEGER_free(ret); 449 if (ret != ai)
421 return(NULL); 450 M_ASN1_INTEGER_free(ret);
451 return (NULL);
422} 452}
423 453
424BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) 454BIGNUM *
455ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
425{ 456{
426 BIGNUM *ret; 457 BIGNUM *ret;
427 458
428 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 459 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
429 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); 460 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN, ASN1_R_BN_LIB);
430 else if(ai->type == V_ASN1_NEG_INTEGER) 461 else if (ai->type == V_ASN1_NEG_INTEGER)
431 BN_set_negative(ret, 1); 462 BN_set_negative(ret, 1);
432 return(ret); 463 return (ret);
433} 464}
434 465
435IMPLEMENT_STACK_OF(ASN1_INTEGER) 466IMPLEMENT_STACK_OF(ASN1_INTEGER)
diff --git a/src/lib/libssl/src/crypto/asn1/a_mbstr.c b/src/lib/libssl/src/crypto/asn1/a_mbstr.c
index f6d8da8b3c..5a909d6ae2 100644
--- a/src/lib/libssl/src/crypto/asn1/a_mbstr.c
+++ b/src/lib/libssl/src/crypto/asn1/a_mbstr.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -62,7 +62,7 @@
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63 63
64static int traverse_string(const unsigned char *p, int len, int inform, 64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg); 65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg); 66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg); 67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg); 68static int type_str(unsigned long value, void *arg);
@@ -80,15 +80,17 @@ static int is_printable(unsigned long value);
80 * The 'ncopy' form checks minimum and maximum size limits too. 80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */ 81 */
82 82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, 83int
84 int inform, unsigned long mask) 84ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
85 int inform, unsigned long mask)
85{ 86{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0); 87 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87} 88}
88 89
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, 90int
90 int inform, unsigned long mask, 91ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
91 long minsize, long maxsize) 92 int inform, unsigned long mask,
93 long minsize, long maxsize)
92{ 94{
93 int str_type; 95 int str_type;
94 int ret; 96 int ret;
@@ -98,59 +100,62 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
98 unsigned char *p; 100 unsigned char *p;
99 int nchar; 101 int nchar;
100 char strbuf[32]; 102 char strbuf[32];
101 int (*cpyfunc)(unsigned long,void *) = NULL; 103 int (*cpyfunc)(unsigned long, void *) = NULL;
102 if(len == -1) len = strlen((const char *)in); 104
103 if(!mask) mask = DIRSTRING_TYPE; 105 if (len == -1)
106 len = strlen((const char *)in);
107 if (!mask)
108 mask = DIRSTRING_TYPE;
104 109
105 /* First do a string check and work out the number of characters */ 110 /* First do a string check and work out the number of characters */
106 switch(inform) { 111 switch (inform) {
107 112
108 case MBSTRING_BMP: 113 case MBSTRING_BMP:
109 if(len & 1) { 114 if (len & 1) {
110 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 115 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
111 ASN1_R_INVALID_BMPSTRING_LENGTH); 116 ASN1_R_INVALID_BMPSTRING_LENGTH);
112 return -1; 117 return -1;
113 } 118 }
114 nchar = len >> 1; 119 nchar = len >> 1;
115 break; 120 break;
116 121
117 case MBSTRING_UNIV: 122 case MBSTRING_UNIV:
118 if(len & 3) { 123 if (len & 3) {
119 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 124 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH); 125 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
121 return -1; 126 return -1;
122 } 127 }
123 nchar = len >> 2; 128 nchar = len >> 2;
124 break; 129 break;
125 130
126 case MBSTRING_UTF8: 131 case MBSTRING_UTF8:
127 nchar = 0; 132 nchar = 0;
128 /* This counts the characters and does utf8 syntax checking */ 133 /* This counts the characters and does utf8 syntax checking */
129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar); 134 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
130 if(ret < 0) { 135 if (ret < 0) {
131 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 136 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
132 ASN1_R_INVALID_UTF8STRING); 137 ASN1_R_INVALID_UTF8STRING);
133 return -1; 138 return -1;
134 } 139 }
135 break; 140 break;
136 141
137 case MBSTRING_ASC: 142 case MBSTRING_ASC:
138 nchar = len; 143 nchar = len;
139 break; 144 break;
140 145
141 default: 146 default:
142 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT); 147 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT);
143 return -1; 148 return -1;
144 } 149 }
145 150
146 if((minsize > 0) && (nchar < minsize)) { 151 if ((minsize > 0) && (nchar < minsize)) {
147 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT); 152 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT);
148 (void) snprintf(strbuf, sizeof strbuf, "%ld", minsize); 153 (void) snprintf(strbuf, sizeof strbuf, "%ld", minsize);
149 ERR_add_error_data(2, "minsize=", strbuf); 154 ERR_add_error_data(2, "minsize=", strbuf);
150 return -1; 155 return -1;
151 } 156 }
152 157
153 if((maxsize > 0) && (nchar > maxsize)) { 158 if ((maxsize > 0) && (nchar > maxsize)) {
154 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG); 159 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG);
155 (void) snprintf(strbuf, sizeof strbuf, "%ld", maxsize); 160 (void) snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
156 ERR_add_error_data(2, "maxsize=", strbuf); 161 ERR_add_error_data(2, "maxsize=", strbuf);
@@ -158,7 +163,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
158 } 163 }
159 164
160 /* Now work out minimal type (if any) */ 165 /* Now work out minimal type (if any) */
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) { 166 if (traverse_string(in, len, inform, type_str, &mask) < 0) {
162 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS); 167 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS);
163 return -1; 168 return -1;
164 } 169 }
@@ -166,24 +171,28 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
166 171
167 /* Now work out output format and string type */ 172 /* Now work out output format and string type */
168 outform = MBSTRING_ASC; 173 outform = MBSTRING_ASC;
169 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING; 174 if (mask & B_ASN1_PRINTABLESTRING)
170 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING; 175 str_type = V_ASN1_PRINTABLESTRING;
171 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING; 176 else if (mask & B_ASN1_IA5STRING)
172 else if(mask & B_ASN1_BMPSTRING) { 177 str_type = V_ASN1_IA5STRING;
178 else if (mask & B_ASN1_T61STRING)
179 str_type = V_ASN1_T61STRING;
180 else if (mask & B_ASN1_BMPSTRING) {
173 str_type = V_ASN1_BMPSTRING; 181 str_type = V_ASN1_BMPSTRING;
174 outform = MBSTRING_BMP; 182 outform = MBSTRING_BMP;
175 } else if(mask & B_ASN1_UNIVERSALSTRING) { 183 } else if (mask & B_ASN1_UNIVERSALSTRING) {
176 str_type = V_ASN1_UNIVERSALSTRING; 184 str_type = V_ASN1_UNIVERSALSTRING;
177 outform = MBSTRING_UNIV; 185 outform = MBSTRING_UNIV;
178 } else { 186 } else {
179 str_type = V_ASN1_UTF8STRING; 187 str_type = V_ASN1_UTF8STRING;
180 outform = MBSTRING_UTF8; 188 outform = MBSTRING_UTF8;
181 } 189 }
182 if(!out) return str_type; 190 if (!out)
183 if(*out) { 191 return str_type;
192 if (*out) {
184 free_out = 0; 193 free_out = 0;
185 dest = *out; 194 dest = *out;
186 if(dest->data) { 195 if (dest->data) {
187 dest->length = 0; 196 dest->length = 0;
188 free(dest->data); 197 free(dest->data);
189 dest->data = NULL; 198 dest->data = NULL;
@@ -192,75 +201,78 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
192 } else { 201 } else {
193 free_out = 1; 202 free_out = 1;
194 dest = ASN1_STRING_type_new(str_type); 203 dest = ASN1_STRING_type_new(str_type);
195 if(!dest) { 204 if (!dest) {
196 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 205 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
197 ERR_R_MALLOC_FAILURE); 206 ERR_R_MALLOC_FAILURE);
198 return -1; 207 return -1;
199 } 208 }
200 *out = dest; 209 *out = dest;
201 } 210 }
202 /* If both the same type just copy across */ 211 /* If both the same type just copy across */
203 if(inform == outform) { 212 if (inform == outform) {
204 if(!ASN1_STRING_set(dest, in, len)) { 213 if (!ASN1_STRING_set(dest, in, len)) {
205 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 214 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
215 ERR_R_MALLOC_FAILURE);
206 return -1; 216 return -1;
207 } 217 }
208 return str_type; 218 return str_type;
209 } 219 }
210 220
211 /* Work out how much space the destination will need */ 221 /* Work out how much space the destination will need */
212 switch(outform) { 222 switch (outform) {
213 case MBSTRING_ASC: 223 case MBSTRING_ASC:
214 outlen = nchar; 224 outlen = nchar;
215 cpyfunc = cpy_asc; 225 cpyfunc = cpy_asc;
216 break; 226 break;
217 227
218 case MBSTRING_BMP: 228 case MBSTRING_BMP:
219 outlen = nchar << 1; 229 outlen = nchar << 1;
220 cpyfunc = cpy_bmp; 230 cpyfunc = cpy_bmp;
221 break; 231 break;
222 232
223 case MBSTRING_UNIV: 233 case MBSTRING_UNIV:
224 outlen = nchar << 2; 234 outlen = nchar << 2;
225 cpyfunc = cpy_univ; 235 cpyfunc = cpy_univ;
226 break; 236 break;
227 237
228 case MBSTRING_UTF8: 238 case MBSTRING_UTF8:
229 outlen = 0; 239 outlen = 0;
230 traverse_string(in, len, inform, out_utf8, &outlen); 240 traverse_string(in, len, inform, out_utf8, &outlen);
231 cpyfunc = cpy_utf8; 241 cpyfunc = cpy_utf8;
232 break; 242 break;
233 } 243 }
234 if(!(p = malloc(outlen + 1))) { 244 if (!(p = malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest); 245 if (free_out)
236 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 246 ASN1_STRING_free(dest);
247 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE);
237 return -1; 248 return -1;
238 } 249 }
239 dest->length = outlen; 250 dest->length = outlen;
240 dest->data = p; 251 dest->data = p;
241 p[outlen] = 0; 252 p[outlen] = 0;
242 traverse_string(in, len, inform, cpyfunc, &p); 253 traverse_string(in, len, inform, cpyfunc, &p);
243 return str_type; 254 return str_type;
244} 255}
245 256
246/* This function traverses a string and passes the value of each character 257/* This function traverses a string and passes the value of each character
247 * to an optional function along with a void * argument. 258 * to an optional function along with a void * argument.
248 */ 259 */
249 260
250static int traverse_string(const unsigned char *p, int len, int inform, 261static int
251 int (*rfunc)(unsigned long value, void *in), void *arg) 262traverse_string(const unsigned char *p, int len, int inform,
263 int (*rfunc)(unsigned long value, void *in), void *arg)
252{ 264{
253 unsigned long value; 265 unsigned long value;
254 int ret; 266 int ret;
255 while(len) { 267 while (len) {
256 if(inform == MBSTRING_ASC) { 268 if (inform == MBSTRING_ASC) {
257 value = *p++; 269 value = *p++;
258 len--; 270 len--;
259 } else if(inform == MBSTRING_BMP) { 271 } else if (inform == MBSTRING_BMP) {
260 value = *p++ << 8; 272 value = *p++ << 8;
261 value |= *p++; 273 value |= *p++;
262 len -= 2; 274 len -= 2;
263 } else if(inform == MBSTRING_UNIV) { 275 } else if (inform == MBSTRING_UNIV) {
264 value = ((unsigned long)*p++) << 24; 276 value = ((unsigned long)*p++) << 24;
265 value |= ((unsigned long)*p++) << 16; 277 value |= ((unsigned long)*p++) << 16;
266 value |= *p++ << 8; 278 value |= *p++ << 8;
@@ -268,13 +280,14 @@ static int traverse_string(const unsigned char *p, int len, int inform,
268 len -= 4; 280 len -= 4;
269 } else { 281 } else {
270 ret = UTF8_getc(p, len, &value); 282 ret = UTF8_getc(p, len, &value);
271 if(ret < 0) return -1; 283 if (ret < 0) return -1;
272 len -= ret; 284 len -= ret;
273 p += ret; 285 p += ret;
274 } 286 }
275 if(rfunc) { 287 if (rfunc) {
276 ret = rfunc(value, arg); 288 ret = rfunc(value, arg);
277 if(ret <= 0) return ret; 289 if (ret <= 0)
290 return ret;
278 } 291 }
279 } 292 }
280 return 1; 293 return 1;
@@ -284,7 +297,8 @@ static int traverse_string(const unsigned char *p, int len, int inform,
284 297
285/* Just count number of characters */ 298/* Just count number of characters */
286 299
287static int in_utf8(unsigned long value, void *arg) 300static int
301in_utf8(unsigned long value, void *arg)
288{ 302{
289 int *nchar; 303 int *nchar;
290 nchar = arg; 304 nchar = arg;
@@ -294,7 +308,8 @@ static int in_utf8(unsigned long value, void *arg)
294 308
295/* Determine size of output as a UTF8 String */ 309/* Determine size of output as a UTF8 String */
296 310
297static int out_utf8(unsigned long value, void *arg) 311static int
312out_utf8(unsigned long value, void *arg)
298{ 313{
299 int *outlen; 314 int *outlen;
300 outlen = arg; 315 outlen = arg;
@@ -306,28 +321,33 @@ static int out_utf8(unsigned long value, void *arg)
306 * supplied "mask". 321 * supplied "mask".
307 */ 322 */
308 323
309static int type_str(unsigned long value, void *arg) 324static int
325type_str(unsigned long value, void *arg)
310{ 326{
311 unsigned long types; 327 unsigned long types;
328
312 types = *((unsigned long *)arg); 329 types = *((unsigned long *)arg);
313 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) 330 if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
314 types &= ~B_ASN1_PRINTABLESTRING; 331 types &= ~B_ASN1_PRINTABLESTRING;
315 if((types & B_ASN1_IA5STRING) && (value > 127)) 332 if ((types & B_ASN1_IA5STRING) && (value > 127))
316 types &= ~B_ASN1_IA5STRING; 333 types &= ~B_ASN1_IA5STRING;
317 if((types & B_ASN1_T61STRING) && (value > 0xff)) 334 if ((types & B_ASN1_T61STRING) && (value > 0xff))
318 types &= ~B_ASN1_T61STRING; 335 types &= ~B_ASN1_T61STRING;
319 if((types & B_ASN1_BMPSTRING) && (value > 0xffff)) 336 if ((types & B_ASN1_BMPSTRING) && (value > 0xffff))
320 types &= ~B_ASN1_BMPSTRING; 337 types &= ~B_ASN1_BMPSTRING;
321 if(!types) return -1; 338 if (!types)
339 return -1;
322 *((unsigned long *)arg) = types; 340 *((unsigned long *)arg) = types;
323 return 1; 341 return 1;
324} 342}
325 343
326/* Copy one byte per character ASCII like strings */ 344/* Copy one byte per character ASCII like strings */
327 345
328static int cpy_asc(unsigned long value, void *arg) 346static int
347cpy_asc(unsigned long value, void *arg)
329{ 348{
330 unsigned char **p, *q; 349 unsigned char **p, *q;
350
331 p = arg; 351 p = arg;
332 q = *p; 352 q = *p;
333 *q = (unsigned char) value; 353 *q = (unsigned char) value;
@@ -337,9 +357,11 @@ static int cpy_asc(unsigned long value, void *arg)
337 357
338/* Copy two byte per character BMPStrings */ 358/* Copy two byte per character BMPStrings */
339 359
340static int cpy_bmp(unsigned long value, void *arg) 360static int
361cpy_bmp(unsigned long value, void *arg)
341{ 362{
342 unsigned char **p, *q; 363 unsigned char **p, *q;
364
343 p = arg; 365 p = arg;
344 q = *p; 366 q = *p;
345 *q++ = (unsigned char) ((value >> 8) & 0xff); 367 *q++ = (unsigned char) ((value >> 8) & 0xff);
@@ -350,9 +372,11 @@ static int cpy_bmp(unsigned long value, void *arg)
350 372
351/* Copy four byte per character UniversalStrings */ 373/* Copy four byte per character UniversalStrings */
352 374
353static int cpy_univ(unsigned long value, void *arg) 375static int
376cpy_univ(unsigned long value, void *arg)
354{ 377{
355 unsigned char **p, *q; 378 unsigned char **p, *q;
379
356 p = arg; 380 p = arg;
357 q = *p; 381 q = *p;
358 *q++ = (unsigned char) ((value >> 24) & 0xff); 382 *q++ = (unsigned char) ((value >> 24) & 0xff);
@@ -365,9 +389,11 @@ static int cpy_univ(unsigned long value, void *arg)
365 389
366/* Copy to a UTF8String */ 390/* Copy to a UTF8String */
367 391
368static int cpy_utf8(unsigned long value, void *arg) 392static int
393cpy_utf8(unsigned long value, void *arg)
369{ 394{
370 unsigned char **p; 395 unsigned char **p;
396
371 int ret; 397 int ret;
372 p = arg; 398 p = arg;
373 /* We already know there is enough room so pass 0xff as the length */ 399 /* We already know there is enough room so pass 0xff as the length */
@@ -377,17 +403,23 @@ static int cpy_utf8(unsigned long value, void *arg)
377} 403}
378 404
379/* Return 1 if the character is permitted in a PrintableString */ 405/* Return 1 if the character is permitted in a PrintableString */
380static int is_printable(unsigned long value) 406static int
407is_printable(unsigned long value)
381{ 408{
382 int ch; 409 int ch;
383 if(value > 0x7f) return 0; 410
384 ch = (int) value; 411 if (value > 0x7f) return 0;
385 /* Note: we can't use 'isalnum' because certain accented 412 ch = (int)value;
413 /* Note: we can't use 'isalnum' because certain accented
386 * characters may count as alphanumeric in some environments. 414 * characters may count as alphanumeric in some environments.
387 */ 415 */
388 if((ch >= 'a') && (ch <= 'z')) return 1; 416 if ((ch >= 'a') && (ch <= 'z'))
389 if((ch >= 'A') && (ch <= 'Z')) return 1; 417 return 1;
390 if((ch >= '0') && (ch <= '9')) return 1; 418 if ((ch >= 'A') && (ch <= 'Z'))
391 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; 419 return 1;
420 if ((ch >= '0') && (ch <= '9'))
421 return 1;
422 if ((ch == ' ') || strchr("'()+,-./:=?", ch))
423 return 1;
392 return 0; 424 return 0;
393} 425}
diff --git a/src/lib/libssl/src/crypto/asn1/a_object.c b/src/lib/libssl/src/crypto/asn1/a_object.c
index e73b1223de..293b269c21 100644
--- a/src/lib/libssl/src/crypto/asn1/a_object.c
+++ b/src/lib/libssl/src/crypto/asn1/a_object.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
@@ -64,28 +64,32 @@
64#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include <openssl/bn.h> 65#include <openssl/bn.h>
66 66
67int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) 67int
68i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
68{ 69{
69 unsigned char *p; 70 unsigned char *p;
70 int objsize; 71 int objsize;
71 72
72 if ((a == NULL) || (a->data == NULL)) return(0); 73 if ((a == NULL) || (a->data == NULL))
74 return (0);
73 75
74 objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); 76 objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
75 if (pp == NULL) return objsize; 77 if (pp == NULL)
78 return objsize;
76 79
77 p= *pp; 80 p = *pp;
78 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); 81 ASN1_put_object(&p, 0,a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
79 memcpy(p,a->data,a->length); 82 memcpy(p, a->data, a->length);
80 p+=a->length; 83 p += a->length;
81 84
82 *pp=p; 85 *pp = p;
83 return(objsize); 86 return (objsize);
84} 87}
85 88
86int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) 89int
90a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
87{ 91{
88 int i,first,len=0,c, use_bn; 92 int i, first, len = 0, c, use_bn;
89 char ftmp[24], *tmp = ftmp; 93 char ftmp[24], *tmp = ftmp;
90 int tmpsize = sizeof ftmp; 94 int tmpsize = sizeof ftmp;
91 const char *p; 95 const char *p;
@@ -93,42 +97,46 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
93 BIGNUM *bl = NULL; 97 BIGNUM *bl = NULL;
94 98
95 if (num == 0) 99 if (num == 0)
96 return(0); 100 return (0);
97 else if (num == -1) 101 else if (num == -1)
98 num=strlen(buf); 102 num = strlen(buf);
99 103
100 p=buf; 104 p = buf;
101 c= *(p++); 105 c = *(p++);
102 num--; 106 num--;
103 if ((c >= '0') && (c <= '2')) { 107 if ((c >= '0') && (c <= '2')) {
104 first= c-'0'; 108 first= c-'0';
105 } else { 109 } else {
106 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); 110 ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE);
107 goto err; 111 goto err;
108 } 112 }
109 113
110 if (num <= 0) { 114 if (num <= 0) {
111 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); 115 ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER);
112 goto err; 116 goto err;
113 } 117 }
114 c= *(p++); 118 c = *(p++);
115 num--; 119 num--;
116 for (;;) { 120 for (;;) {
117 if (num <= 0) break; 121 if (num <= 0)
122 break;
118 if ((c != '.') && (c != ' ')) { 123 if ((c != '.') && (c != ' ')) {
119 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); 124 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
125 ASN1_R_INVALID_SEPARATOR);
120 goto err; 126 goto err;
121 } 127 }
122 l=0; 128 l = 0;
123 use_bn = 0; 129 use_bn = 0;
124 for (;;) { 130 for (;;) {
125 if (num <= 0) break; 131 if (num <= 0)
132 break;
126 num--; 133 num--;
127 c= *(p++); 134 c = *(p++);
128 if ((c == ' ') || (c == '.')) 135 if ((c == ' ') || (c == '.'))
129 break; 136 break;
130 if ((c < '0') || (c > '9')) { 137 if ((c < '0') || (c > '9')) {
131 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); 138 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
139 ASN1_R_INVALID_DIGIT);
132 goto err; 140 goto err;
133 } 141 }
134 if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { 142 if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
@@ -139,30 +147,29 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
139 goto err; 147 goto err;
140 } 148 }
141 if (use_bn) { 149 if (use_bn) {
142 if (!BN_mul_word(bl, 10L) 150 if (!BN_mul_word(bl, 10L) ||
143 || !BN_add_word(bl, c-'0')) 151 !BN_add_word(bl, c-'0'))
144 goto err; 152 goto err;
145 } 153 } else
146 else 154 l = l * 10L + (long)(c - '0');
147 l=l*10L+(long)(c-'0');
148 } 155 }
149 if (len == 0) { 156 if (len == 0) {
150 if ((first < 2) && (l >= 40)) { 157 if ((first < 2) && (l >= 40)) {
151 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); 158 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
159 ASN1_R_SECOND_NUMBER_TOO_LARGE);
152 goto err; 160 goto err;
153 } 161 }
154 if (use_bn) { 162 if (use_bn) {
155 if (!BN_add_word(bl, first * 40)) 163 if (!BN_add_word(bl, first * 40))
156 goto err; 164 goto err;
157 } 165 } else
158 else 166 l += (long)first * 40;
159 l+=(long)first*40;
160 } 167 }
161 i=0; 168 i = 0;
162 if (use_bn) { 169 if (use_bn) {
163 int blsize; 170 int blsize;
164 blsize = BN_num_bits(bl); 171 blsize = BN_num_bits(bl);
165 blsize = (blsize + 6)/7; 172 blsize = (blsize + 6) / 7;
166 if (blsize > tmpsize) { 173 if (blsize > tmpsize) {
167 if (tmp != ftmp) 174 if (tmp != ftmp)
168 free(tmp); 175 free(tmp);
@@ -171,108 +178,118 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
171 if (!tmp) 178 if (!tmp)
172 goto err; 179 goto err;
173 } 180 }
174 while(blsize--) 181 while (blsize--)
175 tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); 182 tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
176 } else { 183 } else {
177 184
178 for (;;) { 185 for (;;) {
179 tmp[i++]=(unsigned char)l&0x7f; 186 tmp[i++] = (unsigned char)l & 0x7f;
180 l>>=7L; 187 l >>= 7L;
181 if (l == 0L) break; 188 if (l == 0L)
189 break;
182 } 190 }
183 191
184 } 192 }
185 if (out != NULL) { 193 if (out != NULL) {
186 if (len+i > olen) { 194 if (len + i > olen) {
187 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); 195 ASN1err(ASN1_F_A2D_ASN1_OBJECT,
196 ASN1_R_BUFFER_TOO_SMALL);
188 goto err; 197 goto err;
189 } 198 }
190 while (--i > 0) 199 while (--i > 0)
191 out[len++]=tmp[i]|0x80; 200 out[len++] = tmp[i]|0x80;
192 out[len++]=tmp[0]; 201 out[len++] = tmp[0];
193 } 202 } else
194 else 203 len += i;
195 len+=i;
196 } 204 }
197 if (tmp != ftmp) 205 if (tmp != ftmp)
198 free(tmp); 206 free(tmp);
199 if (bl) 207 if (bl)
200 BN_free(bl); 208 BN_free(bl);
201 return(len); 209 return (len);
210
202err: 211err:
203 if (tmp != ftmp) 212 if (tmp != ftmp)
204 free(tmp); 213 free(tmp);
205 if (bl) 214 if (bl)
206 BN_free(bl); 215 BN_free(bl);
207 return(0); 216 return (0);
208} 217}
209 218
210int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) 219int
220i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
211{ 221{
212 return OBJ_obj2txt(buf, buf_len, a, 0); 222 return OBJ_obj2txt(buf, buf_len, a, 0);
213} 223}
214 224
215int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) 225int
226i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
216{ 227{
217 char buf[80], *p = buf; 228 char buf[80], *p = buf;
218 int i; 229 int i;
219 230
220 if ((a == NULL) || (a->data == NULL)) 231 if ((a == NULL) || (a->data == NULL))
221 return(BIO_write(bp,"NULL",4)); 232 return(BIO_write(bp, "NULL",4));
222 i=i2t_ASN1_OBJECT(buf,sizeof buf,a); 233 i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
223 if (i > (int)(sizeof(buf) - 1)) { 234 if (i > (int)(sizeof(buf) - 1)) {
224 p = malloc(i + 1); 235 p = malloc(i + 1);
225 if (!p) 236 if (!p)
226 return -1; 237 return -1;
227 i2t_ASN1_OBJECT(p,i + 1,a); 238 i2t_ASN1_OBJECT(p, i + 1, a);
228 } 239 }
229 if (i <= 0) 240 if (i <= 0)
230 return BIO_write(bp, "<INVALID>", 9); 241 return BIO_write(bp, "<INVALID>", 9);
231 BIO_write(bp,p,i); 242 BIO_write(bp, p, i);
232 if (p != buf) 243 if (p != buf)
233 free(p); 244 free(p);
234 return(i); 245 return (i);
235} 246}
236 247
237ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, 248ASN1_OBJECT *
238 long length) 249d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length)
239{ 250{
240 const unsigned char *p; 251 const unsigned char *p;
241 long len; 252 long len;
242 int tag,xclass; 253 int tag, xclass;
243 int inf,i; 254 int inf, i;
244 ASN1_OBJECT *ret = NULL; 255 ASN1_OBJECT *ret = NULL;
245 p= *pp; 256
246 inf=ASN1_get_object(&p,&len,&tag,&xclass,length); 257 p = *pp;
258 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
247 if (inf & 0x80) { 259 if (inf & 0x80) {
248 i=ASN1_R_BAD_OBJECT_HEADER; 260 i = ASN1_R_BAD_OBJECT_HEADER;
249 goto err; 261 goto err;
250 } 262 }
251 263
252 if (tag != V_ASN1_OBJECT) { 264 if (tag != V_ASN1_OBJECT) {
253 i=ASN1_R_EXPECTING_AN_OBJECT; 265 i = ASN1_R_EXPECTING_AN_OBJECT;
254 goto err; 266 goto err;
255 } 267 }
256 ret = c2i_ASN1_OBJECT(a, &p, len); 268 ret = c2i_ASN1_OBJECT(a, &p, len);
257 if(ret) *pp = p; 269 if (ret)
270 *pp = p;
258 return ret; 271 return ret;
272
259err: 273err:
260 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); 274 ASN1err(ASN1_F_D2I_ASN1_OBJECT, i);
261 return(NULL); 275 return (NULL);
262} 276}
263ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, 277
264 long len) 278ASN1_OBJECT *
279c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
265{ 280{
266 ASN1_OBJECT *ret=NULL; 281 ASN1_OBJECT *ret = NULL;
267 const unsigned char *p; 282 const unsigned char *p;
268 unsigned char *data; 283 unsigned char *data;
269 int i; 284 int i;
285
270 /* Sanity check OID encoding: can't have leading 0x80 in 286 /* Sanity check OID encoding: can't have leading 0x80 in
271 * subidentifiers, see: X.690 8.19.2 287 * subidentifiers, see: X.690 8.19.2
272 */ 288 */
273 for (i = 0, p = *pp; i < len; i++, p++) { 289 for (i = 0, p = *pp; i < len; i++, p++) {
274 if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { 290 if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
275 ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); 291 ASN1err(ASN1_F_C2I_ASN1_OBJECT,
292 ASN1_R_INVALID_OBJECT_ENCODING);
276 return NULL; 293 return NULL;
277 } 294 }
278 } 295 }
@@ -280,92 +297,106 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
280 /* only the ASN1_OBJECTs from the 'table' will have values 297 /* only the ASN1_OBJECTs from the 'table' will have values
281 * for ->sn or ->ln */ 298 * for ->sn or ->ln */
282 if ((a == NULL) || ((*a) == NULL) || 299 if ((a == NULL) || ((*a) == NULL) ||
283 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { 300 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
284 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); 301 if ((ret = ASN1_OBJECT_new()) == NULL)
285 } 302 return (NULL);
286 else ret=(*a); 303 } else
304 ret = (*a);
287 305
288 p= *pp; 306 p = *pp;
289 /* detach data from object */ 307 /* detach data from object */
290 data = (unsigned char *)ret->data; 308 data = (unsigned char *)ret->data;
291 ret->data = NULL; 309 ret->data = NULL;
292 /* once detached we can change it */ 310 /* once detached we can change it */
293 if ((data == NULL) || (ret->length < len)) { 311 if ((data == NULL) || (ret->length < len)) {
294 ret->length=0; 312 ret->length = 0;
295 if (data != NULL) free(data); 313 if (data != NULL)
296 data=(unsigned char *)malloc(len ? (int)len : 1); 314 free(data);
297 if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } 315 data = (unsigned char *)malloc(len ? (int)len : 1);
298 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; 316 if (data == NULL) {
317 i = ERR_R_MALLOC_FAILURE;
318 goto err;
319 }
320 ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
299 } 321 }
300 memcpy(data,p,(int)len); 322 memcpy(data, p, (int)len);
301 /* reattach data to object, after which it remains const */ 323 /* reattach data to object, after which it remains const */
302 ret->data =data; 324 ret->data = data;
303 ret->length=(int)len; 325 ret->length = (int)len;
304 ret->sn=NULL; 326 ret->sn = NULL;
305 ret->ln=NULL; 327 ret->ln = NULL;
306 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ 328 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
307 p+=len; 329 p += len;
330
331 if (a != NULL)
332 (*a) = ret;
333 *pp = p;
334 return (ret);
308 335
309 if (a != NULL) (*a)=ret;
310 *pp=p;
311 return(ret);
312err: 336err:
313 ASN1err(ASN1_F_C2I_ASN1_OBJECT,i); 337 ASN1err(ASN1_F_C2I_ASN1_OBJECT, i);
314 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 338 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
315 ASN1_OBJECT_free(ret); 339 ASN1_OBJECT_free(ret);
316 return(NULL); 340 return (NULL);
317} 341}
318 342
319ASN1_OBJECT *ASN1_OBJECT_new(void) 343ASN1_OBJECT *
344ASN1_OBJECT_new(void)
320{ 345{
321 ASN1_OBJECT *ret; 346 ASN1_OBJECT *ret;
322 347
323 ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); 348 ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
324 if (ret == NULL) { 349 if (ret == NULL) {
325 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); 350 ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
326 return(NULL); 351 return (NULL);
327 } 352 }
328 ret->length=0; 353 ret->length = 0;
329 ret->data=NULL; 354 ret->data = NULL;
330 ret->nid=0; 355 ret->nid = 0;
331 ret->sn=NULL; 356 ret->sn = NULL;
332 ret->ln=NULL; 357 ret->ln = NULL;
333 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; 358 ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
334 return(ret); 359 return (ret);
335} 360}
336 361
337void ASN1_OBJECT_free(ASN1_OBJECT *a) 362void
363ASN1_OBJECT_free(ASN1_OBJECT *a)
338{ 364{
339 if (a == NULL) return; 365 if (a == NULL)
366 return;
340 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) { 367 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
341#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ 368#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
342 if (a->sn != NULL) free((void *)a->sn); 369 if (a->sn != NULL)
343 if (a->ln != NULL) free((void *)a->ln); 370 free((void *)a->sn);
371 if (a->ln != NULL)
372 free((void *)a->ln);
344#endif 373#endif
345 a->sn=a->ln=NULL; 374 a->sn = a->ln = NULL;
346 } 375 }
347 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { 376 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
348 if (a->data != NULL) free((void *)a->data); 377 if (a->data != NULL)
349 a->data=NULL; 378 free((void *)a->data);
350 a->length=0; 379 a->data = NULL;
380 a->length = 0;
351 } 381 }
352 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) 382 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
353 free(a); 383 free(a);
354} 384}
355 385
356ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, 386ASN1_OBJECT *
357 const char *sn, const char *ln) 387ASN1_OBJECT_create(int nid, unsigned char *data, int len,
388 const char *sn, const char *ln)
358{ 389{
359 ASN1_OBJECT o; 390 ASN1_OBJECT o;
360 391
361 o.sn=sn; 392 o.sn = sn;
362 o.ln=ln; 393 o.ln = ln;
363 o.data=data; 394 o.data = data;
364 o.nid=nid; 395 o.nid = nid;
365 o.length=len; 396 o.length = len;
366 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 397 o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
367 ASN1_OBJECT_FLAG_DYNAMIC_DATA; 398 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
368 return(OBJ_dup(&o)); 399 return (OBJ_dup(&o));
369} 400}
370 401
371IMPLEMENT_STACK_OF(ASN1_OBJECT) 402IMPLEMENT_STACK_OF(ASN1_OBJECT)
diff --git a/src/lib/libssl/src/crypto/asn1/a_octet.c b/src/lib/libssl/src/crypto/asn1/a_octet.c
index e8725e44f1..74f849cf12 100644
--- a/src/lib/libssl/src/crypto/asn1/a_octet.c
+++ b/src/lib/libssl/src/crypto/asn1/a_octet.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
@@ -60,12 +60,20 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) 63ASN1_OCTET_STRING *
64{ return M_ASN1_OCTET_STRING_dup(x); } 64ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
65 65{
66int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b) 66 return M_ASN1_OCTET_STRING_dup(x);
67{ return M_ASN1_OCTET_STRING_cmp(a, b); } 67}
68 68
69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len) 69int
70{ return M_ASN1_OCTET_STRING_set(x, d, len); } 70ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
71{
72 return M_ASN1_OCTET_STRING_cmp(a, b);
73}
71 74
75int
76ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
77{
78 return M_ASN1_OCTET_STRING_set(x, d, len);
79}
diff --git a/src/lib/libssl/src/crypto/asn1/a_print.c b/src/lib/libssl/src/crypto/asn1/a_print.c
index 9e421dba66..3e9a7c0f40 100644
--- a/src/lib/libssl/src/crypto/asn1/a_print.c
+++ b/src/lib/libssl/src/crypto/asn1/a_print.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
@@ -60,57 +60,66 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63int ASN1_PRINTABLE_type(const unsigned char *s, int len) 63int
64ASN1_PRINTABLE_type(const unsigned char *s, int len)
64{ 65{
65 int c; 66 int c;
66 int ia5=0; 67 int ia5 = 0;
67 int t61=0; 68 int t61 = 0;
68 69
69 if (len <= 0) len= -1; 70 if (len <= 0)
70 if (s == NULL) return(V_ASN1_PRINTABLESTRING); 71 len = -1;
72 if (s == NULL)
73 return (V_ASN1_PRINTABLESTRING);
71 74
72 while ((*s) && (len-- != 0)) { 75 while ((*s) && (len-- != 0)) {
73 c= *(s++); 76 c= *(s++);
74 if (!( ((c >= 'a') && (c <= 'z')) || 77 if (!(((c >= 'a') && (c <= 'z')) ||
75 ((c >= 'A') && (c <= 'Z')) || 78 ((c >= 'A') && (c <= 'Z')) ||
76 (c == ' ') || 79 (c == ' ') ||
77 ((c >= '0') && (c <= '9')) || 80 ((c >= '0') && (c <= '9')) ||
78 (c == ' ') || (c == '\'') || 81 (c == ' ') || (c == '\'') ||
79 (c == '(') || (c == ')') || 82 (c == '(') || (c == ')') ||
80 (c == '+') || (c == ',') || 83 (c == '+') || (c == ',') ||
81 (c == '-') || (c == '.') || 84 (c == '-') || (c == '.') ||
82 (c == '/') || (c == ':') || 85 (c == '/') || (c == ':') ||
83 (c == '=') || (c == '?'))) 86 (c == '=') || (c == '?')))
84 ia5=1; 87 ia5 = 1;
85 if (c&0x80) 88 if (c & 0x80)
86 t61=1; 89 t61 = 1;
87 } 90 }
88 if (t61) return(V_ASN1_T61STRING); 91 if (t61)
89 if (ia5) return(V_ASN1_IA5STRING); 92 return (V_ASN1_T61STRING);
90 return(V_ASN1_PRINTABLESTRING); 93 if (ia5)
94 return (V_ASN1_IA5STRING);
95 return (V_ASN1_PRINTABLESTRING);
91} 96}
92 97
93int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) 98int
99ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
94{ 100{
95 int i; 101 int i;
96 unsigned char *p; 102 unsigned char *p;
97 103
98 if (s->type != V_ASN1_UNIVERSALSTRING) return(0); 104 if (s->type != V_ASN1_UNIVERSALSTRING)
99 if ((s->length%4) != 0) return(0); 105 return (0);
100 p=s->data; 106 if ((s->length % 4) != 0)
101 for (i=0; i<s->length; i+=4) { 107 return (0);
108 p = s->data;
109 for (i = 0; i < s->length; i += 4) {
102 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) 110 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
103 break; 111 break;
104 else 112 else
105 p+=4; 113 p += 4;
106 } 114 }
107 if (i < s->length) return(0); 115 if (i < s->length)
108 p=s->data; 116 return (0);
109 for (i=3; i<s->length; i+=4) { 117 p = s->data;
110 *(p++)=s->data[i]; 118 for (i = 3; i < s->length; i += 4) {
119 *(p++) = s->data[i];
111 } 120 }
112 *(p)='\0'; 121 *(p) = '\0';
113 s->length/=4; 122 s->length /= 4;
114 s->type=ASN1_PRINTABLE_type(s->data,s->length); 123 s->type = ASN1_PRINTABLE_type(s->data, s->length);
115 return(1); 124 return (1);
116} 125}