summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_bytes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_bytes.c')
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c78
1 files changed, 22 insertions, 56 deletions
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
index 14168d61ad..bb88660f58 100644
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -58,38 +58,13 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); 63static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
64 * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK); 64/* type is a 'bitmap' of acceptable string types.
65 * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE);
66 * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG);
67 */ 65 */
68 66ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
69static unsigned long tag2bit[32]={ 67 long length, int type)
700, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
71B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
72B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
73B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */
740, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING,
75B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
760,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,
77B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN,
78 };
79
80#ifndef NOPROTO
81static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c);
82#else
83static int asn1_collate_primative();
84#endif
85
86/* type is a 'bitmap' of acceptable string types to be accepted.
87 */
88ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type)
89ASN1_STRING **a;
90unsigned char **pp;
91long length;
92int type;
93 { 68 {
94 ASN1_STRING *ret=NULL; 69 ASN1_STRING *ret=NULL;
95 unsigned char *p,*s; 70 unsigned char *p,*s;
@@ -106,7 +81,7 @@ int type;
106 i=ASN1_R_TAG_VALUE_TOO_HIGH;; 81 i=ASN1_R_TAG_VALUE_TOO_HIGH;;
107 goto err; 82 goto err;
108 } 83 }
109 if (!(tag2bit[tag] & type)) 84 if (!(ASN1_tag2bit(tag) & type))
110 { 85 {
111 i=ASN1_R_WRONG_TYPE; 86 i=ASN1_R_WRONG_TYPE;
112 goto err; 87 goto err;
@@ -125,7 +100,7 @@ int type;
125 100
126 if (len != 0) 101 if (len != 0)
127 { 102 {
128 s=(unsigned char *)Malloc((int)len+1); 103 s=(unsigned char *)OPENSSL_malloc((int)len+1);
129 if (s == NULL) 104 if (s == NULL)
130 { 105 {
131 i=ERR_R_MALLOC_FAILURE; 106 i=ERR_R_MALLOC_FAILURE;
@@ -138,7 +113,7 @@ int type;
138 else 113 else
139 s=NULL; 114 s=NULL;
140 115
141 if (ret->data != NULL) Free((char *)ret->data); 116 if (ret->data != NULL) OPENSSL_free(ret->data);
142 ret->length=(int)len; 117 ret->length=(int)len;
143 ret->data=s; 118 ret->data=s;
144 ret->type=tag; 119 ret->type=tag;
@@ -152,11 +127,7 @@ err:
152 return(NULL); 127 return(NULL);
153 } 128 }
154 129
155int i2d_ASN1_bytes(a, pp, tag, xclass) 130int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
156ASN1_STRING *a;
157unsigned char **pp;
158int tag;
159int xclass;
160 { 131 {
161 int ret,r,constructed; 132 int ret,r,constructed;
162 unsigned char *p; 133 unsigned char *p;
@@ -182,12 +153,8 @@ int xclass;
182 return(r); 153 return(r);
183 } 154 }
184 155
185ASN1_STRING *d2i_ASN1_bytes(a, pp, length, Ptag, Pclass) 156ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
186ASN1_STRING **a; 157 int Ptag, int Pclass)
187unsigned char **pp;
188long length;
189int Ptag;
190int Pclass;
191 { 158 {
192 ASN1_STRING *ret=NULL; 159 ASN1_STRING *ret=NULL;
193 unsigned char *p,*s; 160 unsigned char *p,*s;
@@ -227,7 +194,7 @@ int Pclass;
227 c.tag=Ptag; 194 c.tag=Ptag;
228 c.xclass=Pclass; 195 c.xclass=Pclass;
229 c.max=(length == 0)?0:(p+length); 196 c.max=(length == 0)?0:(p+length);
230 if (!asn1_collate_primative(ret,&c)) 197 if (!asn1_collate_primitive(ret,&c))
231 goto err; 198 goto err;
232 else 199 else
233 { 200 {
@@ -240,8 +207,8 @@ int Pclass;
240 { 207 {
241 if ((ret->length < len) || (ret->data == NULL)) 208 if ((ret->length < len) || (ret->data == NULL))
242 { 209 {
243 if (ret->data != NULL) Free((char *)ret->data); 210 if (ret->data != NULL) OPENSSL_free(ret->data);
244 s=(unsigned char *)Malloc((int)len); 211 s=(unsigned char *)OPENSSL_malloc((int)len + 1);
245 if (s == NULL) 212 if (s == NULL)
246 { 213 {
247 i=ERR_R_MALLOC_FAILURE; 214 i=ERR_R_MALLOC_FAILURE;
@@ -251,12 +218,13 @@ int Pclass;
251 else 218 else
252 s=ret->data; 219 s=ret->data;
253 memcpy(s,p,(int)len); 220 memcpy(s,p,(int)len);
221 s[len] = '\0';
254 p+=len; 222 p+=len;
255 } 223 }
256 else 224 else
257 { 225 {
258 s=NULL; 226 s=NULL;
259 if (ret->data != NULL) Free((char *)ret->data); 227 if (ret->data != NULL) OPENSSL_free(ret->data);
260 } 228 }
261 229
262 ret->length=(int)len; 230 ret->length=(int)len;
@@ -275,13 +243,11 @@ err:
275 } 243 }
276 244
277 245
278/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapes 246/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
279 * them into the one struture that is then returned */ 247 * them into the one structure that is then returned */
280/* There have been a few bug fixes for this function from 248/* There have been a few bug fixes for this function from
281 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ 249 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
282static int asn1_collate_primative(a,c) 250static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
283ASN1_STRING *a;
284ASN1_CTX *c;
285 { 251 {
286 ASN1_STRING *os=NULL; 252 ASN1_STRING *os=NULL;
287 BUF_MEM b; 253 BUF_MEM b;
@@ -333,14 +299,14 @@ ASN1_CTX *c;
333 if (!asn1_Finish(c)) goto err; 299 if (!asn1_Finish(c)) goto err;
334 300
335 a->length=num; 301 a->length=num;
336 if (a->data != NULL) Free(a->data); 302 if (a->data != NULL) OPENSSL_free(a->data);
337 a->data=(unsigned char *)b.data; 303 a->data=(unsigned char *)b.data;
338 if (os != NULL) ASN1_STRING_free(os); 304 if (os != NULL) ASN1_STRING_free(os);
339 return(1); 305 return(1);
340err: 306err:
341 ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,c->error); 307 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
342 if (os != NULL) ASN1_STRING_free(os); 308 if (os != NULL) ASN1_STRING_free(os);
343 if (b.data != NULL) Free(b.data); 309 if (b.data != NULL) OPENSSL_free(b.data);
344 return(0); 310 return(0);
345 } 311 }
346 312