Mistake on this page?
Report an issue in GitHub or email us
ssi_aes.h
Go to the documentation of this file.
1 /**************************************************************************************
2 * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
3 * *
4 * This file and the related binary are licensed under the following license: *
5 * *
6 * ARM Object Code and Header Files License, v1.0 Redistribution. *
7 * *
8 * Redistribution and use of object code, header files, and documentation, without *
9 * modification, are permitted provided that the following conditions are met: *
10 * *
11 * 1) Redistributions must reproduce the above copyright notice and the *
12 * following disclaimer in the documentation and/or other materials *
13 * provided with the distribution. *
14 * *
15 * 2) Unless to the extent explicitly permitted by law, no reverse *
16 * engineering, decompilation, or disassembly of is permitted. *
17 * *
18 * 3) Redistribution and use is permitted solely for the purpose of *
19 * developing or executing applications that are targeted for use *
20 * on an ARM-based product. *
21 * *
22 * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
23 * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
24 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
25 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
33 **************************************************************************************/
34 
35 
36 /*! @file
37 @brief This file contains all of the enums and definitions that are used for the
38 CryptoCell AES APIs, as well as the APIs themselves.
39 @defgroup ssi_aes CryptoCell AES APIs
40 @{
41 @ingroup cryptocell_api
42 */
43 
44 #ifndef SSI_AES_H
45 #define SSI_AES_H
46 
47 #include "ssi_pal_types.h"
48 #include "ssi_aes_error.h"
49 #include "ssi_aes_defs.h"
50 
51 
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
57 /************************ Defines ******************************/
58 
59 
60 /************************ Enums ********************************/
61 
62 /*!
63 Encrypt or Decrypt operation mode.
64 */
65 typedef enum {
66  /*! Encrypt operation. */
68  /*! Decrypt operation. */
70  /*! Maximal number of operations. */
72  /*! Reserved. */
75 
76 /*!
77 AES operation mode.
78 */
79 typedef enum {
80  SASI_AES_MODE_ECB = 0, /*!< ECB mode. */
81  SASI_AES_MODE_CBC = 1, /*!< CBC mode. */
82  SASI_AES_MODE_CBC_MAC = 2, /*!< CBC-MAC mode. */
83  SASI_AES_MODE_CTR = 3, /*!< CTR mode. */
84  SASI_AES_MODE_XCBC_MAC = 4, /*!< XCBC-MAC mode. */
85  SASI_AES_MODE_CMAC = 5, /*!< CMAC mode. */
86  SASI_AES_MODE_XTS = 6, /*!< XTS mode. */
87  SASI_AES_MODE_CBC_CTS = 7, /*!< CBC-CTS mode. */
88  SASI_AES_MODE_OFB = 8, /*!< OFB mode. */
89 
90  /*! Maximal number of AES modes */
92  /*! Reserved. */
95 
96 /*!
97 AES padding type.
98 */
99 typedef enum {
100  SASI_AES_PADDING_NONE = 0, /*!< No padding. */
101  SASI_AES_PADDING_PKCS7 = 1, /*!< PKCS7 padding. */
102 
103  /*! Maximal number of AES padding modes */
105  /*! Reserved. */
108 
109 /*!
110 AES key type.
111 */
112 typedef enum {
113  SASI_AES_USER_KEY = 0, /*!< user key. */
114  SASI_AES_PLATFORM_KEY = 1, /*!< Kplt hardware key. */
115  SASI_AES_CUSTOMER_KEY = 2, /*!< Kcst hardware key. */
116 
117  /*! Maximal number of AES key types */
119  /*! Reserved. */
122 
123 /************************ Typedefs ****************************/
124 
125 /*! Defines the IV buffer - 16 bytes array. */
127 
128 /*! Defines the AES key data buffer. */
130 
131 /************************ Structs ******************************/
132 
133 /*! The user's context prototype - the argument type that is passed by the user
134  to the AES APIs. The context saves the state of the operation and must be saved by the user
135  till the end of the APIs flow*/
136 typedef struct SaSiAesUserContext_t {
137  /*! Context buffer for internal usage. */
140 
141 
142 /*! AES User Key Data. */
143 typedef struct SaSiAesUserKeyData_t {
144  uint8_t * pKey; /*!< Pointer to the key. */
145  size_t keySize; /*!< The key size in bytes. Valid values:
146  <ul><li> For XTS mode - 32 or 64 byte, indicating the full size of the double key (2x128 or 2x256 bit).</li>
147  <li>For XCBC-MAC mode - 16 byte (limited by the standard).</li>
148  <li>For all other modes - 16, 24 or 32 byte.</li></ul> */
150 
151 /*! AES HW Key Data - this structure is likely to be changed when we'll start using it. */
152 typedef struct SaSiAesHwKeyData_t {
153  size_t slotNumber; /*!< Slot number. */
155 
156 
157 /************************ Functions *****************************/
158 
159 /*!
160 @brief This function is used to initialize an AES operation context.
161  To operate the AES machine, this must be the first API called.
162 
163 @return SASI_OK on success,
164 @return A non-zero value from ssi_aes_error.h on failure.
165 */
166 CIMPORT_C SaSiError_t SaSi_AesInit(
167  SaSiAesUserContext_t * pContext, /*!< [in] Pointer to the AES context buffer that is allocated by the caller and initialized by this API.
168  Should be used in all subsequent calls that are part of the same operation. */
169  SaSiAesEncryptMode_t encryptDecryptFlag, /*!< [in] A flag specifying whether an AES Encrypt (SASI_AES_Encrypt) or Decrypt (SASI_AES_Decrypt) operation should be performed.
170  Must be set to CRYS_AES_Encrypt in CBC-MAC, XCBC-MAC and CMAC modes. */
171  SaSiAesOperationMode_t operationMode, /*!< [in] The operation cipher/mode. */
172  SaSiAesPaddingType_t paddingType /*!< [in] The padding type for AES operation:
173  <ul><li> NONE - supported for all operation modes.</li>
174  <li> PKCS7 - supported for ECB, CBC, CBC-MAC operation modes.</li></ul> */
175 );
176 
177 
178 /*!
179 @brief This function sets the key information for the AES operation, in the context that was initialized by SaSi_AesInit.
180 \note When FIPS certification mode is set to ON, and the mode is AES-XTS, weak keys are not allowed (128/256 lsb bits must be
181 different than 128/256 msb bits, according to the key size).
182 @return SASI_OK on success,
183 @return A non-zero value from ssi_aes_error.h on failure.
184 */
185 CIMPORT_C SaSiError_t SaSi_AesSetKey(
186  SaSiAesUserContext_t * pContext, /*!< [in] Pointer to the AES context, after it was initialized by SaSi_AesInit. */
187  SaSiAesKeyType_t keyType, /*!< [in] The type of key to be used for the AES operation.
188  Currently only SASI_AES_USER_KEY is supported - the key is plaintext and provided in the pKeyData parameter. */
189  void * pKeyData, /*!< [in] Pointer to the key data structure (to be casted to the relevant struct type). */
190  size_t keyDataSize /*!< [in] The size of data passed in pKeyData in bytes. */
191 );
192 
193 
194 /*!
195 @brief This function sets the IV, counter or tweak data for the following AES operation on the same context.
196  The context must be first initialized by SaSi_AesInit.
197  It must be called at least once prior to the first SaSi_AesBlock operation on the same context - for those ciphers that require it.
198  If needed, it can also be called to override the IV in the middle of a sequence of SaSi_AesBlock operations.
199 
200 @return SASI_OK on success,
201 @return A non-zero value from ssi_aes_error.h on failure.
202 */
203 CIMPORT_C SaSiError_t SaSi_AesSetIv(
204  SaSiAesUserContext_t * pContext, /*!< [in] Pointer to the AES context. */
205  SaSiAesIv_t pIV /*!< [in] Pointer to the buffer of the IV, counter or tweak.
206  <ul><li> For CBC, CBC-CTS, OFB and CBC-MAC modes - the IV value.</li>
207  <li> For CTR mode - the counter.</li>
208  <li> For XTS mode - the tweak value.</li>
209  <li> For all other modes - N/A. </li></ul>*/
210 );
211 
212 
213 /*!
214 @brief This function retrieves the current IV, counter or tweak from the AES context.
215 
216 @return SASI_OK on success,
217 @return A non-zero value from ssi_aes_error.h on failure.
218 */
219 CIMPORT_C SaSiError_t SaSi_AesGetIv(
220  SaSiAesUserContext_t * pContext, /*!< [in] Pointer to the AES context. */
221  SaSiAesIv_t pIV /*!< [out] Pointer to the buffer of the IV, counter or tweak.
222  <ul><li> For CBC, CBC-CTS, OFB and CBC-MAC modes - the IV value.</li>
223  <li> For CTR mode - the counter.</li>
224  <li> For XTS mode - the tweak value.</li>
225  <li> For all other modes - N/A. </li></ul> */
226 );
227 
228 
229 /*!
230 @brief This function performs an AES operation on an input data buffer, according to the configuration defined in the context parameter.
231  It can be called as many times as needed, until all the input data is processed.
232  SaSi_AesInit, SaSi_AesSetKey, and for some ciphers SaSi_AesSetIv, must be called before
233  the first call to this API with the same context.
234 
235 @return SASI_OK on success,
236 @return A non-zero value from ssi_aes_error.h on failure.
237 */
238 CIMPORT_C SaSiError_t SaSi_AesBlock(
239  SaSiAesUserContext_t * pContext, /*!< [in] Pointer to the AES context. */
240  uint8_t * pDataIn, /*!< [in] Pointer to the buffer of the input data to the AES. The pointer does not need to be aligned.
241  For TZ, the size of the scatter/gather list representing the data buffer is limited to 128 entries,
242  and the size of each entry is limited to 64KB (fragments larger than 64KB are broken into fragments <= 64KB).
243  For ARM CryptoCell 3xx, The buffer must be contiguous and limited to 64KB. */
244  size_t dataInSize, /*!< [in] Size of the input data in bytes.
245  <ul><li> For all modes except XTS, must be multiple of 16 bytes.</li>
246  <li> For XTS mode, only the following data sizes are supported: 64, 512, 520, 521, 1024 and 4096 bytes.
247  The data passed in a single SaSi_AesBlock call is considered to be a single XTS unit.
248  All subsequent calls to this API with the same context must use the same data size. </li></ul>*/
249  uint8_t * pDataOut /*!< [out] Pointer to the output buffer. The pointer does not need to be aligned.
250  For CBC-MAC, XCBC-MAC, CMAC modes it may be NULL.
251  For TZ, the size of the scatter/gather list representing the data buffer is limited to 128 entries,
252  and the size of each entry is limited to 64KB (fragments larger than 64KB are broken into fragments <= 64KB).
253  For ARM CryptoCell 3xx, The buffer must be contiguous and limited to 64KB. */
254 );
255 
256 
257 /*!
258 @brief This function is used to finish AES operation.
259 
260  It processes the last data block if needed, finalizes the AES operation (cipher-specific),
261  and produces operation results (for MAC operations).
262  \note In case AES padding is used (PKCS#7) Din and Dout user's buffers must include extra space for
263  the padding scheme.
264 
265 @return SASI_OK on success,
266 @return A non-zero value from ssi_aes_error.h on failure.
267 */
268 CIMPORT_C SaSiError_t SaSi_AesFinish(
269  SaSiAesUserContext_t * pContext, /*!< [in] Pointer to the AES context. */
270  size_t dataSize, /*!< [in] The size of the input data in bytes.
271  <ul><li> For CBC-CTS mode, must be > 16. Can be <=16 only if this is the only data (no previous calls were
272  made to SaSi_AesBlock with the same context).</li>
273  <li> For XTS mode, the data size must conform to the dataInSize rules as listed for XTS under the
274  SaSi_AesBlock API, and match the data size passed in the previous calls to SaSi_AesBlock with the
275  same context.</li>
276  <li> For all other modes, zero is a valid size.</li>
277  <li> For ECB, CBC, CBC-MAC modes: </li>
278  <ul><li> Must be >= 0, if direction is SASI_AES_ENCRYPT and padding type is SASI_AES_PADDING_PKCS7.</li>
279  <li> Must be >= 16 and a multiple of 16 bytes, if direction is SASI_AES_DECRYPT and padding type
280  is SASI_AES_PADDING_PKCS7.</li>
281  <li> Must be a multiple of 16 bytes, otherwise. </li></ul></ul>*/
282  uint8_t * pDataIn, /*!< [in] Pointer of the input data buffer.
283  For TZ, the size of the scatter/gather list representing the data buffer is limited to 128 entries,
284  and the size of each entry is limited to 64KB (fragments larger than 64KB are broken into fragments <= 64KB).
285  For ARM CryptoCell 3xx, The buffer must be contiguous and limited to 64KB. */
286  size_t dataInBuffSize, /*!< [in] Size of pDataIn buffer in bytes.
287  <ul><li> Must be >= dataSize. </li>
288  <li> According to padding type, must be >= dataSize + padding. For PKCS7, padding size is
289  maximum SASI_AES_BLOCK_SIZE_IN_BYTES. </li></ul>*/
290  uint8_t * pDataOut, /*!< [out] Pointer to the output buffer.
291  For TZ, the size of the scatter/gather list representing the data buffer is limited to 128 entries,
292  and the size of each entry is limited to 64KB (fragments larger than 64KB are broken into fragments <= 64KB).
293  For ARM CryptoCell 3xx, The buffer must be contiguous and limited to 64KB. */
294  size_t * dataOutBuffSize /*!< [in,out] In - Size of pDataOut buffer in bytes.
295  The output buffer size must be no less than:
296  <ul><li> For CBC-MAC, XCBC-MAC, CMAC modes - 16 bytes (for MAC result).</li>
297  <li> For non-MAC modes - dataInBuffSize.</li></ul>
298  Out - The size in bytes of the actual output data:
299  <ul><li> If direction is SASI_AES_ENCRYPT and padding type is SASI_AES_PADDING_PKCS7, it is the actual size
300  with the padding.</li>
301  <li> If direction is SASI_AES_DECRYPT and padding type is SASI_AES_PADDING_PKCS7, it is the size without
302  the padding. </li>
303  <li> For CBC-MAC, XCBC-MAC, CMAC modes - always 16 bytes. </li></ul>*/
304 );
305 
306 
307 /*!
308 @brief This function releases and crears resources after AES operations.
309 
310 @return SASI_OK on success,
311 @return A non-zero value from ssi_aes_error.h on failure.
312 */
313 CIMPORT_C SaSiError_t SaSi_AesFree(
314  SaSiAesUserContext_t * pContext /*!< [in] Pointer to the AES context. */
315 );
316 
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 /**
322 @}
323  */
324 #endif /* #ifndef SSI_AES_H */
325 
#define SASI_AES_IV_SIZE_IN_BYTES
Definition: ssi_aes_defs.h:69
SaSiStatus SaSi_AesSetKey(SaSiAesUserContext_t *pContext, SaSiAesKeyType_t keyType, void *pKeyData, size_t keyDataSize)
This function sets the key information for the AES operation, in the context that was initialized by ...
SaSiStatus SaSi_AesBlock(SaSiAesUserContext_t *pContext, uint8_t *pDataIn, size_t dataInSize, uint8_t *pDataOut)
This function performs an AES operation on an input data buffer, according to the configuration defin...
#define SASI_AES_KEY_MAX_SIZE_IN_BYTES
Definition: ssi_aes_defs.h:74
SaSiStatus SaSi_AesFree(SaSiAesUserContext_t *pContext)
This function releases and crears resources after AES operations.
SaSiAesKeyType_t
Definition: ssi_aes.h:112
SaSiStatus SaSi_AesFinish(SaSiAesUserContext_t *pContext, size_t dataSize, uint8_t *pDataIn, size_t dataInBuffSize, uint8_t *pDataOut, size_t *dataOutBuffSize)
This function is used to finish AES operation.
uint8_t SaSiAesKeyBuffer_t[(4 *sizeof(uint32_t))]
Definition: ssi_aes.h:129
uint32_t buff[(4+4+7+4)]
Definition: ssi_aes.h:138
This file contains definitions that are used for the ARM CryptoCell 3xx version of the CryptoCell AES...
SaSiAesPaddingType_t
Definition: ssi_aes.h:99
SaSiStatus SaSi_AesGetIv(SaSiAesUserContext_t *pContext, SaSiAesIv_t pIV)
This function retrieves the current IV, counter or tweak from the AES context.
SaSiAesEncryptMode_t
Definition: ssi_aes.h:65
uint8_t * pKey
Definition: ssi_aes.h:144
struct SaSiAesHwKeyData_t SaSiAesHwKeyData_t
size_t slotNumber
Definition: ssi_aes.h:153
struct SaSiAesUserContext_t SaSiAesUserContext_t
#define SASI_AES_USER_CTX_SIZE_IN_WORDS
Definition: ssi_aes_defs.h:59
uint8_t SaSiAesIv_t[(4 *sizeof(uint32_t))]
Definition: ssi_aes.h:126
SaSiStatus SaSi_AesSetIv(SaSiAesUserContext_t *pContext, SaSiAesIv_t pIV)
This function sets the IV, counter or tweak data for the following AES operation on the same context...
SaSiStatus SaSi_AesInit(SaSiAesUserContext_t *pContext, SaSiAesEncryptMode_t encryptDecryptFlag, SaSiAesOperationMode_t operationMode, SaSiAesPaddingType_t paddingType)
This function is used to initialize an AES operation context. To operate the AES machine, this must be the first API called.
struct SaSiAesUserKeyData_t SaSiAesUserKeyData_t
This file contains the platform dependent definitions and types.
SaSiAesOperationMode_t
Definition: ssi_aes.h:79
This file contains the definitions of the CryptoCell AES errors.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.