]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/cmp_asn_test.c
test: remove the just added, but now unrealistic, shake128 OAEP tests
[thirdparty/openssl.git] / test / cmp_asn_test.c
CommitLineData
7960dbec 1/*
da1c088f 2 * Copyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved.
7960dbec
DDO
3 * Copyright Nokia 2007-2019
4 * Copyright Siemens AG 2015-2019
5 *
6 * Licensed under the Apache License 2.0 (the "License"). You may not use
7 * this file except in compliance with the License. You can obtain a copy
8 * in the file LICENSE in the source distribution or at
9 * https://www.openssl.org/source/license.html
10 */
11
20f8bc72 12#include "helpers/cmp_testlib.h"
7960dbec
DDO
13
14static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH];
15
16typedef struct test_fixture {
17 const char *test_case_name;
18 int expected;
19 ASN1_OCTET_STRING *src_string;
20 ASN1_OCTET_STRING *tgt_string;
21
22} CMP_ASN_TEST_FIXTURE;
23
24static CMP_ASN_TEST_FIXTURE *set_up(const char *const test_case_name)
25{
26 CMP_ASN_TEST_FIXTURE *fixture;
7960dbec 27
7960dbec 28 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
4dde554c 29 return NULL;
7960dbec 30 fixture->test_case_name = test_case_name;
7960dbec
DDO
31 return fixture;
32}
33
34static void tear_down(CMP_ASN_TEST_FIXTURE *fixture)
35{
36 ASN1_OCTET_STRING_free(fixture->src_string);
37 if (fixture->tgt_string != fixture->src_string)
38 ASN1_OCTET_STRING_free(fixture->tgt_string);
39
40 OPENSSL_free(fixture);
41}
42
3dbc5156 43static int execute_cmp_asn1_get_int_test(CMP_ASN_TEST_FIXTURE *fixture)
7960dbec 44{
2c8d9f19 45 int res = 0;
7960dbec 46 ASN1_INTEGER *asn1integer = ASN1_INTEGER_new();
2c8d9f19
DDO
47 const int good_int = 77;
48 const int64_t max_int = INT_MAX;
316c8daf
P
49
50 if (!TEST_ptr(asn1integer))
2c8d9f19
DDO
51 return res;
52
53 if (!TEST_true(ASN1_INTEGER_set(asn1integer, good_int))) {
a4347a9a
P
54 ASN1_INTEGER_free(asn1integer);
55 return 0;
56 }
2c8d9f19
DDO
57 res = TEST_int_eq(good_int, ossl_cmp_asn1_get_int(asn1integer));
58 if (res == 0)
59 goto err;
60
61 res = 0;
62 if (!TEST_true(ASN1_INTEGER_set_int64(asn1integer, max_int + 1)))
63 goto err;
64 res = TEST_int_eq(-2, ossl_cmp_asn1_get_int(asn1integer));
65
66 err:
7960dbec 67 ASN1_INTEGER_free(asn1integer);
316c8daf 68 return res;
7960dbec
DDO
69}
70
71static int test_cmp_asn1_get_int(void)
72{
73 SETUP_TEST_FIXTURE(CMP_ASN_TEST_FIXTURE, set_up);
74 fixture->expected = 1;
75 EXECUTE_TEST(execute_cmp_asn1_get_int_test, tear_down);
76 return result;
77}
78
79static int execute_CMP_ASN1_OCTET_STRING_set1_test(CMP_ASN_TEST_FIXTURE *
80 fixture)
81{
82 if (!TEST_int_eq(fixture->expected,
83 ossl_cmp_asn1_octet_string_set1(&fixture->tgt_string,
84 fixture->src_string)))
85 return 0;
86 if (fixture->expected != 0)
87 return TEST_int_eq(0, ASN1_OCTET_STRING_cmp(fixture->tgt_string,
88 fixture->src_string));
89 return 1;
90}
91
92static int test_ASN1_OCTET_STRING_set(void)
93{
94 SETUP_TEST_FIXTURE(CMP_ASN_TEST_FIXTURE, set_up);
95 fixture->expected = 1;
96 if (!TEST_ptr(fixture->tgt_string = ASN1_OCTET_STRING_new())
97 || !TEST_ptr(fixture->src_string = ASN1_OCTET_STRING_new())
98 || !TEST_true(ASN1_OCTET_STRING_set(fixture->src_string, rand_data,
99 sizeof(rand_data)))) {
100 tear_down(fixture);
101 fixture = NULL;
102 }
103 EXECUTE_TEST(execute_CMP_ASN1_OCTET_STRING_set1_test, tear_down);
104 return result;
105}
106
107static int test_ASN1_OCTET_STRING_set_tgt_is_src(void)
108{
109 SETUP_TEST_FIXTURE(CMP_ASN_TEST_FIXTURE, set_up);
110 fixture->expected = 1;
111 if (!TEST_ptr(fixture->src_string = ASN1_OCTET_STRING_new())
112 || !(fixture->tgt_string = fixture->src_string)
113 || !TEST_true(ASN1_OCTET_STRING_set(fixture->src_string, rand_data,
114 sizeof(rand_data)))) {
115 tear_down(fixture);
116 fixture = NULL;
117 }
118 EXECUTE_TEST(execute_CMP_ASN1_OCTET_STRING_set1_test, tear_down);
119 return result;
120}
121
7960dbec
DDO
122void cleanup_tests(void)
123{
124 return;
125}
126
127int setup_tests(void)
128{
4dde554c 129 RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH);
7960dbec
DDO
130 /* ASN.1 related tests */
131 ADD_TEST(test_cmp_asn1_get_int);
132 ADD_TEST(test_ASN1_OCTET_STRING_set);
133 ADD_TEST(test_ASN1_OCTET_STRING_set_tgt_is_src);
7960dbec
DDO
134 return 1;
135}