2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
13 #include <openssl/rand.h>
14 #include <openssl/asn1t.h>
15 #include "internal/numbers.h"
19 # pragma GCC diagnostic ignored "-Wunused-function"
22 # pragma clang diagnostic ignored "-Wunused-function"
25 /* Badly coded ASN.1 INTEGER zero wrapped in a sequence */
26 static unsigned char t_invalid_zero[] = {
27 0x30, 0x02, /* SEQUENCE tag + length */
28 0x02, 0x00 /* INTEGER tag + length */
31 #if OPENSSL_API_COMPAT < 0x10200000L
32 /* LONG case ************************************************************* */
38 ASN1_SEQUENCE(ASN1_LONG_DATA) = {
39 ASN1_EMBED(ASN1_LONG_DATA, test_long, LONG),
40 } static_ASN1_SEQUENCE_END(ASN1_LONG_DATA)
42 IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(ASN1_LONG_DATA)
43 IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(ASN1_LONG_DATA)
45 static int test_long(void)
47 const unsigned char *p = t_invalid_zero;
48 ASN1_LONG_DATA *dectst =
49 d2i_ASN1_LONG_DATA(NULL, &p, sizeof(t_invalid_zero));
54 ASN1_LONG_DATA_free(dectst);
59 /* INT32 case ************************************************************* */
65 ASN1_SEQUENCE(ASN1_INT32_DATA) = {
66 ASN1_EMBED(ASN1_INT32_DATA, test_int32, INT32),
67 } static_ASN1_SEQUENCE_END(ASN1_INT32_DATA)
69 IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(ASN1_INT32_DATA)
70 IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(ASN1_INT32_DATA)
72 static int test_int32(void)
74 const unsigned char *p = t_invalid_zero;
75 ASN1_INT32_DATA *dectst =
76 d2i_ASN1_INT32_DATA(NULL, &p, sizeof(t_invalid_zero));
81 ASN1_INT32_DATA_free(dectst);
85 /* UINT32 case ************************************************************* */
91 ASN1_SEQUENCE(ASN1_UINT32_DATA) = {
92 ASN1_EMBED(ASN1_UINT32_DATA, test_uint32, UINT32),
93 } static_ASN1_SEQUENCE_END(ASN1_UINT32_DATA)
95 IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(ASN1_UINT32_DATA)
96 IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(ASN1_UINT32_DATA)
98 static int test_uint32(void)
100 const unsigned char *p = t_invalid_zero;
101 ASN1_UINT32_DATA *dectst =
102 d2i_ASN1_UINT32_DATA(NULL, &p, sizeof(t_invalid_zero));
107 ASN1_UINT32_DATA_free(dectst);
111 /* INT64 case ************************************************************* */
117 ASN1_SEQUENCE(ASN1_INT64_DATA) = {
118 ASN1_EMBED(ASN1_INT64_DATA, test_int64, INT64),
119 } static_ASN1_SEQUENCE_END(ASN1_INT64_DATA)
121 IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(ASN1_INT64_DATA)
122 IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(ASN1_INT64_DATA)
124 static int test_int64(void)
126 const unsigned char *p = t_invalid_zero;
127 ASN1_INT64_DATA *dectst =
128 d2i_ASN1_INT64_DATA(NULL, &p, sizeof(t_invalid_zero));
133 ASN1_INT64_DATA_free(dectst);
137 /* UINT64 case ************************************************************* */
140 uint64_t test_uint64;
143 ASN1_SEQUENCE(ASN1_UINT64_DATA) = {
144 ASN1_EMBED(ASN1_UINT64_DATA, test_uint64, UINT64),
145 } static_ASN1_SEQUENCE_END(ASN1_UINT64_DATA)
147 IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(ASN1_UINT64_DATA)
148 IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(ASN1_UINT64_DATA)
150 static int test_uint64(void)
152 const unsigned char *p = t_invalid_zero;
153 ASN1_UINT64_DATA *dectst =
154 d2i_ASN1_UINT64_DATA(NULL, &p, sizeof(t_invalid_zero));
159 ASN1_UINT64_DATA_free(dectst);
163 int setup_tests(void)
165 #if OPENSSL_API_COMPAT < 0x10200000L
168 ADD_TEST(test_int32);
169 ADD_TEST(test_uint32);
170 ADD_TEST(test_int64);
171 ADD_TEST(test_uint64);