summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/evp_asn1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/evp_asn1.c')
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c164
1 files changed, 88 insertions, 76 deletions
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
index d4ea675f89..4ff03de1f9 100644
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ b/src/lib/libcrypto/asn1/evp_asn1.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -61,84 +61,91 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h> 62#include <openssl/asn1_mac.h>
63 63
64int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) 64int
65ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
65{ 66{
66 ASN1_STRING *os; 67 ASN1_STRING *os;
67 68
68 if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); 69 if ((os = M_ASN1_OCTET_STRING_new()) == NULL)
69 if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); 70 return (0);
70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); 71 if (!M_ASN1_OCTET_STRING_set(os, data, len))
71 return(1); 72 return (0);
73 ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os);
74 return (1);
72} 75}
73 76
74/* int max_len: for returned value */ 77/* int max_len: for returned value */
75int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, 78int
76 int max_len) 79ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len)
77{ 80{
78 int ret,num; 81 int ret, num;
79 unsigned char *p; 82 unsigned char *p;
80 83
81 if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { 84 if ((a->type != V_ASN1_OCTET_STRING) ||
82 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); 85 (a->value.octet_string == NULL)) {
83 return(-1); 86 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG);
87 return (-1);
84 } 88 }
85 p=M_ASN1_STRING_data(a->value.octet_string); 89 p = M_ASN1_STRING_data(a->value.octet_string);
86 ret=M_ASN1_STRING_length(a->value.octet_string); 90 ret = M_ASN1_STRING_length(a->value.octet_string);
87 if (ret < max_len) 91 if (ret < max_len)
88 num=ret; 92 num = ret;
89 else 93 else
90 num=max_len; 94 num = max_len;
91 memcpy(data,p,num); 95 memcpy(data, p, num);
92 return(ret); 96 return (ret);
93} 97}
94 98
95int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, 99int
96 int len) 100ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
101 int len)
97{ 102{
98 int n,size; 103 int n, size;
99 ASN1_OCTET_STRING os,*osp; 104 ASN1_OCTET_STRING os, *osp;
100 ASN1_INTEGER in; 105 ASN1_INTEGER in;
101 unsigned char *p; 106 unsigned char *p;
102 unsigned char buf[32]; /* when they have 256bit longs, 107 unsigned char buf[32]; /* when they have 256bit longs,
103 * I'll be in trouble */ 108 * I'll be in trouble */
104 in.data=buf; 109 in.data = buf;
105 in.length=32; 110 in.length = 32;
106 os.data=data; 111 os.data = data;
107 os.type=V_ASN1_OCTET_STRING; 112 os.type = V_ASN1_OCTET_STRING;
108 os.length=len; 113 os.length = len;
109 ASN1_INTEGER_set(&in,num); 114 ASN1_INTEGER_set(&in, num);
110 n = i2d_ASN1_INTEGER(&in,NULL); 115 n = i2d_ASN1_INTEGER(&in, NULL);
111 n+=M_i2d_ASN1_OCTET_STRING(&os,NULL); 116 n += M_i2d_ASN1_OCTET_STRING(&os, NULL);
112 117
113 size=ASN1_object_size(1,n,V_ASN1_SEQUENCE); 118 size = ASN1_object_size(1, n, V_ASN1_SEQUENCE);
114 119
115 if ((osp=ASN1_STRING_new()) == NULL) return(0); 120 if ((osp = ASN1_STRING_new()) == NULL)
121 return (0);
116 /* Grow the 'string' */ 122 /* Grow the 'string' */
117 if (!ASN1_STRING_set(osp,NULL,size)) { 123 if (!ASN1_STRING_set(osp, NULL, size)) {
118 ASN1_STRING_free(osp); 124 ASN1_STRING_free(osp);
119 return(0); 125 return (0);
120 } 126 }
121 127
122 M_ASN1_STRING_length_set(osp, size); 128 M_ASN1_STRING_length_set(osp, size);
123 p=M_ASN1_STRING_data(osp); 129 p = M_ASN1_STRING_data(osp);
124 130
125 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 131 ASN1_put_object(&p, 1,n, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
126 i2d_ASN1_INTEGER(&in,&p); 132 i2d_ASN1_INTEGER(&in, &p);
127 M_i2d_ASN1_OCTET_STRING(&os,&p); 133 M_i2d_ASN1_OCTET_STRING(&os, &p);
128 134
129 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); 135 ASN1_TYPE_set(a, V_ASN1_SEQUENCE, osp);
130 return(1); 136 return (1);
131} 137}
132 138
133/* we return the actual length..., num may be missing, in which 139/* we return the actual length..., num may be missing, in which
134 * case, set it to zero */ 140 * case, set it to zero */
135/* int max_len: for returned value */ 141/* int max_len: for returned value */
136int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, 142int
137 int max_len) 143ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
144 int max_len)
138{ 145{
139 int ret= -1,n; 146 int ret = -1, n;
140 ASN1_INTEGER *ai=NULL; 147 ASN1_INTEGER *ai = NULL;
141 ASN1_OCTET_STRING *os=NULL; 148 ASN1_OCTET_STRING *os = NULL;
142 const unsigned char *p; 149 const unsigned char *p;
143 long length; 150 long length;
144 ASN1_const_CTX c; 151 ASN1_const_CTX c;
@@ -146,40 +153,45 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
146 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { 153 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) {
147 goto err; 154 goto err;
148 } 155 }
149 p=M_ASN1_STRING_data(a->value.sequence); 156 p = M_ASN1_STRING_data(a->value.sequence);
150 length=M_ASN1_STRING_length(a->value.sequence); 157 length = M_ASN1_STRING_length(a->value.sequence);
151 158
152 c.pp= &p; 159 c.pp = &p;
153 c.p=p; 160 c.p = p;
154 c.max=p+length; 161 c.max = p + length;
155 c.error=ASN1_R_DATA_IS_WRONG; 162 c.error = ASN1_R_DATA_IS_WRONG;
156 163
157 M_ASN1_D2I_start_sequence(); 164 M_ASN1_D2I_start_sequence();
158 c.q=c.p; 165 c.q = c.p;
159 if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; 166 if ((ai = d2i_ASN1_INTEGER(NULL, &c.p, c.slen)) == NULL)
160 c.slen-=(c.p-c.q); 167 goto err;
161 c.q=c.p; 168 c.slen -= (c.p - c.q);
162 if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; 169 c.q = c.p;
163 c.slen-=(c.p-c.q); 170 if ((os = d2i_ASN1_OCTET_STRING(NULL, &c.p, c.slen)) == NULL)
164 if (!M_ASN1_D2I_end_sequence()) goto err; 171 goto err;
172 c.slen -= (c.p - c.q);
173 if (!M_ASN1_D2I_end_sequence())
174 goto err;
165 175
166 if (num != NULL) 176 if (num != NULL)
167 *num=ASN1_INTEGER_get(ai); 177 *num = ASN1_INTEGER_get(ai);
168 178
169 ret=M_ASN1_STRING_length(os); 179 ret = M_ASN1_STRING_length(os);
170 if (max_len > ret) 180 if (max_len > ret)
171 n=ret; 181 n = ret;
172 else 182 else
173 n=max_len; 183 n = max_len;
174 184
175 if (data != NULL) 185 if (data != NULL)
176 memcpy(data,M_ASN1_STRING_data(os),n); 186 memcpy(data, M_ASN1_STRING_data(os), n);
177 if (0) { 187 if (0) {
178err: 188err:
179 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); 189 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,
190 ASN1_R_DATA_IS_WRONG);
180 } 191 }
181 if (os != NULL) M_ASN1_OCTET_STRING_free(os); 192 if (os != NULL)
182 if (ai != NULL) M_ASN1_INTEGER_free(ai); 193 M_ASN1_OCTET_STRING_free(os);
183 return(ret); 194 if (ai != NULL)
195 M_ASN1_INTEGER_free(ai);
196 return (ret);
184} 197}
185