From 7068f99b4dee7dbed48db26ef25d16c7e6a65978 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 25 Sep 2012 21:16:39 +0200 Subject: [PATCH] Updated to minitasn1 3.0 --- lib/minitasn1/Makefile.am | 2 +- lib/minitasn1/coding.c | 20 ++-- lib/minitasn1/decoding.c | 31 ++++-- lib/minitasn1/element.c | 42 ++++---- lib/minitasn1/errors.c | 41 -------- lib/minitasn1/gstr.c | 11 ++- lib/minitasn1/gstr.h | 2 +- lib/minitasn1/hash.c | 235 +++++++++++++++++++++++++++++++++++++++++++++ lib/minitasn1/int.h | 9 +- lib/minitasn1/libtasn1.h | 56 +---------- lib/minitasn1/parser_aux.c | 203 +++++++++++++++------------------------ lib/minitasn1/parser_aux.h | 101 ++++++++++++++++--- lib/minitasn1/structure.c | 81 +++++++--------- lib/minitasn1/structure.h | 2 +- 14 files changed, 504 insertions(+), 332 deletions(-) create mode 100644 lib/minitasn1/hash.c diff --git a/lib/minitasn1/Makefile.am b/lib/minitasn1/Makefile.am index 7de6a75b1..dc26f1f4a 100644 --- a/lib/minitasn1/Makefile.am +++ b/lib/minitasn1/Makefile.am @@ -29,4 +29,4 @@ noinst_LTLIBRARIES = libminitasn1.la libminitasn1_la_SOURCES = libtasn1.h gstr.h int.h parser_aux.h \ structure.h element.h decoding.c gstr.c errors.c parser_aux.c \ - structure.c element.c coding.c version.c + structure.c element.c coding.c version.c hash.c diff --git a/lib/minitasn1/coding.c b/lib/minitasn1/coding.c index 307dd40d2..11f8f4828 100644 --- a/lib/minitasn1/coding.c +++ b/lib/minitasn1/coding.c @@ -260,7 +260,7 @@ _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len) max_len = *der_len; - temp = _asn1_malloc (str_len + 2); + temp = malloc (str_len + 2); if (temp == NULL) return ASN1_MEM_ALLOC_ERROR; @@ -313,7 +313,7 @@ _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len) } *der_len += len_len; - _asn1_free (temp); + free (temp); if (max_len < (*der_len)) return ASN1_MEM_ERROR; @@ -638,7 +638,7 @@ _asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) first = last = NULL; while (p) { - p_vet = (struct vet *) _asn1_malloc (sizeof (struct vet)); + p_vet = malloc (sizeof (struct vet)); if (p_vet == NULL) return; @@ -679,7 +679,7 @@ _asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) if (p_vet->value > p2_vet->value) { /* change position */ - temp = (unsigned char *) _asn1_malloc (p_vet->end - counter); + temp = malloc (p_vet->end - counter); if (temp == NULL) return; @@ -688,7 +688,7 @@ _asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) p2_vet->end - p_vet->end); memcpy (der + counter + p2_vet->end - p_vet->end, temp, p_vet->end - counter); - _asn1_free (temp); + free (temp); tag = p_vet->value; p_vet->value = p2_vet->value; @@ -706,7 +706,7 @@ _asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node) p_vet->prev->next = NULL; else first = NULL; - _asn1_free (p_vet); + free (p_vet); p_vet = first; } } @@ -752,7 +752,7 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node) first = last = NULL; while (p) { - p_vet = (struct vet *) _asn1_malloc (sizeof (struct vet)); + p_vet = malloc (sizeof (struct vet)); if (p_vet == NULL) return; @@ -817,7 +817,7 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node) if (change == 1) { /* change position */ - temp = (unsigned char *) _asn1_malloc (p_vet->end - counter); + temp = malloc (p_vet->end - counter); if (temp == NULL) return; @@ -826,7 +826,7 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node) (p2_vet->end) - (p_vet->end)); memcpy (der + counter + (p2_vet->end) - (p_vet->end), temp, (p_vet->end) - counter); - _asn1_free (temp); + free (temp); p_vet->end = counter + (p2_vet->end - p_vet->end); } @@ -840,7 +840,7 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node) p_vet->prev->next = NULL; else first = NULL; - _asn1_free (p_vet); + free (p_vet); p_vet = first; } } diff --git a/lib/minitasn1/decoding.c b/lib/minitasn1/decoding.c index e6cdb9850..717112ba7 100644 --- a/lib/minitasn1/decoding.c +++ b/lib/minitasn1/decoding.c @@ -728,8 +728,6 @@ _asn1_get_octet_string (const unsigned char *der, ASN1_TYPE node, int *len) asn1_length_der (tot_len, temp, &len2); _asn1_set_value (node, temp, len2); - tot_len += len2; - ret = _asn1_extract_der_octet (node, der, *len); if (ret != ASN1_SUCCESS) return ret; @@ -741,9 +739,10 @@ _asn1_get_octet_string (const unsigned char *der, ASN1_TYPE node, int *len) len2 = asn1_get_length_der (der, *len, &len3); if (len2 < 0) return ASN1_DER_ERROR; - if (node) - _asn1_set_value (node, der, len3 + len2); + counter = len3 + len2; + if (node) + _asn1_set_value (node, der, counter); } *len = counter; @@ -1428,7 +1427,7 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const char *elementName, goto cleanup; } - if ((*structure)->name) + if ((*structure)->name[0] != 0) { /* Has *structure got a name? */ nameLen -= strlen ((*structure)->name); if (nameLen > 0) @@ -2248,6 +2247,9 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, p = node; while (1) { + if (p == NULL) + return ASN1_DER_ERROR; + ris = ASN1_SUCCESS; if (move != UP) @@ -2255,6 +2257,9 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, if (p->type & CONST_SET) { p2 = _asn1_find_up (p); + if (p2 == NULL) + return ASN1_DER_ERROR; + len2 = _asn1_strtol (p2->value, NULL, 10); if (len2 == -1) { @@ -2274,7 +2279,9 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, } else if (counter > len2) return ASN1_DER_ERROR; + p2 = p2->down; + while (p2) { if ((p2->type & CONST_SET) && (p2->type & CONST_NOT_USED)) @@ -2286,6 +2293,9 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, else { p3 = p2->down; + if (p3 == NULL) + return ASN1_DER_ERROR; + ris = _asn1_extract_tag_der (p3, der + counter, len - counter, &len2); @@ -2309,6 +2319,9 @@ asn1_der_decoding_startEnd (ASN1_TYPE element, const void *ider, int len, if (type_field (p->type) == TYPE_CHOICE) { p = p->down; + if (p == NULL) + return ASN1_DER_ERROR; + ris = _asn1_extract_tag_der (p, der + counter, len - counter, &len2); @@ -2596,7 +2609,7 @@ asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) p3 = p3->down; while (p3) { - if ((p3->name) && !(strcmp (p3->name, p2->name))) + if (!(strcmp (p3->name, p2->name))) break; p3 = p3->right; } @@ -2618,7 +2631,7 @@ asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) while (p3) { - if ((p3->name) && !(strcmp (p3->name, p2->name))) + if (!(strcmp (p3->name, p2->name))) break; p3 = p3->right; } @@ -2662,7 +2675,7 @@ asn1_expand_any_defined_by (ASN1_TYPE definitions, ASN1_TYPE * element) asn1_create_element (definitions, name, &aux); if (result == ASN1_SUCCESS) { - _asn1_set_name (aux, p->name); + _asn1_cpy_name (aux, p); len2 = asn1_get_length_der (p->value, p->value_len, &len3); @@ -2844,7 +2857,7 @@ asn1_expand_octet_string (ASN1_TYPE definitions, ASN1_TYPE * element, result = asn1_create_element (definitions, name, &aux); if (result == ASN1_SUCCESS) { - _asn1_set_name (aux, octetNode->name); + _asn1_cpy_name (aux, octetNode); len2 = asn1_get_length_der (octetNode->value, octetNode->value_len, &len3); diff --git a/lib/minitasn1/element.c b/lib/minitasn1/element.c index 8e8807b02..2ee495002 100644 --- a/lib/minitasn1/element.c +++ b/lib/minitasn1/element.c @@ -45,7 +45,7 @@ _asn1_hierarchical_name (ASN1_TYPE node, char *name, int name_size) while (p != NULL) { - if (p->name != NULL) + if (p->name[0] != 0) { _asn1_str_cpy (tmp_name, sizeof (tmp_name), name), _asn1_str_cpy (name, name_size, p->name); @@ -145,7 +145,7 @@ _asn1_append_sequence_set (ASN1_TYPE node) p = p->right; _asn1_set_right (p, p2); - if (p->name == NULL) + if (p->name[0] == 0) _asn1_str_cpy (temp, sizeof (temp), "?1"); else { @@ -343,8 +343,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, { if ((isdigit (value[0])) || (value[0] == '-')) { - value_temp = - (unsigned char *) _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT); + value_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); if (value_temp == NULL) return ASN1_MEM_ALLOC_ERROR; @@ -360,11 +359,9 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, { if (type_field (p->type) == TYPE_CONSTANT) { - if ((p->name) && (!_asn1_strcmp (p->name, value))) + if (!_asn1_strcmp (p->name, value)) { - value_temp = - (unsigned char *) - _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT); + value_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); if (value_temp == NULL) return ASN1_MEM_ALLOC_ERROR; @@ -383,7 +380,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, } else { /* len != 0 */ - value_temp = (unsigned char *) _asn1_malloc (len); + value_temp = malloc (len); if (value_temp == NULL) return ASN1_MEM_ALLOC_ERROR; memcpy (value_temp, value, len); @@ -397,7 +394,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, if (negative && (type_field (node->type) == TYPE_ENUMERATED)) { - _asn1_free (value_temp); + free (value_temp); return ASN1_VALUE_NOT_VALID; } @@ -420,11 +417,10 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, p = p->right; if ((isdigit (p->value[0])) || (p->value[0] == '-')) { - default_temp = - (unsigned char *) _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT); + default_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); if (default_temp == NULL) { - _asn1_free (value_temp); + free (value_temp); return ASN1_MEM_ALLOC_ERROR; } @@ -435,7 +431,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, { /* is an identifier like v1 */ if (!(node->type & CONST_LIST)) { - _asn1_free (value_temp); + free (value_temp); return ASN1_VALUE_NOT_VALID; } p2 = node->down; @@ -443,14 +439,12 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, { if (type_field (p2->type) == TYPE_CONSTANT) { - if ((p2->name) && (!_asn1_strcmp (p2->name, p->value))) + if (!_asn1_strcmp (p2->name, p->value)) { - default_temp = - (unsigned char *) - _asn1_malloc (SIZEOF_UNSIGNED_LONG_INT); + default_temp = malloc (SIZEOF_UNSIGNED_LONG_INT); if (default_temp == NULL) { - _asn1_free (value_temp); + free (value_temp); return ASN1_MEM_ALLOC_ERROR; } @@ -465,7 +459,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, } if (p2 == NULL) { - _asn1_free (value_temp); + free (value_temp); return ASN1_VALUE_NOT_VALID; } } @@ -481,9 +475,9 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, if (k2 == len2) _asn1_set_value (node, NULL, 0); } - _asn1_free (default_temp); + free (default_temp); } - _asn1_free (value_temp); + free (value_temp); break; case TYPE_OBJECT_ID: for (i = 0; i < _asn1_strlen (value); i++) @@ -562,7 +556,7 @@ asn1_write_value (ASN1_TYPE node_root, const char *name, if (len == 0) len = _asn1_strlen (value); asn1_length_der ((len >> 3) + 2, NULL, &len2); - temp = (unsigned char *) _asn1_malloc ((len >> 3) + 2 + len2); + temp = malloc ((len >> 3) + 2 + len2); if (temp == NULL) return ASN1_MEM_ALLOC_ERROR; @@ -767,7 +761,7 @@ asn1_read_value (ASN1_TYPE root, const char *name, void *ivalue, int *len) { if (type_field (p2->type) == TYPE_CONSTANT) { - if ((p2->name) && (!_asn1_strcmp (p2->name, p->value))) + if (!_asn1_strcmp (p2->name, p->value)) { if (_asn1_convert_integer (p2->value, value, value_size, diff --git a/lib/minitasn1/errors.c b/lib/minitasn1/errors.c index 76611d817..8b6e5e4df 100644 --- a/lib/minitasn1/errors.c +++ b/lib/minitasn1/errors.c @@ -100,44 +100,3 @@ asn1_strerror (asn1_retCode error) return NULL; } - -#ifndef ASN1_DISABLE_DEPRECATED - -/* Compatibility mappings to preserve ABI. */ - -/** - * libtasn1_perror: - * @error: is an error returned by a libtasn1 function. - * - * Prints a string to stderr with a description of an error. This - * function is like perror(). The only difference is that it accepts - * an error returned by a libtasn1 function. - * - * Deprecated: Use asn1_perror() instead. - **/ -void -libtasn1_perror (asn1_retCode error) -{ - asn1_perror (error); -} - -/** - * libtasn1_strerror: - * @error: is an error returned by a libtasn1 function. - * - * Returns a string with a description of an error. This function is - * similar to strerror. The only difference is that it accepts an - * error (number) returned by a libtasn1 function. - * - * Returns: Pointer to static zero-terminated string describing error - * code. - * - * Deprecated: Use asn1_strerror() instead. - **/ -const char * -libtasn1_strerror (asn1_retCode error) -{ - return asn1_strerror (error); -} - -#endif diff --git a/lib/minitasn1/gstr.c b/lib/minitasn1/gstr.c index 478507384..0558c7777 100644 --- a/lib/minitasn1/gstr.c +++ b/lib/minitasn1/gstr.c @@ -48,7 +48,8 @@ _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src) } } -void +/* Returns the bytes copied (not including the null terminator) */ +unsigned int _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src) { size_t str_size = strlen (src); @@ -56,13 +57,17 @@ _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src) if (dest_tot_size > str_size) { strcpy (dest, src); + return str_size; } else { if (dest_tot_size > 0) { - memcpy (dest, src, dest_tot_size - 1); - dest[dest_tot_size - 1] = 0; + str_size = dest_tot_size - 1; + memcpy (dest, src, str_size); + dest[str_size] = 0; + return str_size; } + else return 0; } } diff --git a/lib/minitasn1/gstr.h b/lib/minitasn1/gstr.h index baaa6a0b1..672d59eb5 100644 --- a/lib/minitasn1/gstr.h +++ b/lib/minitasn1/gstr.h @@ -19,7 +19,7 @@ * 02110-1301, USA */ -void _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src); +unsigned int _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src); void _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src); #define Estrcpy(x,y) _asn1_str_cpy(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) diff --git a/lib/minitasn1/hash.c b/lib/minitasn1/hash.c new file mode 100644 index 000000000..50da70c51 --- /dev/null +++ b/lib/minitasn1/hash.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2011-2012 Free Software Foundation, Inc. + * + * Author: Nikos Mavrogiannopoulos + * + * This file is part of GnuTLS. + * + * The GnuTLS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + */ + +#include + +#define INIT_VAL 0x33a1 +/* +------------------------------------------------------------------------------- +lookup3.c, by Bob Jenkins, May 2006, Public Domain. + +These are functions for producing 32-bit hashes for hash table lookup. +hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() +are externally useful functions. Routines to test the hash are included +if SELF_TEST is defined. You can use this free for any purpose. It's in +the public domain. It has no warranty. + +You probably want to use hashlittle(). hashlittle() and hashbig() +hash byte arrays. hashlittle() is faster than hashbig() on +little-endian machines. Intel and AMD are little-endian machines. +On second thought, you probably want hashlittle2(), which is identical to +hashlittle() except it returns two 32-bit hashes for the price of one. +You could implement hashbig2() if you wanted but I haven't bothered here. + +If you want to find a hash of, say, exactly 7 integers, do + a = i1; b = i2; c = i3; + mix(a,b,c); + a += i4; b += i5; c += i6; + mix(a,b,c); + a += i7; + final(a,b,c); +then use c as the hash value. If you have a variable length array of +4-byte integers to hash, use hashword(). If you have a byte array (like +a character string), use hashlittle(). If you have several byte arrays, or +a mix of things, see the comments above hashlittle(). + +Why is this so big? I read 12 bytes at a time into 3 4-byte integers, +then mix those integers. This is fast (you can do a lot more thorough +mixing with 12*3 instructions on 3 integers than you can with 3 instructions +on 1 byte), but shoehorning those bytes into integers efficiently is messy. +------------------------------------------------------------------------------- +*/ +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) + +/* +------------------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. + +This is reversible, so any information in (a,b,c) before mix() is +still in (a,b,c) after mix(). + +If four pairs of (a,b,c) inputs are run through mix(), or through +mix() in reverse, there are at least 32 bits of the output that +are sometimes the same for one pair and different for another pair. +This was tested for: +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that +satisfy this are + 4 6 8 16 19 4 + 9 15 3 18 27 15 + 14 9 3 7 17 3 +Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing +for "differ" defined as + with a one-bit base and a two-bit delta. I +used http://burtleburtle.net/bob/hash/avalanche.html to choose +the operations, constants, and arrangements of the variables. + +This does not achieve avalanche. There are input bits of (a,b,c) +that fail to affect some output bits of (a,b,c), especially of a. The +most thoroughly mixed value is c, but it doesn't really even achieve +avalanche in c. + +This allows some parallelism. Read-after-writes are good at doubling +the number of bits affected, so the goal of mixing pulls in the opposite +direction as the goal of parallelism. I did what I could. Rotates +seem to cost as much as shifts on every machine I could lay my hands +on, and rotates are much kinder to the top and bottom bits, so I used +rotates. +------------------------------------------------------------------------------- +*/ +#define mix(a,b,c) \ +{ \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ +} + +/* +------------------------------------------------------------------------------- +final -- final mixing of 3 32-bit values (a,b,c) into c + +Pairs of (a,b,c) values differing in only a few bits will usually +produce values of c that look totally different. This was tested for +* pairs that differed by one bit, by two bits, in any combination + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). +* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. +* the base values were pseudorandom, all zero but one bit set, or + all zero plus a counter that starts at zero. + +These constants passed: + 14 11 25 16 4 14 24 + 12 14 25 16 4 14 24 +and these came close: + 4 8 15 26 3 22 24 + 10 8 15 26 3 22 24 + 11 8 15 26 3 22 24 +------------------------------------------------------------------------------- +*/ +#define final(a,b,c) \ +{ \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ +} + + +/* +------------------------------------------------------------------------------- +hashlittle() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + length : the length of the key, counting by bytes + initval : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Two keys differing by one or two bits will have +totally different hash values. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (uint8_t **)k, do it like this: + for (i=0, h=0; i 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } + + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + case 11: c+=((uint32_t)k[10])<<16; + case 10: c+=((uint32_t)k[9])<<8; + case 9 : c+=k[8]; + case 8 : b+=((uint32_t)k[7])<<24; + case 7 : b+=((uint32_t)k[6])<<16; + case 6 : b+=((uint32_t)k[5])<<8; + case 5 : b+=k[4]; + case 4 : a+=((uint32_t)k[3])<<24; + case 3 : a+=((uint32_t)k[2])<<16; + case 2 : a+=((uint32_t)k[1])<<8; + case 1 : a+=k[0]; + break; + case 0 : return c; + } + + final(a,b,c); + return c; +} + + + diff --git a/lib/minitasn1/int.h b/lib/minitasn1/int.h index aad7ba63b..9e6bc89c7 100644 --- a/lib/minitasn1/int.h +++ b/lib/minitasn1/int.h @@ -46,7 +46,8 @@ struct node_asn_struct { /* public fields: */ - char *name; /* Node name */ + char name[ASN1_MAX_NAME_SIZE+1]; /* Node name */ + unsigned int name_hash; unsigned int type; /* Node type */ unsigned char *value; /* Node value */ int value_len; @@ -57,17 +58,13 @@ struct node_asn_struct unsigned char small_value[ASN1_SMALL_VALUE_SIZE]; /* For small values */ }; -#define _asn1_malloc malloc -#define _asn1_free free -#define _asn1_calloc calloc -#define _asn1_realloc realloc -#define _asn1_strdup strdup #define _asn1_strlen(s) strlen((const char *) s) #define _asn1_strtol(n,e,b) strtol((const char *) n, e, b) #define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b) #define _asn1_strcmp(a,b) strcmp((const char *)a, (const char *)b) #define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b) #define _asn1_strcat(a,b) strcat((char *)a, (const char *)b) +uint32_t _asn1_bhash( const void *key, size_t length); #define MAX_LOG_SIZE 1024 /* maximum number of characters of a log message */ diff --git a/lib/minitasn1/libtasn1.h b/lib/minitasn1/libtasn1.h index e9337e2d8..6293e7d47 100644 --- a/lib/minitasn1/libtasn1.h +++ b/lib/minitasn1/libtasn1.h @@ -44,7 +44,7 @@ extern "C" { #endif -#define ASN1_VERSION "2.14" +#define ASN1_VERSION "3.0" typedef int asn1_retCode; /* type returned by libtasn1 functions */ @@ -108,26 +108,14 @@ extern "C" /* that represent an ASN.1 DEFINITION. */ /******************************************************/ -#if !defined ASN1_BUILDING - /* This structure is also in internal.h, but then contains more - fields. You cannot make any modifications to these fields - without breaking ABI. */ - struct node_asn_struct - { - char *name; /* Node name */ - unsigned int type; /* Node type */ - unsigned char *value; /* Node value */ - int value_len; - struct node_asn_struct *down; /* Pointer to the son node */ - struct node_asn_struct *right; /* Pointer to the brother node */ - struct node_asn_struct *left; /* Pointer to the next list element */ - }; -#endif - typedef struct node_asn_struct node_asn; typedef node_asn *ASN1_TYPE; + /* maximum number of characters of a name */ + /* inside a file with ASN1 definitons */ +#define ASN1_MAX_NAME_SIZE 64 + #define ASN1_TYPE_EMPTY NULL /*****************************************/ @@ -178,9 +166,6 @@ extern "C" /* Fixed constants */ /***********************************/ - /* maximum number of characters of a name */ - /* inside a file with ASN1 definitons */ -#define ASN1_MAX_NAME_SIZE 128 /* maximum number of characters */ /* of a description message */ @@ -315,37 +300,6 @@ extern "C" asn1_copy_node (ASN1_TYPE dst, const char *dst_name, ASN1_TYPE src, const char *src_name); - /* Deprecated stuff. */ - -#ifndef ASN1_DISABLE_DEPRECATED - -#define LIBTASN1_VERSION ASN1_VERSION - -#ifndef MAX_NAME_SIZE -# define MAX_NAME_SIZE ASN1_MAX_NAME_SIZE -#endif - -#ifndef MAX_ERROR_DESCRIPTION_SIZE -# define MAX_ERROR_DESCRIPTION_SIZE ASN1_MAX_ERROR_DESCRIPTION_SIZE -#endif - -#ifndef __attribute__ - /* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) -# define __attribute__(Spec) /* empty */ -# endif -#endif - - /* Use asn1_strerror instead. */ - extern ASN1_API const char *libtasn1_strerror (asn1_retCode error) - __attribute__ ((deprecated)); - - /* Use asn1_perror instead. */ - extern ASN1_API void - libtasn1_perror (asn1_retCode error) __attribute__ ((deprecated)); - -#endif - #ifdef __cplusplus } #endif diff --git a/lib/minitasn1/parser_aux.c b/lib/minitasn1/parser_aux.c index 2e1f7eeec..ff701bc32 100644 --- a/lib/minitasn1/parser_aux.c +++ b/lib/minitasn1/parser_aux.c @@ -43,7 +43,7 @@ typedef struct list_struct list_type *firstElement = NULL; /******************************************************/ -/* Function : _asn1_add_node */ +/* Function : _asn1_add_static_node */ /* Description: creates a new NODE_ASN element and */ /* puts it in the list pointed by firstElement. */ /* Parameters: */ @@ -52,19 +52,19 @@ list_type *firstElement = NULL; /* Return: pointer to the new element. */ /******************************************************/ ASN1_TYPE -_asn1_add_node (unsigned int type) +_asn1_add_static_node (unsigned int type) { list_type *listElement; ASN1_TYPE punt; - punt = (ASN1_TYPE) _asn1_calloc (1, sizeof (struct node_asn_struct)); + punt = calloc (1, sizeof (struct node_asn_struct)); if (punt == NULL) return NULL; - listElement = (list_type *) _asn1_malloc (sizeof (list_type)); + listElement = malloc (sizeof (list_type)); if (listElement == NULL) { - _asn1_free (punt); + free (punt); return NULL; } @@ -95,6 +95,8 @@ asn1_find_node (ASN1_TYPE pointer, const char *name) ASN1_TYPE p; char *n_end, n[ASN1_MAX_NAME_SIZE + 1]; const char *n_start; + unsigned int nsize; + unsigned int nhash; if (pointer == NULL) return NULL; @@ -105,25 +107,30 @@ asn1_find_node (ASN1_TYPE pointer, const char *name) p = pointer; n_start = name; - if (p->name != NULL) + if (p->name[0] != 0) { /* has *pointer got a name ? */ n_end = strchr (n_start, '.'); /* search the first dot */ if (n_end) { - memcpy (n, n_start, n_end - n_start); - n[n_end - n_start] = 0; + nsize = n_end - n_start; + memcpy (n, n_start, nsize); + n[nsize] = 0; n_start = n_end; n_start++; + + nhash = _asn1_bhash(n, nsize); } else { - _asn1_str_cpy (n, sizeof (n), n_start); + nsize = _asn1_str_cpy (n, sizeof (n), n_start); + nhash = _asn1_bhash(n, nsize); + n_start = NULL; } while (p) { - if ((p->name) && (!strcmp (p->name, n))) + if ((p->name) && nhash == p->name_hash && (!strcmp (p->name, n))) break; else p = p->right; @@ -143,14 +150,18 @@ asn1_find_node (ASN1_TYPE pointer, const char *name) n_end = strchr (n_start, '.'); /* search the next dot */ if (n_end) { - memcpy (n, n_start, n_end - n_start); - n[n_end - n_start] = 0; + nsize = n_end - n_start; + memcpy (n, n_start, nsize); + n[nsize] = 0; n_start = n_end; n_start++; + + nhash = _asn1_bhash(n, nsize); } else { - _asn1_str_cpy (n, sizeof (n), n_start); + nsize = _asn1_str_cpy (n, sizeof (n), n_start); + nhash = _asn1_bhash(n, nsize); n_start = NULL; } @@ -172,7 +183,7 @@ asn1_find_node (ASN1_TYPE pointer, const char *name) { /* no "?LAST" */ while (p) { - if ((p->name) && (!strcmp (p->name, n))) + if (p->name_hash == nhash && !strcmp (p->name, n)) break; else p = p->right; @@ -204,7 +215,7 @@ _asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len) if (node->value) { if (node->value != node->small_value) - _asn1_free (node->value); + free (node->value); node->value = NULL; node->value_len = 0; } @@ -218,7 +229,7 @@ _asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len) } else { - node->value = _asn1_malloc (len); + node->value = malloc (len); if (node->value == NULL) return NULL; } @@ -249,7 +260,7 @@ _asn1_set_value_octet (ASN1_TYPE node, const void *value, unsigned int len) return node; asn1_length_der (len, NULL, &len2); - temp = (unsigned char *) _asn1_malloc (len + len2); + temp = malloc (len + len2); if (temp == NULL) return NULL; @@ -269,7 +280,7 @@ _asn1_set_value_m (ASN1_TYPE node, void *value, unsigned int len) if (node->value) { if (node->value != node->small_value) - _asn1_free (node->value); + free (node->value); node->value = NULL; node->value_len = 0; } @@ -303,7 +314,7 @@ _asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len) /* value is allocated */ int prev_len = node->value_len; node->value_len += len; - node->value = _asn1_realloc (node->value, node->value_len); + node->value = realloc (node->value, node->value_len); if (node->value == NULL) { node->value_len = 0; @@ -318,7 +329,7 @@ _asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len) /* value is in node */ int prev_len = node->value_len; node->value_len += len; - node->value = _asn1_malloc (node->value_len); + node->value = malloc (node->value_len); if (node->value == NULL) { node->value_len = 0; @@ -346,27 +357,51 @@ _asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len) ASN1_TYPE _asn1_set_name (ASN1_TYPE node, const char *name) { +unsigned int nsize; + if (node == NULL) return node; - if (node->name) + if (name == NULL) { - _asn1_free (node->name); - node->name = NULL; + node->name[0] = 0; + node->name_hash = _asn1_bhash(node->name, 0); + return node; } - if (name == NULL) - return node; + nsize = _asn1_str_cpy (node->name, sizeof (node->name), name); + node->name_hash = _asn1_bhash(node->name, nsize); + + return node; +} + +/******************************************************************/ +/* Function : _asn1_cpy_name */ +/* Description: copies the field NAME in a NODE_ASN element. */ +/* Parameters: */ +/* dst: a dest element pointer. */ +/* src: a source element pointer. */ +/* Return: pointer to the NODE_ASN element. */ +/******************************************************************/ +ASN1_TYPE +_asn1_cpy_name (ASN1_TYPE dst, ASN1_TYPE src) +{ +unsigned int nsize; - if (strlen (name)) + if (dst == NULL) + return dst; + + if (src == NULL) { - node->name = (char *) _asn1_strdup (name); - if (node->name == NULL) - return NULL; + dst->name[0] = 0; + dst->name_hash = _asn1_bhash(dst->name, 0); + return dst; } - else - node->name = NULL; - return node; + + nsize = _asn1_str_cpy (dst->name, sizeof (dst->name), src->name); + dst->name_hash = src->name_hash; + + return dst; } /******************************************************************/ @@ -389,21 +424,6 @@ _asn1_set_right (ASN1_TYPE node, ASN1_TYPE right) return node; } -/******************************************************************/ -/* Function : _asn1_get_right */ -/* Description: returns the element pointed by the RIGHT field of */ -/* a NODE_ASN element. */ -/* Parameters: */ -/* node: NODE_ASN element pointer. */ -/* Return: field RIGHT of NODE. */ -/******************************************************************/ -ASN1_TYPE -_asn1_get_right (ASN1_TYPE node) -{ - if (node == NULL) - return NULL; - return node->right; -} /******************************************************************/ /* Function : _asn1_get_last_right */ @@ -426,78 +446,6 @@ _asn1_get_last_right (ASN1_TYPE node) } /******************************************************************/ -/* Function : _asn1_set_down */ -/* Description: sets the field DOWN in a NODE_ASN element. */ -/* Parameters: */ -/* node: element pointer. */ -/* down: pointer to a NODE_ASN element that you want be pointed */ -/* by NODE. */ -/* Return: pointer to *NODE. */ -/******************************************************************/ -ASN1_TYPE -_asn1_set_down (ASN1_TYPE node, ASN1_TYPE down) -{ - if (node == NULL) - return node; - node->down = down; - if (down) - down->left = node; - return node; -} - -/******************************************************************/ -/* Function : _asn1_get_down */ -/* Description: returns the element pointed by the DOWN field of */ -/* a NODE_ASN element. */ -/* Parameters: */ -/* node: NODE_ASN element pointer. */ -/* Return: field DOWN of NODE. */ -/******************************************************************/ -ASN1_TYPE -_asn1_get_down (ASN1_TYPE node) -{ - if (node == NULL) - return NULL; - return node->down; -} - -/******************************************************************/ -/* Function : _asn1_get_name */ -/* Description: returns the name of a NODE_ASN element. */ -/* Parameters: */ -/* node: NODE_ASN element pointer. */ -/* Return: a null terminated string. */ -/******************************************************************/ -char * -_asn1_get_name (ASN1_TYPE node) -{ - if (node == NULL) - return NULL; - return node->name; -} - -/******************************************************************/ -/* Function : _asn1_mod_type */ -/* Description: change the field TYPE of an NODE_ASN element. */ -/* The new value is the old one | (bitwise or) the */ -/* paramener VALUE. */ -/* Parameters: */ -/* node: NODE_ASN element pointer. */ -/* value: the integer value that must be or-ed with the current */ -/* value of field TYPE. */ -/* Return: NODE pointer. */ -/******************************************************************/ -ASN1_TYPE -_asn1_mod_type (ASN1_TYPE node, unsigned int value) -{ - if (node == NULL) - return node; - node->type |= value; - return node; -} - - -/******************************************************************/ /* Function : _asn1_remove_node */ /* Description: gets free the memory allocated for an NODE_ASN */ /* element (not the elements pointed by it). */ @@ -510,11 +458,9 @@ _asn1_remove_node (ASN1_TYPE node) if (node == NULL) return; - if (node->name != NULL) - _asn1_free (node->name); if (node->value != NULL && node->value != node->small_value) - _asn1_free (node->value); - _asn1_free (node); + free (node->value); + free (node); } /******************************************************************/ @@ -554,7 +500,7 @@ _asn1_delete_list (void) { listElement = firstElement; firstElement = firstElement->next; - _asn1_free (listElement); + free (listElement); } } @@ -573,7 +519,7 @@ _asn1_delete_list_and_nodes (void) listElement = firstElement; firstElement = firstElement->next; _asn1_remove_node (listElement->node); - _asn1_free (listElement); + free (listElement); } } @@ -732,7 +678,7 @@ _asn1_expand_object_id (ASN1_TYPE node) { if (type_field (p4->type) == TYPE_CONSTANT) { - p5 = _asn1_add_node_only (TYPE_CONSTANT); + p5 = _asn1_add_single_node (TYPE_CONSTANT); _asn1_set_name (p5, p4->name); tlen = _asn1_strlen (p4->value); if (tlen > 0) @@ -965,7 +911,10 @@ _asn1_check_identifier (ASN1_TYPE node) p2 = asn1_find_node (node, name2); if (p2 == NULL) { - _asn1_strcpy (_asn1_identifierMissing, p->value); + if (p->value) + _asn1_strcpy (_asn1_identifierMissing, p->value); + else + _asn1_strcpy (_asn1_identifierMissing, "(null)"); return ASN1_IDENTIFIER_NOT_FOUND; } } diff --git a/lib/minitasn1/parser_aux.h b/lib/minitasn1/parser_aux.h index 374f59953..f3aeb54fd 100644 --- a/lib/minitasn1/parser_aux.h +++ b/lib/minitasn1/parser_aux.h @@ -27,7 +27,7 @@ /***************************************/ /* Functions used by ASN.1 parser */ /***************************************/ -ASN1_TYPE _asn1_add_node (unsigned int type); +ASN1_TYPE _asn1_add_static_node (unsigned int type); ASN1_TYPE _asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len); @@ -42,20 +42,12 @@ _asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len); ASN1_TYPE _asn1_set_name (ASN1_TYPE node, const char *name); -ASN1_TYPE _asn1_set_right (ASN1_TYPE node, ASN1_TYPE right); +ASN1_TYPE _asn1_cpy_name (ASN1_TYPE dst, ASN1_TYPE src); -ASN1_TYPE _asn1_get_right (ASN1_TYPE node); +ASN1_TYPE _asn1_set_right (ASN1_TYPE node, ASN1_TYPE right); ASN1_TYPE _asn1_get_last_right (ASN1_TYPE node); -ASN1_TYPE _asn1_set_down (ASN1_TYPE node, ASN1_TYPE down); - -char *_asn1_get_name (ASN1_TYPE node); - -ASN1_TYPE _asn1_get_down (ASN1_TYPE node); - -ASN1_TYPE _asn1_mod_type (ASN1_TYPE node, unsigned int value); - void _asn1_remove_node (ASN1_TYPE node); void _asn1_delete_list (void); @@ -76,4 +68,91 @@ asn1_retCode _asn1_check_identifier (ASN1_TYPE node); asn1_retCode _asn1_set_default_tag (ASN1_TYPE node); +/******************************************************************/ +/* Function : _asn1_get_right */ +/* Description: returns the element pointed by the RIGHT field of */ +/* a NODE_ASN element. */ +/* Parameters: */ +/* node: NODE_ASN element pointer. */ +/* Return: field RIGHT of NODE. */ +/******************************************************************/ +inline static ASN1_TYPE +_asn1_get_right (ASN1_TYPE node) +{ + if (node == NULL) + return NULL; + return node->right; +} + +/******************************************************************/ +/* Function : _asn1_set_down */ +/* Description: sets the field DOWN in a NODE_ASN element. */ +/* Parameters: */ +/* node: element pointer. */ +/* down: pointer to a NODE_ASN element that you want be pointed */ +/* by NODE. */ +/* Return: pointer to *NODE. */ +/******************************************************************/ +inline static ASN1_TYPE +_asn1_set_down (ASN1_TYPE node, ASN1_TYPE down) +{ + if (node == NULL) + return node; + node->down = down; + if (down) + down->left = node; + return node; +} + +/******************************************************************/ +/* Function : _asn1_get_down */ +/* Description: returns the element pointed by the DOWN field of */ +/* a NODE_ASN element. */ +/* Parameters: */ +/* node: NODE_ASN element pointer. */ +/* Return: field DOWN of NODE. */ +/******************************************************************/ +inline static ASN1_TYPE +_asn1_get_down (ASN1_TYPE node) +{ + if (node == NULL) + return NULL; + return node->down; +} + +/******************************************************************/ +/* Function : _asn1_get_name */ +/* Description: returns the name of a NODE_ASN element. */ +/* Parameters: */ +/* node: NODE_ASN element pointer. */ +/* Return: a null terminated string. */ +/******************************************************************/ +inline static char * +_asn1_get_name (ASN1_TYPE node) +{ + if (node == NULL) + return NULL; + return node->name; +} + +/******************************************************************/ +/* Function : _asn1_mod_type */ +/* Description: change the field TYPE of an NODE_ASN element. */ +/* The new value is the old one | (bitwise or) the */ +/* paramener VALUE. */ +/* Parameters: */ +/* node: NODE_ASN element pointer. */ +/* value: the integer value that must be or-ed with the current */ +/* value of field TYPE. */ +/* Return: NODE pointer. */ +/******************************************************************/ +inline static ASN1_TYPE +_asn1_mod_type (ASN1_TYPE node, unsigned int value) +{ + if (node == NULL) + return node; + node->type |= value; + return node; +} + #endif diff --git a/lib/minitasn1/structure.c b/lib/minitasn1/structure.c index 41cebe4b1..7d622ce82 100644 --- a/lib/minitasn1/structure.c +++ b/lib/minitasn1/structure.c @@ -37,7 +37,7 @@ extern char _asn1_identifierMissing[]; /******************************************************/ -/* Function : _asn1_add_node_only */ +/* Function : _asn1_add_single_node */ /* Description: creates a new NODE_ASN element. */ /* Parameters: */ /* type: type of the new element (see TYPE_ */ @@ -45,11 +45,11 @@ extern char _asn1_identifierMissing[]; /* Return: pointer to the new element. */ /******************************************************/ ASN1_TYPE -_asn1_add_node_only (unsigned int type) +_asn1_add_single_node (unsigned int type) { ASN1_TYPE punt; - punt = (ASN1_TYPE) _asn1_calloc (1, sizeof (struct node_asn_struct)); + punt = calloc (1, sizeof (struct node_asn_struct)); if (punt == NULL) return NULL; @@ -104,7 +104,7 @@ _asn1_create_static_structure (ASN1_TYPE pointer, char *output_file_name, { fprintf (file, " { "); - if (p->name) + if (p->name[0] != 0) fprintf (file, "\"%s\", ", p->name); else fprintf (file, "NULL, "); @@ -191,7 +191,7 @@ asn1_array2tree (const ASN1_ARRAY_TYPE * array, ASN1_TYPE * definitions, k = 0; while (array[k].value || array[k].type || array[k].name) { - p = _asn1_add_node (array[k].type & (~CONST_DOWN)); + p = _asn1_add_static_node (array[k].type & (~CONST_DOWN)); if (array[k].name) _asn1_set_name (p, array[k].name); if (array[k].value) @@ -380,7 +380,7 @@ _asn1_copy_structure3 (ASN1_TYPE source_node) if (source_node == NULL) return NULL; - dest_node = _asn1_add_node_only (source_node->type); + dest_node = _asn1_add_single_node (source_node->type); p_s = source_node; p_d = dest_node; @@ -391,48 +391,37 @@ _asn1_copy_structure3 (ASN1_TYPE source_node) { if (move != UP) { - if (p_s->name) - _asn1_set_name (p_d, p_s->name); + if (p_s->name[0] != 0) + _asn1_cpy_name (p_d, p_s); if (p_s->value) _asn1_set_value (p_d, p_s->value, p_s->value_len); - move = DOWN; - } - else - move = RIGHT; - - if (move == DOWN) - { if (p_s->down) { p_s = p_s->down; p_d_prev = p_d; - p_d = _asn1_add_node_only (p_s->type); + p_d = _asn1_add_single_node (p_s->type); _asn1_set_down (p_d_prev, p_d); + continue; } - else - move = RIGHT; } if (p_s == source_node) - break; + break; - if (move == RIGHT) - { - if (p_s->right) - { - p_s = p_s->right; - p_d_prev = p_d; - p_d = _asn1_add_node_only (p_s->type); - _asn1_set_right (p_d_prev, p_d); - } - else + if (p_s->right) + { + move = RIGHT; + p_s = p_s->right; + p_d_prev = p_d; + p_d = _asn1_add_single_node (p_s->type); + _asn1_set_right (p_d_prev, p_d); + } + else + { move = UP; - } - if (move == UP) - { - p_s = _asn1_find_up (p_s); - p_d = _asn1_find_up (p_d); - } + p_s = _asn1_find_up (p_s); + p_d = _asn1_find_up (p_d); + } } while (p_s != source_node); @@ -481,7 +470,7 @@ _asn1_type_choice_config (ASN1_TYPE node) { if (type_field (p3->type) == TYPE_TAG) { - p4 = _asn1_add_node_only (p3->type); + p4 = _asn1_add_single_node (p3->type); tlen = _asn1_strlen (p3->value); if (tlen > 0) _asn1_set_value (p4, p3->value, tlen + 1); @@ -556,15 +545,13 @@ _asn1_expand_identifier (ASN1_TYPE * node, ASN1_TYPE root) { if (type_field (p->type) == TYPE_IDENTIFIER) { - _asn1_str_cpy (name2, sizeof (name2), root->name); - _asn1_str_cat (name2, sizeof (name2), "."); - _asn1_str_cat (name2, sizeof (name2), (char *) p->value); + snprintf(name2, sizeof (name2), "%s.%s", root->name, p->value); p2 = _asn1_copy_structure2 (root, name2); if (p2 == NULL) { return ASN1_IDENTIFIER_NOT_FOUND; } - _asn1_set_name (p2, p->name); + _asn1_cpy_name (p2, p); p2->right = p->right; p2->left = p->left; if (p->right) @@ -719,7 +706,7 @@ asn1_print_structure (FILE * out, ASN1_TYPE structure, const char *name, for (k = 0; k < indent; k++) fprintf (out, " "); fprintf (out, "name:"); - if (p->name) + if (p->name[0] != 0) fprintf (out, "%s ", p->name); else fprintf (out, "NULL "); @@ -736,7 +723,7 @@ asn1_print_structure (FILE * out, ASN1_TYPE structure, const char *name, for (k = 0; k < indent; k++) fprintf (out, " "); fprintf (out, "name:"); - if (p->name) + if (p->name[0] != 0) fprintf (out, "%s ", p->name); else fprintf (out, "NULL "); @@ -1078,7 +1065,7 @@ asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num) while (p) { - if ((p->name) && (p->name[0] == '?')) + if (p->name[0] == '?') (*num)++; p = p->right; } @@ -1169,27 +1156,27 @@ asn1_copy_node (ASN1_TYPE dst, const char *dst_name, if (result != ASN1_MEM_ERROR) return result; - data = _asn1_malloc (size); + data = malloc (size); if (data == NULL) return ASN1_MEM_ERROR; result = asn1_der_coding (src, src_name, data, &size, NULL); if (result != ASN1_SUCCESS) { - _asn1_free (data); + free (data); return result; } dst_node = asn1_find_node (dst, dst_name); if (dst_node == NULL) { - _asn1_free (data); + free (data); return ASN1_ELEMENT_NOT_FOUND; } result = asn1_der_decoding (&dst_node, data, size, NULL); - _asn1_free (data); + free (data); return result; } diff --git a/lib/minitasn1/structure.h b/lib/minitasn1/structure.h index 0a84e26be..cf4205b86 100644 --- a/lib/minitasn1/structure.h +++ b/lib/minitasn1/structure.h @@ -34,7 +34,7 @@ asn1_retCode _asn1_create_static_structure (ASN1_TYPE pointer, ASN1_TYPE _asn1_copy_structure3 (ASN1_TYPE source_node); -ASN1_TYPE _asn1_add_node_only (unsigned int type); +ASN1_TYPE _asn1_add_single_node (unsigned int type); ASN1_TYPE _asn1_find_left (ASN1_TYPE node); -- 2.11.4.GIT