diff options
Diffstat (limited to 'src/lib/libcrypto/asn1')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 11 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/asn_pack.c | 97 |
2 files changed, 108 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index 176a3d5b82..78705da909 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
| @@ -760,6 +760,10 @@ typedef struct BIT_STRING_BITNAME_st { | |||
| 760 | (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ | 760 | (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ |
| 761 | ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) | 761 | ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) |
| 762 | 762 | ||
| 763 | /* for the is_set parameter to i2d_ASN1_SET */ | ||
| 764 | #define IS_SEQUENCE 0 | ||
| 765 | #define IS_SET 1 | ||
| 766 | |||
| 763 | DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) | 767 | DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) |
| 764 | 768 | ||
| 765 | int ASN1_TYPE_get(ASN1_TYPE *a); | 769 | int ASN1_TYPE_get(ASN1_TYPE *a); |
| @@ -1035,7 +1039,14 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, | |||
| 1035 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, | 1039 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, |
| 1036 | unsigned char *data, int max_len); | 1040 | unsigned char *data, int max_len); |
| 1037 | 1041 | ||
| 1042 | STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len, | ||
| 1043 | d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK)); | ||
| 1044 | unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d, | ||
| 1045 | unsigned char **buf, int *len ); | ||
| 1046 | void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i); | ||
| 1038 | void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); | 1047 | void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); |
| 1048 | ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, | ||
| 1049 | ASN1_OCTET_STRING **oct); | ||
| 1039 | 1050 | ||
| 1040 | ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); | 1051 | ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); |
| 1041 | 1052 | ||
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c index 9752a68206..8eb39e6a9b 100644 --- a/src/lib/libcrypto/asn1/asn_pack.c +++ b/src/lib/libcrypto/asn1/asn_pack.c | |||
| @@ -60,6 +60,103 @@ | |||
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
| 62 | 62 | ||
| 63 | #ifndef NO_ASN1_OLD | ||
| 64 | |||
| 65 | /* ASN1 packing and unpacking functions */ | ||
| 66 | |||
| 67 | /* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */ | ||
| 68 | |||
| 69 | STACK_OF(OPENSSL_BLOCK) * | ||
| 70 | ASN1_seq_unpack(const unsigned char *buf, int len, d2i_of_void *d2i, | ||
| 71 | void (*free_func)(OPENSSL_BLOCK)) | ||
| 72 | { | ||
| 73 | STACK_OF(OPENSSL_BLOCK) *sk; | ||
| 74 | const unsigned char *pbuf; | ||
| 75 | |||
| 76 | pbuf = buf; | ||
| 77 | if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, | ||
| 78 | V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL))) | ||
| 79 | ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR); | ||
| 80 | return sk; | ||
| 81 | } | ||
| 82 | |||
| 83 | /* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a | ||
| 84 | * OPENSSL_malloc'ed buffer | ||
| 85 | */ | ||
| 86 | |||
| 87 | unsigned char * | ||
| 88 | ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d, | ||
| 89 | unsigned char **buf, int *len) | ||
| 90 | { | ||
| 91 | int safelen; | ||
| 92 | unsigned char *safe, *p; | ||
| 93 | |||
| 94 | if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE, | ||
| 95 | V_ASN1_UNIVERSAL, IS_SEQUENCE))) { | ||
| 96 | ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR); | ||
| 97 | return NULL; | ||
| 98 | } | ||
| 99 | if (!(safe = malloc(safelen))) { | ||
| 100 | ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE); | ||
| 101 | return NULL; | ||
| 102 | } | ||
| 103 | p = safe; | ||
| 104 | i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, | ||
| 105 | IS_SEQUENCE); | ||
| 106 | if (len) | ||
| 107 | *len = safelen; | ||
| 108 | if (buf) | ||
| 109 | *buf = safe; | ||
| 110 | return safe; | ||
| 111 | } | ||
| 112 | |||
| 113 | /* Extract an ASN1 object from an ASN1_STRING */ | ||
| 114 | |||
| 115 | void * | ||
| 116 | ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i) | ||
| 117 | { | ||
| 118 | const unsigned char *p; | ||
| 119 | char *ret; | ||
| 120 | |||
| 121 | p = oct->data; | ||
| 122 | if (!(ret = d2i(NULL, &p, oct->length))) | ||
| 123 | ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR); | ||
| 124 | return ret; | ||
| 125 | } | ||
| 126 | |||
| 127 | /* Pack an ASN1 object into an ASN1_STRING */ | ||
| 128 | |||
| 129 | ASN1_STRING * | ||
| 130 | ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct) | ||
| 131 | { | ||
| 132 | unsigned char *p; | ||
| 133 | ASN1_STRING *octmp; | ||
| 134 | |||
| 135 | if (!oct || !*oct) { | ||
| 136 | if (!(octmp = ASN1_STRING_new())) { | ||
| 137 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
| 138 | return NULL; | ||
| 139 | } | ||
| 140 | if (oct) | ||
| 141 | *oct = octmp; | ||
| 142 | } else | ||
| 143 | octmp = *oct; | ||
| 144 | |||
| 145 | if (!(octmp->length = i2d(obj, NULL))) { | ||
| 146 | ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR); | ||
| 147 | return NULL; | ||
| 148 | } | ||
| 149 | if (!(p = malloc (octmp->length))) { | ||
| 150 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
| 151 | return NULL; | ||
| 152 | } | ||
| 153 | octmp->data = p; | ||
| 154 | i2d (obj, &p); | ||
| 155 | return octmp; | ||
| 156 | } | ||
| 157 | |||
| 158 | #endif | ||
| 159 | |||
| 63 | /* ASN1_ITEM versions of the above */ | 160 | /* ASN1_ITEM versions of the above */ |
| 64 | 161 | ||
| 65 | ASN1_STRING * | 162 | ASN1_STRING * |
