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  * <h4> Starting a CTR operation </h4>
107  *
108  * The AESCTR_oneStepEncrypt() and AESCTR_oneStepDecrypt() functions perform a CTR operation
109  * in a single call.
110  *
111  * <h4> After the CTR operation completes </h4>
112  *
113  * After the CTR operation completes, the application should either start
114  * another operation or close the driver by calling #AESCTR_close().
115  *
116  * @anchor ti_drivers_AESCTR_Synopsis
117  * ## Synopsis
118  *
119  * @anchor ti_drivers_AESCTR_Synopsis_Code
120  * @code
121  *
122  * // Import AESCTR Driver definitions
123  * #include <ti/drivers/AESCTR.h>
124  *
125  * // Define name for AESCTR channel index
126  * #define AESCTR_INSTANCE 0
127  *
128  * AESCTR_init();
129  *
130  * handle = AESCTR_open(AESCTR_INSTANCE, NULL);
131  *
132  * // Initialize symmetric key
133  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
134  *
135  * // Set up AESCTR_Operation
136  * AESCTR_OneStepOperation_init(&operation);
137  * operation.key = &cryptoKey;
138  * operation.input = plaintext;
139  * operation.output = ciphertext;
140  * operation.inputLength = sizeof(plaintext);
141  * operation.initialCounter = initialCounter;
142  *
143  * encryptionResult = AESCTR_oneStepEncrypt(handle, &operation);
144  *
145  * AESCTR_close(handle);
146  * @endcode
147  *
148  * @anchor ti_drivers_AESCTR_Examples
149  * <h4> Examples </h4>
150  *
151  * <h5> One step CTR encryption with plaintext CryptoKey in blocking return mode </h5>
152  * @code
153  *
154  * #include <ti/drivers/AESCTR.h>
155  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
156  *
157  * ...
158  *
159  * AESCTR_Handle handle;
160  * CryptoKey cryptoKey;
161  * int_fast16_t encryptionResult;
162  *
163  * // For example purposes only. Generate IVs in a non-static way in practice.
164  * // Test vector from NIST SP 800-38A
165  * uint8_t initialCounter[16] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
166  * 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
167  * uint8_t plaintext[64] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
168  * 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
169  * 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
170  * 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
171  * 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
172  * 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
173  * 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
174  * 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10};
175  * uint8_t ciphertext[sizeof(plaintext)];
176  * uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
177  * 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
178  *
179  * handle = AESCTR_open(0, NULL);
180  *
181  * if (handle == NULL) {
182  * // handle error
183  * while(1);
184  * }
185  *
186  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
187  *
188  * AESCTR_OneStepOperation operation;
189  * AESCTR_OneStepOperation_init(&operation);
190  *
191  * operation.key = &cryptoKey;
192  * operation.input = plaintext;
193  * operation.output = ciphertext;
194  * operation.inputLength = sizeof(plaintext);
195  * operation.initialCounter = initialCounter;
196  *
197  * encryptionResult = AESCTR_oneStepEncrypt(handle, &operation);
198  *
199  * if (encryptionResult != AESCTR_STATUS_SUCCESS) {
200  * // handle error
201  * while(1);
202  * }
203  *
204  * // The ciphertext should be the following after the encryption operation:
205  * // 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
206  * // 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
207  * // 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
208  * // 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
209  * // 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
210  * // 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
211  * // 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
212  * // 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee
213  *
214  * AESCTR_close(handle);
215  *
216  * @endcode
217  *
218  * <h4> The following code snippet is for CC27XX devices only and leverages the HSM which is a seperate Hardware
219  * Accelerator </h4>
220  *
221  * <h5> One step CTR encryption with plaintext CryptoKey in blocking return mode using the HSM accelerator </h5>
222  * @code
223  *
224  * #include <ti/drivers/AESCTR.h>
225  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
226  *
227  * ...
228  *
229  * AESCTR_Handle handle;
230  * CryptoKey cryptoKey;
231  * int_fast16_t encryptionResult;
232  *
233  * // For example purposes only. Generate IVs in a non-static way in practice.
234  * // Test vector from NIST SP 800-38A
235  * uint8_t initialCounter[16] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
236  * 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff};
237  * uint8_t plaintext[64] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
238  * 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
239  * 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
240  * 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
241  * 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
242  * 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
243  * 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
244  * 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10};
245  * uint8_t ciphertext[sizeof(plaintext)];
246  * uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
247  * 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
248  *
249  * handle = AESCTR_open(0, NULL);
250  *
251  * if (handle == NULL) {
252  * // handle error
253  * while(1);
254  * }
255  *
256  * CryptoKeyPlaintextHSM_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
257  *
258  * AESCTR_OneStepOperation operation;
259  * AESCTR_OneStepOperation_init(&operation);
260  *
261  * operation.key = &cryptoKey;
262  * operation.input = plaintext;
263  * operation.output = ciphertext;
264  * operation.inputLength = sizeof(plaintext);
265  * operation.initialCounter = initialCounter;
266  *
267  * encryptionResult = AESCTR_oneStepEncrypt(handle, &operation);
268  *
269  * if (encryptionResult != AESCTR_STATUS_SUCCESS) {
270  * // handle error
271  * while(1);
272  * }
273  *
274  * // The ciphertext should be the following after the encryption operation:
275  * // 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
276  * // 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
277  * // 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
278  * // 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
279  * // 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
280  * // 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
281  * // 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
282  * // 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee
283  *
284  * AESCTR_close(handle);
285  *
286  * @endcode
287  *
288  * <h5> One step CTR decryption with plaintext CryptoKey in callback return mode </h5>
289  * @code
290  *
291  * #include <ti/drivers/AESCTR.h>
292  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
293  *
294  * ...
295  *
296  *
297  * void ctrCallback(AESCTR_Handle handle,
298  * int_fast16_t returnValue,
299  * AESCTR_OperationUnion *operation,
300  * AESCTR_OperationType operationType) {
301  *
302  * if (returnValue != AESCTR_STATUS_SUCCESS) {
303  * // handle error
304  * while(1);
305  * }
306  * }
307  * AESCTR_Operation operation;
308  *
309  * void ctrStartFunction(void) {
310  * uint8_t initialCounter[16] = {0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
311  * 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01};
312  * uint8_t ciphertext[] = {0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
313  * 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
314  * 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
315  * 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
316  * 0x25, 0xB2, 0x07, 0x2F};
317  * uint8_t keyingMaterial[] = {0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
318  * 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC};
319  * uint8_t plaintext[sizeof(ciphertext)];
320  *
321  * AESCTR_Handle handle;
322  * AESCTR_Params params;
323  * CryptoKey cryptoKey;
324  * int_fast16_t decryptionResult;
325  *
326  * AESCTR_OneStepOperation operation;
327  *
328  * AESCTR_Params_init(&params);
329  * params.returnBehavior = AESCTR_RETURN_BEHAVIOR_CALLBACK;
330  * params.callbackFxn = ctrCallback;
331  *
332  * handle = AESCTR_open(0, &params);
333  *
334  * if (handle == NULL) {
335  * // handle error
336  * while(1);
337  * }
338  *
339  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
340  *
341  * AESCTR_OneStepOperation_init(&operation); // Optional as all struct members will be set before use.
342  *
343  * operation.key = &cryptoKey;
344  * operation.input = ciphertext;
345  * operation.output = plaintext;
346  * operation.inputLength = sizeof(ciphertext);
347  * operation.initialCounter = initialCounter;
348  *
349  * decryptionResult = AESCTR_oneStepDecrypt(handle, &operation);
350  *
351  * if (decryptionResult != AESCTR_STATUS_SUCCESS) {
352  * // handle error
353  * while(1);
354  * }
355  *
356  * // do other things while CTR operation completes in the background
357  *
358  * // After the operation completes and the callback is invoked, the resultant
359  * // plaintext should be:
360  * // 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
361  * // 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
362  * // 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
363  * // 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
364  * // 0x20, 0x21, 0x22, 0x23
365  *
366  * AESCTR_close(handle);
367  * }
368  *
369  * @endcode
370  *
371  * <h5> Multi-step AES CTR encrypt with plaintext CryptoKey in polling return mode </h5>
372  * @code
373  *
374  * #include <ti/drivers/AESCTR.h>
375  * #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
376  *
377  * #define AES_BLOCK_SIZE 16 // bytes
378  * ...
379  *
380  * AESCTR_Params params;
381  * AESCTR_Handle handle;
382  * CryptoKey cryptoKey;
383  * int_fast16_t retVal;
384  *
385  * // For example purposes only.
386  * uint8_t plaintext[36] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
387  * 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
388  * 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
389  * 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
390  * 0x20, 0x21, 0x22, 0x23};
391  * uint8_t initialCounter[] = {0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
392  * 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01};
393  * uint8_t keyingMaterial[] = {0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
394  * 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC};
395  * uint8_t ciphertext[sizeof(plaintext)];
396  *
397  * AESCTR_Params_init(&params)
398  * params.returnBehavior = AESCTR_RETURN_BEHAVIOR_POLLING;
399  *
400  * handle = AESCTR_open(0, &params);
401  *
402  * if (handle == NULL) {
403  * // handle error
404  * }
405  *
406  * CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
407  *
408  * AESCTR_SegmentedOperation operation;
409  * AESCTR_SegmentedOperation_init(&operation); // Optional as all struct members will be set before use.
410  *
411  * retVal = AESCTR_setupEncrypt(handle, &cryptoKey, initialCounter);
412  *
413  * if (retVal != AESCTR_STATUS_SUCCESS) {
414  * // handle error
415  * }
416  *
417  * operation.input = plaintext;
418  * operation.inputLength = AES_BLOCK_SIZE; // Only block multiple lengths are permitted when adding data.
419  * operation.output = ciphertext;
420  *
421  * retVal = AESCTR_addData(handle, &operation);
422  *
423  * if (retVal != AESCTR_STATUS_SUCCESS) {
424  * // handle error
425  * }
426  *
427  * operation.input = plaintext + AES_BLOCK_SIZE;
428  * operation.inputLength = sizeof(plaintext) - AES_BLOCK_SIZE; // Non-block multiple length permitted during
429  * finalization. operation.output = ciphertext + AES_BLOCK_SIZE;
430  *
431  * retVal = AESCTR_finalize(handle, &operation);
432  *
433  * if (retVal != AESCTR_STATUS_SUCCESS) {
434  * // handle error
435  * }
436  *
437  * // Upon successful return, the resulting ciphertext should be:
438  * // 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
439  * // 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
440  * // 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
441  * // 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
442  * // 0x25, 0xB2, 0x07, 0x2F
443  *
444  * AESCTR_close(handle);
445  *
446  * @endcode
447  */
448 
449 #ifndef ti_drivers_AESCTR__include
450 #define ti_drivers_AESCTR__include
451 
452 #include <stddef.h>
453 #include <stdint.h>
454 
455 #include <ti/drivers/AESCommon.h>
457 
458 #ifdef __cplusplus
459 extern "C" {
460 #endif
461 
474 #define AESCTR_STATUS_RESERVED AES_STATUS_RESERVED
475 
482 #define AESCTR_STATUS_SUCCESS AES_STATUS_SUCCESS
483 
490 #define AESCTR_STATUS_ERROR AES_STATUS_ERROR
491 
500 #define AESCTR_STATUS_RESOURCE_UNAVAILABLE AES_STATUS_RESOURCE_UNAVAILABLE
501 
505 #define AESCTR_STATUS_CANCELED AES_STATUS_CANCELED
506 
510 #define AESCTR_STATUS_FEATURE_NOT_SUPPORTED AES_STATUS_FEATURE_NOT_SUPPORTED
511 
515 #define AESCTR_STATUS_KEYSTORE_INVALID_ID AES_STATUS_KEYSTORE_INVALID_ID
516 
521 #define AESCTR_STATUS_KEYSTORE_GENERIC_ERROR AES_STATUS_KEYSTORE_GENERIC_ERROR
522 
529 #define AESCTR_STATUS_UNALIGNED_IO_NOT_SUPPORTED AES_STATUS_UNALIGNED_IO_NOT_SUPPORTED
530 
552 typedef enum
553 {
572 
580 typedef struct
581 {
582  const CryptoKey *key;
583  const uint8_t *input;
588  uint8_t *output;
596  const uint8_t *initialCounter;
603  size_t inputLength;
609 
619 typedef struct
620 {
621  const uint8_t *input;
626  uint8_t *output;
634  size_t inputLength;
642 
650 
655 typedef union
656 {
657  AESCTR_OneStepOperation oneStepOperation; /* One-step operation element of the operation union */
658  AESCTR_SegmentedOperation segmentedOperation; /* Segmented operation element of the operation union */
660 
664 typedef enum
665 {
668 } AESCTR_Mode;
669 
673 #define AESCTR_OP_MODE_MASK 0x0F
674 
678 #define AESCTR_OP_FLAG_SEGMENTED 0x10 /* bit 4 */
679 
683 #define AESCTR_OP_FLAG_FINALIZE 0x20 /* bit 5 */
684 
688 #define AESCTR_OP_FLAGS_MASK (AESCTR_OP_FLAG_SEGMENTED | AESCTR_OP_FLAG_FINALIZE)
689 
693 typedef enum
694 {
702 
715 
719 typedef AESCTR_Config *AESCTR_Handle;
720 
736 typedef void (*AESCTR_CallbackFxn)(AESCTR_Handle handle,
737  int_fast16_t returnValue,
738  AESCTR_OperationUnion *operation,
739  AESCTR_OperationType operationType);
740 
749 typedef struct
750 {
751  AESCTR_ReturnBehavior returnBehavior;
753  uint32_t timeout;
756  void *custom;
759 } AESCTR_Params;
760 
767 
776 void AESCTR_init(void);
777 
791 
809 AESCTR_Handle AESCTR_open(uint_least8_t index, const AESCTR_Params *params);
810 
820 void AESCTR_close(AESCTR_Handle handle);
821 
840 int_fast16_t AESCTR_setupEncrypt(AESCTR_Handle handle, const CryptoKey *key, const uint8_t *initialCounter);
841 
860 int_fast16_t AESCTR_setupDecrypt(AESCTR_Handle handle, const CryptoKey *key, const uint8_t *initialCounter);
861 
888 int_fast16_t AESCTR_addData(AESCTR_Handle handle, AESCTR_SegmentedOperation *operation);
889 
915 int_fast16_t AESCTR_finalize(AESCTR_Handle handle, AESCTR_SegmentedOperation *operation);
916 
926 void AESCTR_Operation_init(AESCTR_Operation *operation);
927 
935 
943 
962 int_fast16_t AESCTR_oneStepEncrypt(AESCTR_Handle handle, AESCTR_OneStepOperation *operation);
963 
982 int_fast16_t AESCTR_oneStepDecrypt(AESCTR_Handle handle, AESCTR_OneStepOperation *operation);
983 
996 int_fast16_t AESCTR_cancelOperation(AESCTR_Handle handle);
997 
1023 AESCTR_Handle AESCTR_construct(AESCTR_Config *config, const AESCTR_Params *params);
1024 
1025 #ifdef __cplusplus
1026 }
1027 #endif
1028 
1029 #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:666
ADC_Params params
Definition: Driver_Init.h:11
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:719
AESCommon_Config AESCTR_Config
AESCTR Global configuration.
Definition: AESCTR.h:714
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:582
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:736
CTR Parameters.
Definition: AESCTR.h:749
Struct containing the parameters required for encrypting/decrypting a message using a one-step operat...
Definition: AESCTR.h:580
AES Global configuration.
Definition: AESCommon.h:154
const uint8_t * input
Definition: AESCTR.h:583
AESCTR_OperationType
Enum for the operation types supported by the driver.
Definition: AESCTR.h:693
CryptoKey datastructure.
Definition: CryptoKey.h:208
AESCTR_ReturnBehavior
The way in which CTR function calls return after performing an encryption or decryption operation...
Definition: AESCTR.h:552
Definition: AESCommon.h:186
Definition: AESCommon.h:196
Definition: AESCTR.h:566
Definition: AESCTR.h:695
AESCTR_Mode
Enum for the direction of the CTR operation.
Definition: AESCTR.h:664
#define AESCTR_OP_FLAG_SEGMENTED
Flag indicating a segmented operation.
Definition: AESCTR.h:678
AESCTR_OneStepOperation oneStepOperation
Definition: AESCTR.h:657
void AESCTR_Params_init(AESCTR_Params *params)
Function to initialize the AESCTR_Params struct to its defaults.
Definition: AESCTR.h:667
Definition: AESCommon.h:192
uint8_t * output
Definition: AESCTR.h:588
size_t inputLength
Definition: AESCTR.h:634
Definition: AESCTR.h:554
Struct containing the parameters required for encrypting/decrypting a message using a segmented opera...
Definition: AESCTR.h:619
AESCTR_CallbackFxn callbackFxn
Definition: AESCTR.h:752
void * custom
Definition: AESCTR.h:756
AESCTR_SegmentedOperation segmentedOperation
Definition: AESCTR.h:658
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:751
Definition: AESCTR.h:561
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:603
const uint8_t * input
Definition: AESCTR.h:621
uint8_t * output
Definition: AESCTR.h:626
#define AESCTR_OP_FLAG_FINALIZE
Flag indicating a finalize operation.
Definition: AESCTR.h:683
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:655
uint32_t timeout
Definition: AESCTR.h:753
AESCTR_Handle AESCTR_construct(AESCTR_Config *config, const AESCTR_Params *params)
Constructs a new AESCTR object.
const uint8_t * initialCounter
Definition: AESCTR.h:596
AESCTR_OneStepOperation AESCTR_Operation
Definition: AESCTR.h:649
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:696
void AESCTR_close(AESCTR_Handle handle)
Function to close a CTR peripheral specified by the AESCTR handle.
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale