aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/aesni/raw.h
blob: fb29ce40ab660f1d7074a383a26cfcff9c100bbc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
 * \file
 * \author Egor Tensin <Egor.Tensin@gmail.com>
 * \date 2015
 * \copyright This file is licensed under the terms of the MIT License.
 *            See LICENSE.txt for details.
 *
 * \brief *Don't use.* Declares "raw" 128-bit block encryption/decryption
 * functions.
 */

#pragma once

/**
 * \defgroup aesni_raw_api Raw API
 * \brief *Don't use.* "Raw" 128-bit block encryption/decryption functions.
 * \ingroup aesni
 * \{
 *
 * For each of AES-128/192/256, four functions are defined:
 *
 * * a key schedule "expansion" function to prepare for encryption,
 * * a 128-bit block encryption function using the key schedule,
 * * a key schedule "inversion" function to prepare for decryption,
 * * a 128-bit block decryption function using the "inverted" key schedule.
 *
 * The functions, respectively, are:
 *
 * * `aesni_raw_expand_key_scheduleNNN`,
 * * `aesni_raw_encrypt_blockNNN`,
 * * `aesni_raw_invert_key_scheduleNNN`,
 * * `aesni_raw_decrypt_blockNNN`,
 *
 * where `NNN` is key length (either `128`, `192` or `256`).
 */

#include "data.h"

#ifdef __cplusplus
extern "C"
{
#endif

/**
 * \defgroup aesni_raw_api_aes128 AES-128
 * \{
 */

/**
 * \brief Expands a key schedule for AES-128 encryption.
 *
 * \param[in] key The AES-128 key.
 * \param[out] key_schedule The AES-128 encryption key schedule. Must not be
 * `NULL`.
 */
void __fastcall aesni_raw_expand_key_schedule128(
    AesNI_Block128 key,
    AesNI_KeySchedule128* key_schedule);

/**
 * \brief "Inverts" an AES-128 key schedule to prepare for decryption.
 *
 * \param[in] key_schedule The AES-128 encryption key schedule. Must not be
 * `NULL`.
 * \param[out] inverted_schedule The AES-128 decryption key schedule. Must not
 * be `NULL`.
 */
void __fastcall aesni_raw_invert_key_schedule128(
    AesNI_KeySchedule128* key_schedule,
    AesNI_KeySchedule128* inverted_schedule);

/**
 * \brief Encrypts a 128-bit block using AES-128.
 *
 * \param[in] plain The plaintext to be encrypted.
 * \param[in] key_schedule The AES-128 encryption key schedule. Must not be
 * `NULL`.
 * \return The encrypted 128-bit ciphertext.
 */
AesNI_Block128 __fastcall aesni_raw_encrypt_block128(
    AesNI_Block128 plain,
    AesNI_KeySchedule128* key_schedule);

/**
 * \brief Decrypts a 128-bit block using AES-128.
 *
 * \param[in] cipher The ciphertext to be decrypted.
 * \param[in] inverted_schedule The AES-128 decryption key schedule. Must not
 * be `NULL`.
 * \return The decrypted 128-bit plaintext.
 */
AesNI_Block128 __fastcall aesni_raw_decrypt_block128(
    AesNI_Block128 cipher,
    AesNI_KeySchedule128* inverted_schedule);

/**
 * \}
 *
 * \defgroup aesni_raw_api_aes192 AES-192
 * \{
 */

/**
 * \brief Expands a key schedule for AES-192 encryption.
 *
 * \param[in] key_lo The least significant part of the AES-192 key.
 * \param[in] key_hi The most significant part of the AES-192 key.
 * \param[out] key_schedule The AES-192 encryption key schedule. Must not be
 * `NULL`.
 */
void __fastcall aesni_raw_expand_key_schedule192(
    AesNI_Block128 key_lo,
    AesNI_Block128 key_hi,
    AesNI_KeySchedule192* key_schedule);

/**
 * \brief "Inverts" an AES-192 key schedule to prepare for decryption.
 *
 * \param[in] key_schedule The AES-192 encryption key schedule. Must not be
 * `NULL`.
 * \param[out] inverted_schedule The AES-192 decryption key schedule. Must not
 * be `NULL`.
 */
void __fastcall aesni_raw_invert_key_schedule192(
    AesNI_KeySchedule192* key_schedule,
    AesNI_KeySchedule192* inverted_schedule);

/**
 * \brief Encrypts a 128-bit block using AES-192.
 *
 * \param[in] plain The plaintext to be encrypted.
 * \param[in] key_schedule The AES-192 encryption key schedule. Must not be
 * `NULL`.
 * \return The encrypted 128-bit ciphertext.
 */
AesNI_Block128 __fastcall aesni_raw_encrypt_block192(
    AesNI_Block128 plain,
    AesNI_KeySchedule192* key_schedule);

/**
 * \brief Decrypts a 128-bit block using AES-192.
 *
 * \param[in] cipher The ciphertext to be decrypted.
 * \param[in] inverted_schedule The AES-192 decryption key schedule. Must not
 * be `NULL`.
 * \return The decrypted 128-bit plaintext.
 */
AesNI_Block128 __fastcall aesni_raw_decrypt_block192(
    AesNI_Block128 cipher,
    AesNI_KeySchedule192* inverted_schedule);

/**
 * \}
 *
 * \defgroup aesni_raw_api_aes256 AES-256
 * \{
 */

/**
 * \brief Expands a key schedule for AES-256 encryption.
 *
 * \param[in] key_lo The least significant part of the AES-256 key.
 * \param[in] key_hi The most significant part of the AES-256 key.
 * \param[out] key_schedule The AES-256 encryption key schedule. Must not be
 * `NULL`.
 */
void __fastcall aesni_raw_expand_key_schedule256(
    AesNI_Block128 key_lo,
    AesNI_Block128 key_hi,
    AesNI_KeySchedule256* key_schedule);

/**
 * \brief "Inverts" a AES-256 key schedule to prepare for decryption.
 *
 * \param[in] key_schedule The AES-256 encryption key schedule. Must not be
 * `NULL`.
 * \param[out] inverted_schedule The AES-256 decryption key schedule. Must not
 * be `NULL`.
 */
void __fastcall aesni_raw_invert_key_schedule256(
    AesNI_KeySchedule256* key_schedule,
    AesNI_KeySchedule256* inverted_schedule);

/**
 * \brief Encrypts a 128-bit block using AES-256.
 *
 * \param[in] plain The plaintext to be encrypted.
 * \param[in] key_schedule The AES-256 encryption key schedule. Must not be
 * `NULL`.
 * \return The encrypted 128-bit ciphertext.
 */
AesNI_Block128 __fastcall aesni_raw_encrypt_block256(
    AesNI_Block128 plain,
    AesNI_KeySchedule256* key_schedule);

/**
 * \brief Decrypts a 128-bit block using AES-256.
 *
 * \param[in] cipher The ciphertext to be decrypted.
 * \param[in] inverted_schedule The AES-256 decryption key schedule. Must not
 * be `NULL`.
 * \return The decrypted 128-bit plaintext.
 */
AesNI_Block128 __fastcall aesni_raw_decrypt_block256(
    AesNI_Block128 cipher,
    AesNI_KeySchedule256* inverted_schedule);

/**
 * \}
 */

#ifdef __cplusplus
}
#endif

/**
 * \}
 */