Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-2026 DMTF. All rights reserved.
4 : * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5 : **/
6 :
7 : #include "internal/libspdm_secured_message_lib.h"
8 :
9 102 : void *libspdm_secured_message_dhe_new(spdm_version_number_t spdm_version,
10 : uint16_t dhe_named_group, bool is_initiator)
11 : {
12 102 : return libspdm_dhe_new(spdm_version, dhe_named_group, is_initiator);
13 : }
14 :
15 102 : void libspdm_secured_message_dhe_free(uint16_t dhe_named_group, void *dhe_context)
16 : {
17 102 : libspdm_dhe_free(dhe_named_group, dhe_context);
18 102 : }
19 :
20 102 : bool libspdm_secured_message_dhe_generate_key(uint16_t dhe_named_group,
21 : void *dhe_context,
22 : uint8_t *public_key,
23 : size_t *public_key_size)
24 : {
25 102 : return libspdm_dhe_generate_key(dhe_named_group, dhe_context, public_key, public_key_size);
26 : }
27 :
28 31 : bool libspdm_secured_message_dhe_compute_key(
29 : uint16_t dhe_named_group, void *dhe_context,
30 : const uint8_t *peer_public, size_t peer_public_size,
31 : void *spdm_secured_message_context)
32 : {
33 : libspdm_secured_message_context_t *secured_message_context;
34 : uint8_t final_key[LIBSPDM_MAX_DHE_SS_SIZE];
35 : size_t final_key_size;
36 : bool ret;
37 :
38 31 : secured_message_context = spdm_secured_message_context;
39 :
40 31 : final_key_size = sizeof(final_key);
41 31 : ret = libspdm_dhe_compute_key(dhe_named_group, dhe_context, peer_public,
42 : peer_public_size, final_key,
43 : &final_key_size);
44 31 : if (!ret) {
45 0 : return ret;
46 : }
47 31 : libspdm_copy_mem(secured_message_context->master_secret.shared_secret,
48 : sizeof(secured_message_context->master_secret.shared_secret),
49 : final_key, final_key_size);
50 31 : libspdm_zero_mem(final_key, final_key_size);
51 31 : secured_message_context->shared_key_size = final_key_size;
52 31 : return true;
53 : }
|