1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7  /*!
8  @addtogroup cc_aes_defs
9  @{
10  */
11 
12 /*!
13  @file
14  @brief This file contains the type definitions that are used by the CryptoCell
15  AES APIs.
16  */
17 
18 
19 #ifndef CC_AES_DEFS_H
20 #define CC_AES_DEFS_H
21 
22 #include "cc_pal_types.h"
23 #include "cc_aes_defs_proj.h"
24 
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 
32 /************************ Defines  ******************************/
33 /*! The size of the AES block in words. */
34 #define CC_AES_CRYPTO_BLOCK_SIZE_IN_WORDS 4
35 /*! The size of the AES block in bytes. */
36 #define CC_AES_BLOCK_SIZE_IN_BYTES  (CC_AES_CRYPTO_BLOCK_SIZE_IN_WORDS * sizeof(uint32_t))
37 
38 /*! The size of the IV buffer in words. */
39 #define CC_AES_IV_SIZE_IN_WORDS   CC_AES_CRYPTO_BLOCK_SIZE_IN_WORDS
40 /*! The size of the IV buffer in bytes. */
41 #define CC_AES_IV_SIZE_IN_BYTES  (CC_AES_IV_SIZE_IN_WORDS * sizeof(uint32_t))
42 
43 
44 /************************ Enums ********************************/
45 /*! The AES operation:<ul><li>Encrypt</li><li>Decrypt</li></ul>. */
46 typedef enum {
47     /*! An AES encrypt operation. */
48     CC_AES_ENCRYPT = 0,
49     /*! An AES decrypt operation. */
50     CC_AES_DECRYPT = 1,
51     /*! The maximal number of operations. */
52     CC_AES_NUM_OF_ENCRYPT_MODES,
53     /*! Reserved. */
54     CC_AES_ENCRYPT_MODE_LAST = 0x7FFFFFFF
55 }CCAesEncryptMode_t;
56 
57 /*! The AES operation mode. */
58 typedef enum {
59     /*! ECB mode. */
60     CC_AES_MODE_ECB          = 0,
61     /*! CBC mode. */
62     CC_AES_MODE_CBC          = 1,
63     /*! CBC-MAC mode. */
64     CC_AES_MODE_CBC_MAC      = 2,
65     /*! CTR mode. */
66     CC_AES_MODE_CTR          = 3,
67     /*! XCBC-MAC mode. */
68     CC_AES_MODE_XCBC_MAC     = 4,
69     /*! CMAC mode. */
70     CC_AES_MODE_CMAC         = 5,
71     /*! XTS mode. */
72     CC_AES_MODE_XTS          = 6,
73     /*! CBC-CTS mode. */
74     CC_AES_MODE_CBC_CTS      = 7,
75     /*! OFB mode. */
76     CC_AES_MODE_OFB          = 8,
77 
78     /*! The maximal number of AES modes. */
79     CC_AES_NUM_OF_OPERATION_MODES,
80     /*! Reserved. */
81     CC_AES_OPERATION_MODE_LAST = 0x7FFFFFFF
82 }CCAesOperationMode_t;
83 
84 /*! The AES padding type. */
85 typedef enum {
86        /*! No padding. */
87        CC_AES_PADDING_NONE  = 0,
88        /*! PKCS7 padding. */
89        CC_AES_PADDING_PKCS7 = 1,
90        /*! The maximal number of AES padding modes. */
91        CC_AES_NUM_OF_PADDING_TYPES,
92        /*! Reserved. */
93        CC_AES_PADDING_TYPE_LAST = 0x7FFFFFFF
94 }CCAesPaddingType_t;
95 
96 /*! The AES key type. */
97 typedef enum {
98     /*! The user key. */
99     CC_AES_USER_KEY          = 0,
100     /*! The Kplt hardware key. */
101     CC_AES_PLATFORM_KEY      = 1,
102     /*! The Kcst hardware key. */
103     CC_AES_CUSTOMER_KEY      = 2,
104     /*! The maximal number of AES key types. */
105     CC_AES_NUM_OF_KEY_TYPES,
106     /*! Reserved. */
107     CC_AES_KEY_TYPE_LAST = 0x7FFFFFFF
108 }CCAesKeyType_t;
109 
110 /************************ Typedefs  ****************************/
111 
112 /*! Defines the IV buffer. A 16-byte array. */
113 typedef uint8_t CCAesIv_t[CC_AES_IV_SIZE_IN_BYTES];
114 
115 /*! Defines the AES key data buffer. */
116 typedef uint8_t CCAesKeyBuffer_t[CC_AES_KEY_MAX_SIZE_IN_BYTES];
117 
118 /************************ Structs  ******************************/
119 
120 /*!
121  The context prototype of the user.
122 
123  The argument type that is passed by the user to the AES APIs. The context
124  saves the state of the operation, and must be saved by the user until
125  the end of the API flow.
126  */
127 typedef struct CCAesUserContext_t {
128     /*! The context buffer for internal usage. */
129     uint32_t buff[CC_AES_USER_CTX_SIZE_IN_WORDS] ;
130 }CCAesUserContext_t;
131 
132 
133 /*! The AES key data of the user. */
134 typedef struct CCAesUserKeyData_t {
135     /*! A pointer to the key. */
136     uint8_t * pKey;
137     /*! The size of the key in bytes. Valid values for XTS mode, if supported:
138     32 bytes or 64 bytes, indicating the full size of the double key (2x128 or
139     2x256 bit). Valid values for XCBC-MAC mode: 16 bytes, as limited by the
140     standard. Valid values for all other modes: 16 bytes, 24 bytes, or
141     32 bytes. */
142     size_t    keySize;
143 }CCAesUserKeyData_t;
144 
145 /*! The AES HW key Data. */
146 typedef struct CCAesHwKeyData_t {
147     /*! Slot number. */
148     size_t slotNumber;
149 }CCAesHwKeyData_t;
150 
151 #endif /* CC_AES_DEFS_H */
152 
153 #ifdef __cplusplus
154 }
155 
156 #endif
157 
158 /*!
159  @}
160 */
161 
162