Skip to content
File

Blob: firmware/platform/tests/crypto_profile/native.c

c47 lines
1#include <assert.h>
2#include <stdlib.h>
3#include "radio_bridge.h"
4 
5/* Separate object so the test exercises the same link-time wraps as the device. */
6extern unsigned test_lock_depth;
7extern int64_t test_now_us;
8void test_allocate(size_t count, size_t size);
9void test_crypto_allocations(int32_t bits);
10 
11void *esp_mbedtls_mem_calloc(size_t count, size_t size)
12{
13 assert(test_lock_depth == 0);
14 return count == 99 ? NULL : calloc(count, size);
15}
16 
17int32_t radio_crypto_hmac(int32_t bits, const uint8_t *key, size_t key_length,
18 const radio_crypto_part *parts, size_t count, uint8_t *output,
19 size_t capacity)
20{
21 assert(key && key_length == 16 && parts && count == 1);
22 assert(parts[0].bytes && parts[0].length == 4 && output && capacity == 64);
23 test_crypto_allocations(bits);
24 test_now_us += 10;
25 return bits == 384 ? -7 : 0;
26}
27 
28int32_t radio_crypto_aes_ctr(const uint8_t *key, size_t key_length, const uint8_t iv[16],
29 const uint8_t *input, size_t length, uint8_t *output, size_t capacity)
30{
31 assert(key && key_length == 16 && iv && input && length == 4 && output && capacity == 64);
32 test_allocate(1, 16);
33 test_now_us += 20;
34 return 0;
35}
36 
37int32_t radio_crypto_aes_gcm(int32_t decrypt, const uint8_t *key, size_t key_length,
38 const uint8_t iv[12], const uint8_t *aad, size_t aad_length,
39 const uint8_t *input, size_t length, uint8_t *output, size_t capacity)
40{
41 assert(key && key_length == 16 && iv && aad && aad_length == 4);
42 assert(input && length == 4 && output && capacity == 64);
43 test_allocate(1, 20);
44 test_now_us += 30;
45 return decrypt ? -9 : 0;
46}