1 /*
2    Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
3    file at the top-level directory of this distribution.
4 
5    Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6    http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7    <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8    option. This file may not be copied, modified, or distributed
9    except according to those terms.
10 */
11 
12 #include "edhoc.h"
13 
14 #include "edhoc/hkdf_info.h"
15 #include "edhoc/okm.h"
16 
17 #include "common/crypto_wrapper.h"
18 #include "common/oscore_edhoc_error.h"
19 
20 #include "common/print_util.h"
21 
okm_calc(enum hash_alg hash_alg,const uint8_t * prk,uint32_t prk_len,const uint8_t * th,uint32_t th_len,const char * label,uint8_t * context,uint32_t context_len,uint8_t * okm,uint32_t okm_len)22 enum err okm_calc(enum hash_alg hash_alg, const uint8_t *prk, uint32_t prk_len,
23 		  const uint8_t *th, uint32_t th_len, const char *label,
24 		  uint8_t *context, uint32_t context_len, uint8_t *okm,
25 		  uint32_t okm_len)
26 {
27 	uint8_t info[INFO_DEFAULT_SIZE];
28 	uint32_t info_len = sizeof(info);
29 
30 	TRY(create_hkdf_info(th, th_len, label, context, context_len, okm_len,
31 			     (uint8_t *)&info, &info_len));
32 	PRINT_ARRAY("info", info, info_len);
33 	TRY(hkdf_expand(hash_alg, prk, prk_len, (uint8_t *)&info, info_len, okm,
34 			okm_len));
35 	return ok;
36 }
37