Debian Codegraph @

crt/s2n/tests/unit/s2n_fips_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include "crypto/s2n_fips.h"
17
18 #include "api/s2n.h"
19 #include "crypto/s2n_libcrypto.h"
20 #include "s2n_test.h"
21
22 int main()
23 {
24 BEGIN_TEST_NO_INIT();
25
26 /* s2n_get_fips_mode() fails before init */
27 {
28 s2n_fips_mode fips_mode = S2N_FIPS_MODE_ENABLED;
29 EXPECT_FAILURE_WITH_ERRNO(s2n_get_fips_mode(&fips_mode), S2N_ERR_NOT_INITIALIZED);
30 EXPECT_EQUAL(fips_mode, S2N_FIPS_MODE_DISABLED);
31 }
32
33 EXPECT_SUCCESS(s2n_init());
34
35 /* Test s2n_get_fips_mode() after init */
36 {
37 /* Safety */
38 EXPECT_FAILURE_WITH_ERRNO(s2n_get_fips_mode(NULL), S2N_ERR_NULL);
39
40 /* FIPS mode matches s2n_is_in_fips_mode() */
41 {
42 s2n_fips_mode fips_mode = S2N_FIPS_MODE_DISABLED;
43 EXPECT_SUCCESS(s2n_get_fips_mode(&fips_mode));
44
45 if (s2n_is_in_fips_mode()) {
46 EXPECT_EQUAL(fips_mode, S2N_FIPS_MODE_ENABLED);
47 } else {
48 EXPECT_EQUAL(fips_mode, S2N_FIPS_MODE_DISABLED);
49 }
50 }
51 }
52
53 END_TEST();
54 }