Debian Codegraph @

crt/s2n/tests/features/S2N_LIBCRYPTO_SUPPORTS_ENGINE.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 /*
17 * This feature probe checks if the linked libcrypto has ENGINE support.
18 * https://docs.openssl.org/1.0.2/man3/engine/
19 */
20
21 /*
22 * We would always expect the `openssl/engine.h` header to be available.
23 * However, some platforms (CentOS 10, Fedora 41, and RHEL 10) have reportedly
24 * been removing the `openssl/engine.h` header.
25 *
26 * See the related issues:
27 * - https://github.com/aws/s2n-tls/pull/4705
28 * - https://github.com/aws/s2n-tls/pull/4873
29 */
30 #include <openssl/engine.h>
31 /* LibreSSL requires <openssl/rand.h> include.
32 * https://github.com/aws/s2n-tls/issues/153#issuecomment-129651643
33 */
34 #include <openssl/rand.h>
35
36 int s2n_noop_rand(unsigned char *buf, int num)
37 {
38 return 1;
39 }
40
41 int main()
42 {
43 /* Init usage in utils/s2n_random.c */
44 ENGINE *e = ENGINE_new();
45 ENGINE_set_id(e, "id");
46 ENGINE_set_name(e, "name");
47 ENGINE_set_flags(e, ENGINE_FLAGS_NO_REGISTER_ALL);
48 ENGINE_set_init_function(e, NULL);
49 ENGINE_set_RAND(e, NULL);
50 ENGINE_add(e);
51 ENGINE_init(e);
52 ENGINE_set_default(e, ENGINE_METHOD_RAND);
53
54 /* Cleanup usage in utils/s2n_random.c */
55 ENGINE_remove(e);
56 ENGINE_finish(e);
57 ENGINE_unregister_RAND(e);
58 ENGINE_free(e);
59 ENGINE_cleanup();
60 RAND_set_rand_engine(NULL);
61 RAND_set_rand_method(NULL);
62
63 /* RAND_METHOD is gated behind S2N_LIBCRYPTO_SUPPORTS_ENGINE because AWS-LC has
64 * a different signature for RAND_METHOD and fails to compile.
65 *
66 * - AWS-LC: https://github.com/aws/aws-lc/blob/main/include/openssl/rand.h#L124
67 * - OpenSSL: https://github.com/openssl/openssl/blob/master/include/openssl/rand.h#L42
68 */
69 RAND_METHOD s2n_noop_rand_method = {
70 .seed = NULL,
71 .bytes = s2n_noop_rand,
72 .cleanup = NULL,
73 .add = NULL,
74 .pseudorand = s2n_noop_rand,
75 .status = NULL
76 };
77
78 return 0;
79 }