4
* interface for abstract crypto transform
13
#include "crypto_kernel.h"
17
* @defgroup Crypto Cryptography
19
* A simple interface to an abstract cryptographic transform that
20
* provides both confidentiality and message authentication.
26
* @brief applies a crypto transform
28
* The function pointer xfm_func_t points to a function that
29
* implements a crypto transform, and provides a uniform API for
30
* accessing crypto mechanisms.
32
* @param key location of secret key
34
* @param clear data to be authenticated only
36
* @param clear_len length of data to be authenticated only
38
* @param iv location to write the Initialization Vector (IV)
40
* @param protect location of the data to be encrypted and
41
* authenticated (before the function call), and the ciphertext
42
* and authentication tag (after the call)
44
* @param protected_len location of the length of the data to be
45
* encrypted and authenticated (before the function call), and the
46
* length of the ciphertext (after the call)
48
* @param auth_tag location to write auth tag
51
typedef err_status_t (*xfm_func_t)
57
unsigned *protected_len,
62
err_status_t (*xfm_inv_t)
63
(void *key, /* location of secret key */
64
void *clear, /* data to be authenticated only */
65
unsigned clear_len, /* length of data to be authenticated only */
66
void *iv, /* location of iv */
67
void *opaque, /* data to be decrypted and authenticated */
68
unsigned *opaque_len, /* location of the length of data to be
69
* decrypted and authd (before and after)
71
void *auth_tag /* location of auth tag */
74
typedef struct xfm_ctx_t {
79
unsigned auth_tag_len;
82
typedef xfm_ctx_t *xfm_t;
84
#define xfm_get_key_len(xfm) ((xfm)->key_len)
86
#define xfm_get_iv_len(xfm) ((xfm)->iv_len)
88
#define xfm_get_auth_tag_len(xfm) ((xfm)->auth_tag_len)
91
/* cryptoalgo - 5/28 */
93
typedef err_status_t (*cryptoalg_func_t)
103
err_status_t (*cryptoalg_inv_t)
104
(void *key, /* location of secret key */
105
void *clear, /* data to be authenticated only */
106
unsigned clear_len, /* length of data to be authenticated only */
107
void *iv, /* location of iv */
108
void *opaque, /* data to be decrypted and authenticated */
109
unsigned *opaque_len /* location of the length of data to be
110
* decrypted and authd (before and after)
114
typedef struct cryptoalg_ctx_t {
115
cryptoalg_func_t enc;
119
unsigned auth_tag_len;
120
unsigned max_expansion;
123
typedef cryptoalg_ctx_t *cryptoalg_t;
125
#define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len)
127
#define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len)
129
#define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len)