Software APIs
sw
device
tests
crypto
aes_gcm_testutils.h
1
// Copyright lowRISC contributors (OpenTitan project).
2
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3
// SPDX-License-Identifier: Apache-2.0
4
5
#ifndef OPENTITAN_SW_DEVICE_TESTS_CRYPTO_AES_GCM_TESTUTILS_H_
6
#define OPENTITAN_SW_DEVICE_TESTS_CRYPTO_AES_GCM_TESTUTILS_H_
7
8
#include <
stdbool.h
>
9
10
#include "sw/device/lib/crypto/drivers/aes.h"
11
12
#ifdef __cplusplus
13
extern
"C"
{
14
#endif
// __cplusplus
15
16
typedef
struct
aes_gcm_test
{
17
/**
18
* Key length in words.
19
*/
20
size_t
key_len
;
21
/**
22
* Key material (length = key_len).
23
*/
24
const
uint32_t *
key
;
25
/**
26
* IV and length (in bytes). If IV length is < 16 then the last bytes are
27
* ignored.
28
*/
29
size_t
iv_len
;
30
uint8_t iv[16];
31
/**
32
* Plaintext and length (in bytes).
33
*/
34
size_t
plaintext_len
;
35
uint8_t *plaintext;
36
/**
37
* Authenticated data and length (in bytes).
38
*/
39
size_t
aad_len
;
40
uint8_t *aad;
41
/**
42
* Ciphertext (same length as plaintext).
43
*/
44
uint8_t *
ciphertext
;
45
/**
46
* Authentication tag and length (in bytes). If the length is < 16 then the
47
* last bytes are ignored.
48
*/
49
size_t
tag_len
;
50
uint8_t tag[16];
51
}
aes_gcm_test_t
;
52
53
/**
54
* Call AES-GCM authenticated encryption for the given test vector.
55
*
56
* @param test The test vector to run
57
* @param streaming Whether to use the streaming interface.
58
* @param[out] cycles Cycle count for the encrypt() call
59
* @return Test status
60
*/
61
status_t
aes_gcm_testutils_encrypt(
const
aes_gcm_test_t
*
test
,
bool
streaming,
62
uint32_t *cycles);
63
64
/**
65
* Call AES-GCM authenticated decryption for the given test vector.
66
*
67
* This function can be used to run negative tests on authentication, i.e. to
68
* check that invalid tags fail. Simply set an invalid tag in the test vector
69
* and check that `tag_valid` is false instead of true.
70
*
71
* @param test The test vector to run
72
* @param streaming Whether to use the streaming interface.
73
* @param[out] tag_valid True iff the tag passed its validity check
74
* @param[out] cycles Cycle count for the decrypt() call
75
* @return Test status
76
*/
77
status_t
aes_gcm_testutils_decrypt(
const
aes_gcm_test_t
*
test
,
78
hardened_bool_t
*tag_valid,
bool
streaming,
79
uint32_t *cycles);
80
81
#ifdef __cplusplus
82
}
// extern "C"
83
#endif
// __cplusplus
84
85
#endif
// OPENTITAN_SW_DEVICE_TESTS_CRYPTO_AES_GCM_TESTUTILS_H_
Return to
OpenTitan Documentation