]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/evp_asn1.c
2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1.h>
13 #include <openssl/asn1t.h>
14 #include "crypto/asn1.h"
16 int ASN1_TYPE_set_octetstring(ASN1_TYPE
*a
, unsigned char *data
, int len
)
20 if ((os
= ASN1_OCTET_STRING_new()) == NULL
)
22 if (!ASN1_OCTET_STRING_set(os
, data
, len
)) {
23 ASN1_OCTET_STRING_free(os
);
26 ASN1_TYPE_set(a
, V_ASN1_OCTET_STRING
, os
);
30 /* int max_len: for returned value */
31 int ASN1_TYPE_get_octetstring(const ASN1_TYPE
*a
, unsigned char *data
, int max_len
)
34 const unsigned char *p
;
36 if ((a
->type
!= V_ASN1_OCTET_STRING
) || (a
->value
.octet_string
== NULL
)) {
37 ERR_raise(ERR_LIB_ASN1
, ASN1_R_DATA_IS_WRONG
);
40 p
= ASN1_STRING_get0_data(a
->value
.octet_string
);
41 ret
= ASN1_STRING_length(a
->value
.octet_string
);
50 static ossl_inline
void asn1_type_init_oct(ASN1_OCTET_STRING
*oct
,
51 unsigned char *data
, int len
)
54 oct
->type
= V_ASN1_OCTET_STRING
;
59 static int asn1_type_get_int_oct(ASN1_OCTET_STRING
*oct
, int32_t anum
,
60 long *num
, unsigned char *data
, int max_len
)
62 int ret
= ASN1_STRING_length(oct
), n
;
73 memcpy(data
, ASN1_STRING_get0_data(oct
), n
);
80 ASN1_OCTET_STRING
*oct
;
83 ASN1_SEQUENCE(asn1_int_oct
) = {
84 ASN1_EMBED(asn1_int_oct
, num
, INT32
),
85 ASN1_SIMPLE(asn1_int_oct
, oct
, ASN1_OCTET_STRING
)
86 } static_ASN1_SEQUENCE_END(asn1_int_oct
)
88 DECLARE_ASN1_ITEM(asn1_int_oct
)
90 int ASN1_TYPE_set_int_octetstring(ASN1_TYPE
*a
, long num
, unsigned char *data
,
94 ASN1_OCTET_STRING oct
;
98 asn1_type_init_oct(&oct
, data
, len
);
100 if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(asn1_int_oct
), &atmp
, &a
))
105 int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE
*a
, long *num
,
106 unsigned char *data
, int max_len
)
108 asn1_int_oct
*atmp
= NULL
;
111 if ((a
->type
!= V_ASN1_SEQUENCE
) || (a
->value
.sequence
== NULL
)) {
115 atmp
= ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(asn1_int_oct
), a
);
120 ret
= asn1_type_get_int_oct(atmp
->oct
, atmp
->num
, num
, data
, max_len
);
124 ERR_raise(ERR_LIB_ASN1
, ASN1_R_DATA_IS_WRONG
);
126 M_ASN1_free_of(atmp
, asn1_int_oct
);
131 ASN1_OCTET_STRING
*oct
;
136 * Defined in RFC 5084 -
137 * Section 2. "Content-Authenticated Encryption Algorithms"
139 ASN1_SEQUENCE(asn1_oct_int
) = {
140 ASN1_SIMPLE(asn1_oct_int
, oct
, ASN1_OCTET_STRING
),
141 ASN1_EMBED(asn1_oct_int
, num
, INT32
)
142 } static_ASN1_SEQUENCE_END(asn1_oct_int
)
144 DECLARE_ASN1_ITEM(asn1_oct_int
)
146 int ossl_asn1_type_set_octetstring_int(ASN1_TYPE
*a
, long num
,
147 unsigned char *data
, int len
)
150 ASN1_OCTET_STRING oct
;
154 asn1_type_init_oct(&oct
, data
, len
);
156 if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(asn1_oct_int
), &atmp
, &a
))
161 int ossl_asn1_type_get_octetstring_int(const ASN1_TYPE
*a
, long *num
,
162 unsigned char *data
, int max_len
)
164 asn1_oct_int
*atmp
= NULL
;
167 if ((a
->type
!= V_ASN1_SEQUENCE
) || (a
->value
.sequence
== NULL
))
170 atmp
= ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(asn1_oct_int
), a
);
175 ret
= asn1_type_get_int_oct(atmp
->oct
, atmp
->num
, num
, data
, max_len
);
179 ERR_raise(ERR_LIB_ASN1
, ASN1_R_DATA_IS_WRONG
);
181 M_ASN1_free_of(atmp
, asn1_oct_int
);