AESCTR.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2024, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file AESCTR.h
34  *
35  * @brief AESCTR driver header
36  *
37  * @anchor ti_drivers_AESCTR_Overview
38  * <h3> Overview </h3>
39  * The Counter (CTR) mode of operation is a generic block cipher mode of operation
40  * that can be used with any block cipher including AES which is used in this
41  * implementation.
42  *
43  * CTR mode encrypts and decrypts messages. It is not required for the message
44  * length to be evenly divisible by the cipher block size. This also means
45  * that padding the message is not required.
46  *
47  * <h3> Operation </h3>
48  * CTR encryption and decryption perform the following steps:
49  * -# Set the counter value to the initial counter value
50  * -# Encrypt the counter value under the symmetric key
51  * -# XOR the encrypted counter value with the input block (plaintext or ciphertext)
52  * -# Increment the counter value. Interpret the byte array as a big-endian number.
53  * -# Repeat steps 2 to 4 until the input is completely processed. If the
54  * input is not evenly divisible by the block size, XOR the last
55  * (u = input length % block size) input bytes with the most significant
56  * u bytes of the last encrypted counter value.
57  *
58  * CTR performs the same steps regardless of whether it is used to
59  * encrypt or decrypt a message. The input merely changes.
60  *
61  * <h3> Choosing Initial Counter Values </h3>
62  * CTR requires that each counter value used to encrypt a block of a message
63  * is unique for each key used. If this requirement is not kept, the
64  * confidentiality of that message block may be compromised.
65  *
66  * There are two general strategies when choosing the initial counter value
67  * of a CTR operation to ensure this requirement holds.
68  *
69  * The first is to choose an initial counter value for the first message
70  * and increment the initial counter value for a subsequent message by
71  * by message length % block length (16-bytes for AES). This effectively
72  * turns a sequence of messages into one long message. If 0 is chosen
73  * as the initial counter value, up to 2^128 - 1 blocks may be encrypted before
74  * key rotation is mandatory.
75  *
76  * The second is to split the initial counter value into a nonce and
77  * counter section. The nonce of length n bits must be unique per message.
78  * This allows for up to 2^n - 1 messages to be encrypted before
79  * key rotation is required. The counter section of length c is incremented
80  * as usual. This limits messages to a length of at most 2^c - 1 blocks.
81  * n and c must be chosen such that n + c = block length in bits
82  * (128 bits for AES) holds.
83  *
84  * @anchor ti_drivers_AESCTR_Usage
85  * <h3> Usage </h3>
86  * <h4> Before starting a CTR operation </h4>
87  *
88  * Before starting a CTR operation, the application must do the following:
89  * - Call #AESCTR_init() to initialize the driver
90  * - Call #AESCTR_Params_init() to initialize the #AESCTR_Params to default values.
91  * - Modify the #AESCTR_Params as desired
92  * - Call #AESCTR_open() to open an instance of the driver
93  * - Initialize a CryptoKey. These opaque data structures are representations
94  * of keying material and its storage. Depending on how the keying material
95  * is stored (RAM or flash, key store), the CryptoKey must be
96  * initialized differently. The AESCTR API can handle all types of CryptoKey.
97  * However, not all device-specific implementations support all types of CryptoKey.
98  * Devices without a key store will not support CryptoKeys with keying material
99  * stored in a key store for example.
100  * All devices support plaintext CryptoKeys.
101  * - Initialize a single-step AESCTR operation using #AESCTR_OneStepOperation_init()
102  * which is equivalent to the deprecated #AESCTR_Operation_init(). If it's
103  * a segmented AESCTR operation, use #AESCTR_SegmentedOperation_init() instead.
104  * Then set all the fields of the one-step or segmented operation struct accordingly.
105  *
106  * ## Device-Specific Requirements #
107  *
108  * For CC27XX devices, CTR operations leveraging the HSM engine
109  * (key encoding suffixed with _HSM) have the following requirements:
110  * - Output buffer address must be 32-bit aligned.
111  * - Input length must be a block-size (16-byte) multiple.
112  *
113  * <h4> Starting a CTR operation </h4>
114  *
115  * The AESCTR_oneStepEncrypt() and AESCTR_oneStepDecrypt() functions perform a CTR operation
116  * in a single call.
117  *
118  * <h4> After the CTR operation completes </h4>
119  *
120  * After the CTR operation completes, the application should either start
121  * another operation or close the driver by calling #AESCTR_close().
122  *
123  * @anchor ti_drivers_AESCTR_Synopsis
124  * ## Synopsis
125  *
126  * @anchor ti_drivers_AESCTR_Synopsis_Code
127  * @code
128  *
129  * // Import AESCTR Driver definitions
130  * #include <ti/drivers/AESCTR.h>
131  *
132  * // Define name for AESCTR channel index
133  * #define AESCTR_INSTANCE 0
134  *
135  * AESCTR_init();
136  *
137  * handle = AESCTR_open(AESCTR_INSTANCE, NULL);
138  *
139  * // Initialize symmetric key
140  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
141  *
142  * // Set up AESCTR_Operation
143  * AESCTR_OneStepOperation_init(&operation);
144  * operation.key = &cryptoKey;
145  * operation.input = plaintext;
146  * operation.output = ciphertext;
147  * operation.inputLength = sizeof(plaintext);
148  * operation.initialCounter = initialCounter;
149  *
150  * encryptionResult = AESCTR_oneStepEncrypt(handle, &operation);
151  *
152  * AESCTR_close(handle);
153  * @endcode
154  *
155  * @anchor ti_drivers_AESCTR_Examples
156  * <h4> Examples </h4>
157  *
158  * <h5> One step CTR encryption with plaintext CryptoKey in blocking return mode </h5>
159  * @code
160  *
161  * #include <ti/drivers/AESCTR.h>
162  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
163  *
164  * ...
165  *
166  * AESCTR_Handle handle;
167  * CryptoKey cryptoKey;
168  * int_fast16_t encryptionResult;
169  *
170  * // For example purposes only. Generate IVs in a non-static way in practice.
171  * // Test vector from NIST SP 800-38A
172  * uint8_t initialCounter[16] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
173  * 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
174  * uint8_t plaintext[64] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
175  * 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
176  * 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
177  * 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
178  * 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
179  * 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
180  * 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
181  * 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10};
182  * uint8_t ciphertext[sizeof(plaintext)];
183  * uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
184  * 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
185  *
186  * handle = AESCTR_open(0, NULL);
187  *
188  * if (handle == NULL) {
189  * // handle error
190  * while(1);
191  * }
192  *
193  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
194  *
195  * AESCTR_OneStepOperation operation;
196  * AESCTR_OneStepOperation_init(&operation);
197  *
198  * operation.key = &cryptoKey;
199  * operation.input = plaintext;
200  * operation.output = ciphertext;
201  * operation.inputLength = sizeof(plaintext);
202  * operation.initialCounter = initialCounter;
203  *
204  * encryptionResult = AESCTR_oneStepEncrypt(handle, &operation);
205  *
206  * if (encryptionResult != AESCTR_STATUS_SUCCESS) {
207  * // handle error
208  * while(1);
209  * }
210  *
211  * // The ciphertext should be the following after the encryption operation:
212  * // 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
213  * // 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
214  * // 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
215  * // 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
216  * // 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
217  * // 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
218  * // 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
219  * // 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee
220  *
221  * AESCTR_close(handle);
222  *
223  * @endcode
224  *
225  * <h4> The following code snippet is for CC27XX devices only and leverages the HSM which is a seperate Hardware
226  * Accelerator </h4>
227  *
228  * <h5> One step CTR encryption with plaintext CryptoKey in blocking return mode using the HSM accelerator </h5>
229  * @code
230  *
231  * #include <ti/drivers/AESCTR.h>
232  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
233  *
234  * ...
235  *
236  * AESCTR_Handle handle;
237  * CryptoKey cryptoKey;
238  * int_fast16_t encryptionResult;
239  *
240  * // For example purposes only. Generate IVs in a non-static way in practice.
241  * // Test vector from NIST SP 800-38A
242  * uint8_t initialCounter[16] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
243  * 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
244  * uint8_t plaintext[64] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
245  * 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
246  * 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
247  * 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
248  * 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
249  * 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
250  * 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
251  * 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10};
252  * uint8_t ciphertext[sizeof(plaintext)];
253  * uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
254  * 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
255  *
256  * handle = AESCTR_open(0, NULL);
257  *
258  * if (handle == NULL) {
259  * // handle error
260  * while(1);
261  * }
262  *
263  * CryptoKeyPlaintextHSM_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
264  *
265  * AESCTR_OneStepOperation operation;
266  * AESCTR_OneStepOperation_init(&operation);
267  *
268  * operation.key = &cryptoKey;
269  * operation.input = plaintext;
270  * operation.output = ciphertext;
271  * operation.inputLength = sizeof(plaintext);
272  * operation.initialCounter = initialCounter;
273  *
274  * encryptionResult = AESCTR_oneStepEncrypt(handle, &operation);
275  *
276  * if (encryptionResult != AESCTR_STATUS_SUCCESS) {
277  * // handle error
278  * while(1);
279  * }
280  *
281  * // The ciphertext should be the following after the encryption operation:
282  * // 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
283  * // 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
284  * // 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
285  * // 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
286  * // 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
287  * // 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
288  * // 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
289  * // 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee
290  *
291  * AESCTR_close(handle);
292  *
293  * @endcode
294  *
295  * <h5> One step CTR decryption with plaintext CryptoKey in callback return mode </h5>
296  * @code
297  *
298  * #include <ti/drivers/AESCTR.h>
299  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
300  *
301  * ...
302  *
303  *
304  * void ctrCallback(AESCTR_Handle handle,
305  * int_fast16_t returnValue,
306  * AESCTR_OperationUnion *operation,
307  * AESCTR_OperationType operationType) {
308  *
309  * if (returnValue != AESCTR_STATUS_SUCCESS) {
310  * // handle error
311  * while(1);
312  * }
313  * }
314  * AESCTR_Operation operation;
315  *
316  * void ctrStartFunction(void) {
317  * uint8_t initialCounter[16] = {0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
318  * 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01};
319  * uint8_t ciphertext[] = {0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
320  * 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
321  * 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
322  * 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
323  * 0x25, 0xB2, 0x07, 0x2F};
324  * uint8_t keyingMaterial[] = {0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
325  * 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC};
326  * uint8_t plaintext[sizeof(ciphertext)];
327  *
328  * AESCTR_Handle handle;
329  * AESCTR_Params params;
330  * CryptoKey cryptoKey;
331  * int_fast16_t decryptionResult;
332  *
333  * AESCTR_OneStepOperation operation;
334  *
335  * AESCTR_Params_init(&params);
336  * params.returnBehavior = AESCTR_RETURN_BEHAVIOR_CALLBACK;
337  * params.callbackFxn = ctrCallback;
338  *
339  * handle = AESCTR_open(0, &params);
340  *
341  * if (handle == NULL) {
342  * // handle error
343  * while(1);
344  * }
345  *
346  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
347  *
348  * AESCTR_OneStepOperation_init(&operation); // Optional as all struct members will be set before use.
349  *
350  * operation.key = &cryptoKey;
351  * operation.input = ciphertext;
352  * operation.output = plaintext;
353  * operation.inputLength = sizeof(ciphertext);
354  * operation.initialCounter = initialCounter;
355  *
356  * decryptionResult = AESCTR_oneStepDecrypt(handle, &operation);
357  *
358  * if (decryptionResult != AESCTR_STATUS_SUCCESS) {
359  * // handle error
360  * while(1);
361  * }
362  *
363  * // do other things while CTR operation completes in the background
364  *
365  * // After the operation completes and the callback is invoked, the resultant
366  * // plaintext should be:
367  * // 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
368  * // 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
369  * // 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
370  * // 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
371  * // 0x20, 0x21, 0x22, 0x23
372  *
373  * AESCTR_close(handle);
374  * }
375  *
376  * @endcode
377  *
378  * <h5> Multi-step AES CTR encrypt with plaintext CryptoKey in polling return mode </h5>
379  * @code
380  *
381  * #include <ti/drivers/AESCTR.h>
382  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
383  *
384  * #define AES_BLOCK_SIZE 16 // bytes
385  * ...
386  *
387  * AESCTR_Params params;
388  * AESCTR_Handle handle;
389  * CryptoKey cryptoKey;
390  * int_fast16_t retVal;
391  *
392  * // For example purposes only.
393  * uint8_t plaintext[36] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
394  * 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
395  * 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
396  * 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
397  * 0x20, 0x21, 0x22, 0x23};
398  * uint8_t initialCounter[] = {0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
399  * 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01};
400  * uint8_t keyingMaterial[] = {0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
401  * 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC};
402  * uint8_t ciphertext[sizeof(plaintext)];
403  *
404  * AESCTR_Params_init(&params)
405  * params.returnBehavior = AESCTR_RETURN_BEHAVIOR_POLLING;
406  *
407  * handle = AESCTR_open(0, &params);
408  *
409  * if (handle == NULL) {
410  * // handle error
411  * }
412  *
413  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
414  *
415  * AESCTR_SegmentedOperation operation;
416  * AESCTR_SegmentedOperation_init(&operation); // Optional as all struct members will be set before use.
417  *
418  * retVal = AESCTR_setupEncrypt(handle, &cryptoKey, initialCounter);
419  *
420  * if (retVal != AESCTR_STATUS_SUCCESS) {
421  * // handle error
422  * }
423  *
424  * operation.input = plaintext;
425  * operation.inputLength = AES_BLOCK_SIZE; // Only block multiple lengths are permitted when adding data.
426  * operation.output = ciphertext;
427  *
428  * retVal = AESCTR_addData(handle, &operation);
429  *
430  * if (retVal != AESCTR_STATUS_SUCCESS) {
431  * // handle error
432  * }
433  *
434  * operation.input = plaintext + AES_BLOCK_SIZE;
435  * operation.inputLength = sizeof(plaintext) - AES_BLOCK_SIZE; // Non-block multiple length permitted during
436  * finalization. operation.output = ciphertext + AES_BLOCK_SIZE;
437  *
438  * retVal = AESCTR_finalize(handle, &operation);
439  *
440  * if (retVal != AESCTR_STATUS_SUCCESS) {
441  * // handle error
442  * }
443  *
444  * // Upon successful return, the resulting ciphertext should be:
445  * // 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
446  * // 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
447  * // 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
448  * // 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
449  * // 0x25, 0xB2, 0x07, 0x2F
450  *
451  * AESCTR_close(handle);
452  *
453  * @endcode
454  */
455 
456 #ifndef ti_drivers_AESCTR__include
457 #define ti_drivers_AESCTR__include
458 
459 #include <stddef.h>
460 #include <stdint.h>
461 
462 #include <ti/drivers/AESCommon.h>
464 
465 #ifdef __cplusplus
466 extern "C" {
467 #endif
468 
481 #define AESCTR_STATUS_RESERVED AES_STATUS_RESERVED
482 
489 #define AESCTR_STATUS_SUCCESS AES_STATUS_SUCCESS
490 
497 #define AESCTR_STATUS_ERROR AES_STATUS_ERROR
498 
507 #define AESCTR_STATUS_RESOURCE_UNAVAILABLE AES_STATUS_RESOURCE_UNAVAILABLE
508 
512 #define AESCTR_STATUS_CANCELED AES_STATUS_CANCELED
513 
517 #define AESCTR_STATUS_FEATURE_NOT_SUPPORTED AES_STATUS_FEATURE_NOT_SUPPORTED
518 
522 #define AESCTR_STATUS_KEYSTORE_INVALID_ID AES_STATUS_KEYSTORE_INVALID_ID
523 
528 #define AESCTR_STATUS_KEYSTORE_GENERIC_ERROR AES_STATUS_KEYSTORE_GENERIC_ERROR
529 
536 #define AESCTR_STATUS_UNALIGNED_IO_NOT_SUPPORTED AES_STATUS_UNALIGNED_IO_NOT_SUPPORTED
537 
559 typedef enum
560 {
579 
587 typedef struct
588 {
589  const CryptoKey *key;
590  const uint8_t *input;
595  uint8_t *output;
607  const uint8_t *initialCounter;
614  size_t inputLength;
623 
633 typedef struct
634 {
635  const uint8_t *input;
640  uint8_t *output;
653  size_t inputLength;
664 
672 
677 typedef union
678 {
679  AESCTR_OneStepOperation oneStepOperation; /* One-step operation element of the operation union */
680  AESCTR_SegmentedOperation segmentedOperation; /* Segmented operation element of the operation union */
682 
686 typedef enum
687 {
690 } AESCTR_Mode;
691 
695 #define AESCTR_OP_MODE_MASK 0x0F
696 
700 #define AESCTR_OP_FLAG_SEGMENTED 0x10 /* bit 4 */
701 
705 #define AESCTR_OP_FLAG_FINALIZE 0x20 /* bit 5 */
706 
710 #define AESCTR_OP_FLAGS_MASK (AESCTR_OP_FLAG_SEGMENTED | AESCTR_OP_FLAG_FINALIZE)
711 
715 typedef enum
716 {
724 
737 
741 typedef AESCTR_Config *AESCTR_Handle;
742 
758 typedef void (*AESCTR_CallbackFxn)(AESCTR_Handle handle,
759  int_fast16_t returnValue,
760  AESCTR_OperationUnion *operation,
761  AESCTR_OperationType operationType);
762 
771 typedef struct
772 {
773  AESCTR_ReturnBehavior returnBehavior;
775  uint32_t timeout;
778  void *custom;
781 } AESCTR_Params;
782 
789 
798 void AESCTR_init(void);
799 
812 void AESCTR_Params_init(AESCTR_Params *params);
813 
831 AESCTR_Handle AESCTR_open(uint_least8_t index, const AESCTR_Params *params);
832 
842 void AESCTR_close(AESCTR_Handle handle);
843 
862 int_fast16_t AESCTR_setupEncrypt(AESCTR_Handle handle, const CryptoKey *key, const uint8_t *initialCounter);
863 
882 int_fast16_t AESCTR_setupDecrypt(AESCTR_Handle handle, const CryptoKey *key, const uint8_t *initialCounter);
883 
910 int_fast16_t AESCTR_addData(AESCTR_Handle handle, AESCTR_SegmentedOperation *operation);
911 
937 int_fast16_t AESCTR_finalize(AESCTR_Handle handle, AESCTR_SegmentedOperation *operation);
938 
948 void AESCTR_Operation_init(AESCTR_Operation *operation);
949 
957 
965 
984 int_fast16_t AESCTR_oneStepEncrypt(AESCTR_Handle handle, AESCTR_OneStepOperation *operation);
985 
1004 int_fast16_t AESCTR_oneStepDecrypt(AESCTR_Handle handle, AESCTR_OneStepOperation *operation);
1005 
1018 int_fast16_t AESCTR_cancelOperation(AESCTR_Handle handle);
1019 
1045 AESCTR_Handle AESCTR_construct(AESCTR_Config *config, const AESCTR_Params *params);
1046 
1047 #ifdef __cplusplus
1048 }
1049 #endif
1050 
1051 #endif /* ti_drivers_AESCTR__include */
void AESCTR_SegmentedOperation_init(AESCTR_SegmentedOperation *operation)
Function to initialize an AESCTR_SegmentedOperation struct to its defaults (all zeroes) ...
const AESCTR_Params AESCTR_defaultParams
Default AESCTR_Params structure.
Definition: AESCTR.h:688
The CryptoKey type is an opaque representation of a cryptographic key.
AESCTR_Config * AESCTR_Handle
A handle that is returned from an AESCTR_open() call.
Definition: AESCTR.h:741
AESCommon_Config AESCTR_Config
AESCTR Global configuration.
Definition: AESCTR.h:736
int_fast16_t AESCTR_oneStepDecrypt(AESCTR_Handle handle, AESCTR_OneStepOperation *operation)
Function to perform an AESCTR decryption operation in one call.
void AESCTR_init(void)
This function initializes the CTR module.
const CryptoKey * key
Definition: AESCTR.h:589
int_fast16_t AESCTR_setupEncrypt(AESCTR_Handle handle, const CryptoKey *key, const uint8_t *initialCounter)
Function to prepare a segmented AESCTR encryption operation.
void AESCTR_OneStepOperation_init(AESCTR_OneStepOperation *operation)
Function to initialize an AESCTR_OneStepOperation struct to its defaults (all zeroes) ...
void(* AESCTR_CallbackFxn)(AESCTR_Handle handle, int_fast16_t returnValue, AESCTR_OperationUnion *operation, AESCTR_OperationType operationType)
The definition of a callback function used by the AESCTR driver when used in AESCTR_RETURN_BEHAVIOR_C...
Definition: AESCTR.h:758
CTR Parameters.
Definition: AESCTR.h:771
Struct containing the parameters required for encrypting/decrypting a message using a one-step operat...
Definition: AESCTR.h:587
AES Global configuration.
Definition: AESCommon.h:154
const uint8_t * input
Definition: AESCTR.h:590
AESCTR_OperationType
Enum for the operation types supported by the driver.
Definition: AESCTR.h:715
CryptoKey datastructure.
Definition: CryptoKey.h:211
AESCTR_ReturnBehavior
The way in which CTR function calls return after performing an encryption or decryption operation...
Definition: AESCTR.h:559
Definition: AESCommon.h:186
Definition: AESCommon.h:196
Definition: AESCTR.h:573
Definition: AESCTR.h:717
AESCTR_Mode
Enum for the direction of the CTR operation.
Definition: AESCTR.h:686
#define AESCTR_OP_FLAG_SEGMENTED
Flag indicating a segmented operation.
Definition: AESCTR.h:700
AESCTR_OneStepOperation oneStepOperation
Definition: AESCTR.h:679
void AESCTR_Params_init(AESCTR_Params *params)
Function to initialize the AESCTR_Params struct to its defaults.
Definition: AESCTR.h:689
Definition: AESCommon.h:192
uint8_t * output
Definition: AESCTR.h:595
size_t inputLength
Definition: AESCTR.h:653
Definition: AESCTR.h:561
Struct containing the parameters required for encrypting/decrypting a message using a segmented opera...
Definition: AESCTR.h:633
AESCTR_CallbackFxn callbackFxn
Definition: AESCTR.h:774
void * custom
Definition: AESCTR.h:778
AESCTR_SegmentedOperation segmentedOperation
Definition: AESCTR.h:680
int_fast16_t AESCTR_addData(AESCTR_Handle handle, AESCTR_SegmentedOperation *operation)
Encrypts or decrypts a segment of data with a length.
int_fast16_t AESCTR_cancelOperation(AESCTR_Handle handle)
Cancels an ongoing AESCTR operation.
AESCTR_ReturnBehavior returnBehavior
Definition: AESCTR.h:773
Definition: AESCTR.h:568
AESCTR_Handle AESCTR_open(uint_least8_t index, const AESCTR_Params *params)
This function opens a given AESCTR peripheral.
size_t inputLength
Definition: AESCTR.h:614
const uint8_t * input
Definition: AESCTR.h:635
uint8_t * output
Definition: AESCTR.h:640
#define AESCTR_OP_FLAG_FINALIZE
Flag indicating a finalize operation.
Definition: AESCTR.h:705
int_fast16_t AESCTR_finalize(AESCTR_Handle handle, AESCTR_SegmentedOperation *operation)
Finalize the AES operation. If new data needs to be added, inputLength will be used to govern how man...
void AESCTR_Operation_init(AESCTR_Operation *operation)
Function to initialize an AESCTR_Operation struct to its defaults (all zeroes)
int_fast16_t AESCTR_oneStepEncrypt(AESCTR_Handle handle, AESCTR_OneStepOperation *operation)
Function to perform an AESCTR encryption operation in one call.
AES common module header for all devices.
Union containing a reference to a one-step and segmented operation structure.
Definition: AESCTR.h:677
uint32_t timeout
Definition: AESCTR.h:775
AESCTR_Handle AESCTR_construct(AESCTR_Config *config, const AESCTR_Params *params)
Constructs a new AESCTR object.
const uint8_t * initialCounter
Definition: AESCTR.h:607
AESCTR_OneStepOperation AESCTR_Operation
Definition: AESCTR.h:671
int_fast16_t AESCTR_setupDecrypt(AESCTR_Handle handle, const CryptoKey *key, const uint8_t *initialCounter)
Function to prepare a segmented AESCTR decryption operation.
Definition: AESCTR.h:718
void AESCTR_close(AESCTR_Handle handle)
Function to close a CTR peripheral specified by the AESCTR handle.
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale