| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/cal/hkdf.h> |
| 6 |
|
| 7 |
#ifndef BYO_CRYPTO |
| 8 |
|
| 9 |
extern int aws_hkdf_derive_impl( |
| 10 |
struct aws_allocator *allocator, |
| 11 |
enum aws_hkdf_hmac_type hmac_type, |
| 12 |
struct aws_byte_cursor ikm, |
| 13 |
struct aws_byte_cursor salt, |
| 14 |
struct aws_byte_cursor info, |
| 15 |
struct aws_byte_buf *out_buf, |
| 16 |
size_t length); |
| 17 |
|
| 18 |
#else |
| 19 |
|
| 20 |
int aws_hkdf_derive_impl( |
| 21 |
struct aws_allocator *allocator, |
| 22 |
enum aws_hkdf_hmac_type hmac_type, |
| 23 |
struct aws_byte_cursor ikm, |
| 24 |
struct aws_byte_cursor salt, |
| 25 |
struct aws_byte_cursor info, |
| 26 |
struct aws_byte_buf *out_buf, |
| 27 |
size_t length) { |
| 28 |
(void)allocator; |
| 29 |
(void)hmac_type; |
| 30 |
(void)ikm; |
| 31 |
(void)salt; |
| 32 |
(void)info; |
| 33 |
(void)out_buf; |
| 34 |
(void)length; |
| 35 |
abort(); |
| 36 |
} |
| 37 |
|
| 38 |
#endif |
| 39 |
|
| 40 |
static aws_hkdf_fn *s_hkdf_impl_fn = aws_hkdf_derive_impl; |
| 41 |
|
| 42 |
AWS_CAL_API void aws_set_hkdf_fn(aws_hkdf_fn *fn) { |
| 43 |
s_hkdf_impl_fn = fn; |
| 44 |
} |
| 45 |
|
| 46 |
int aws_hkdf_derive( |
| 47 |
struct aws_allocator *allocator, |
| 48 |
enum aws_hkdf_hmac_type hmac_type, |
| 49 |
struct aws_byte_cursor ikm, |
| 50 |
struct aws_byte_cursor salt, |
| 51 |
struct aws_byte_cursor info, |
| 52 |
struct aws_byte_buf *out_buf, |
| 53 |
size_t length) { |
| 54 |
|
| 55 |
AWS_ERROR_PRECONDITION(allocator); |
| 56 |
AWS_ERROR_PRECONDITION(hmac_type == HKDF_HMAC_SHA512); |
| 57 |
AWS_ERROR_PRECONDITION(ikm.len != 0); |
| 58 |
AWS_ERROR_PRECONDITION(out_buf); |
| 59 |
|
| 60 |
return s_hkdf_impl_fn(allocator, hmac_type, ikm, salt, info, out_buf, length); |
| 61 |
} |