Debian Codegraph @

crt/s2n/tests/testlib/s2n_testlib_ecc_keys.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 "stuffer/s2n_stuffer.h"
17 #include "testlib/s2n_testlib.h"
18 #include "utils/s2n_safety.h"
19
20 int s2n_public_ecc_keys_are_equal(struct s2n_ecc_evp_params *params_1, struct s2n_ecc_evp_params *params_2)
21 {
22 POSIX_ENSURE_REF(params_1);
23 POSIX_ENSURE_REF(params_2);
24
25 struct s2n_stuffer point_stuffer = { 0 };
26 int size = params_1->negotiated_curve->share_size;
27
28 if (params_1->negotiated_curve != params_2->negotiated_curve) {
29 return 0;
30 }
31
32 POSIX_GUARD(s2n_stuffer_alloc(&point_stuffer, size * 2));
33
34 uint8_t *point_1 = s2n_stuffer_raw_write(&point_stuffer, 0);
35 POSIX_GUARD(s2n_ecc_evp_write_params_point(params_1, &point_stuffer));
36
37 uint8_t *point_2 = s2n_stuffer_raw_write(&point_stuffer, 0);
38 POSIX_GUARD(s2n_ecc_evp_write_params_point(params_2, &point_stuffer));
39
40 int result = memcmp(point_1, point_2, size) == 0;
41
42 POSIX_GUARD(s2n_stuffer_free(&point_stuffer));
43
44 return result;
45 }