| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <stdint.h> |
| 17 |
|
| 18 |
#include "crypto/s2n_ecc_evp.h" |
| 19 |
#include "s2n_test.h" |
| 20 |
#include "stuffer/s2n_stuffer.h" |
| 21 |
#include "testlib/s2n_testlib.h" |
| 22 |
#include "tls/extensions/s2n_key_share.h" |
| 23 |
#include "tls/s2n_tls.h" |
| 24 |
#include "utils/s2n_safety.h" |
| 25 |
|
| 26 |
int main(int argc, char **argv) |
| 27 |
{ |
| 28 |
BEGIN_TEST(); |
| 29 |
EXPECT_SUCCESS(s2n_disable_tls13_in_test()); |
| 30 |
const struct s2n_ecc_named_curve *test_curve = s2n_all_supported_curves_list[0]; |
| 31 |
|
| 32 |
|
| 33 |
{ |
| 34 |
struct s2n_stuffer out = { 0 }; |
| 35 |
|
| 36 |
struct s2n_ecc_evp_params ecc_evp_params; |
| 37 |
ecc_evp_params.negotiated_curve = test_curve; |
| 38 |
ecc_evp_params.evp_pkey = NULL; |
| 39 |
|
| 40 |
EXPECT_SUCCESS(s2n_stuffer_alloc(&out, test_curve->share_size + 4)); |
| 41 |
EXPECT_SUCCESS(s2n_ecdhe_parameters_send(&ecc_evp_params, &out)); |
| 42 |
S2N_STUFFER_READ_EXPECT_EQUAL(&out, test_curve->iana_id, uint16); |
| 43 |
S2N_STUFFER_READ_EXPECT_EQUAL(&out, test_curve->share_size, uint16); |
| 44 |
EXPECT_EQUAL(s2n_stuffer_data_available(&out), test_curve->share_size); |
| 45 |
|
| 46 |
EXPECT_SUCCESS(s2n_ecc_evp_params_free(&ecc_evp_params)); |
| 47 |
EXPECT_SUCCESS(s2n_stuffer_free(&out)); |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
{ |
| 52 |
struct s2n_stuffer out = { 0 }; |
| 53 |
|
| 54 |
struct s2n_ecc_evp_params ecc_evp_params; |
| 55 |
const struct s2n_ecc_named_curve bad_curve = { |
| 56 |
.iana_id = 12345, |
| 57 |
.libcrypto_nid = 0, |
| 58 |
.name = test_curve->name, |
| 59 |
.share_size = test_curve->share_size |
| 60 |
}; |
| 61 |
|
| 62 |
ecc_evp_params.negotiated_curve = &bad_curve; |
| 63 |
ecc_evp_params.evp_pkey = NULL; |
| 64 |
|
| 65 |
EXPECT_SUCCESS(s2n_stuffer_alloc(&out, bad_curve.share_size + 4)); |
| 66 |
|
| 67 |
EXPECT_FAILURE(s2n_ecdhe_parameters_send(&ecc_evp_params, &out)); |
| 68 |
|
| 69 |
EXPECT_SUCCESS(s2n_ecc_evp_params_free(&ecc_evp_params)); |
| 70 |
EXPECT_SUCCESS(s2n_stuffer_free(&out)); |
| 71 |
}; |
| 72 |
|
| 73 |
END_TEST(); |
| 74 |
} |