Skip to content

Commit b700ea3

Browse files
committed
K64F: Add MMCAU driver needed for mbedtls
Signed-off-by: Mahadevan Mahesh <[email protected]>
1 parent bdf13cb commit b700ea3

File tree

6 files changed

+1128
-0
lines changed

6 files changed

+1128
-0
lines changed
Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
1+
/*
2+
* Copyright (c) 2015, Freescale Semiconductor, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* o Redistributions of source code must retain the above copyright notice, this list
9+
* of conditions and the following disclaimer.
10+
*
11+
* o Redistributions in binary form must reproduce the above copyright notice, this
12+
* list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16+
* contributors may be used to endorse or promote products derived from this
17+
* software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
#ifndef _CAU_API_H_
31+
#define _CAU_API_H_
32+
33+
/*******************************************************************************
34+
* Definitions
35+
******************************************************************************/
36+
37+
/*!
38+
* @addtogroup mmcau MMCAU Peripheral Driver
39+
* @{
40+
*/
41+
#define cau_aes_set_key mmcau_aes_set_key
42+
#define cau_aes_encrypt mmcau_aes_encrypt
43+
#define cau_aes_decrypt mmcau_aes_decrypt
44+
#define cau_des_chk_parity mmcau_des_chk_parity
45+
#define cau_des_encrypt mmcau_des_encrypt
46+
#define cau_des_decrypt mmcau_des_decrypt
47+
#define cau_md5_initialize_output mmcau_md5_initialize_output
48+
#define cau_md5_hash_n mmcau_md5_hash_n
49+
#define cau_md5_update mmcau_md5_update
50+
#define cau_md5_hash mmcau_md5_hash
51+
#define cau_sha1_initialize_output mmcau_sha1_initialize_output
52+
#define cau_sha1_hash_n mmcau_sha1_hash_n
53+
#define cau_sha1_update mmcau_sha1_update
54+
#define cau_sha1_hash mmcau_sha1_hash
55+
#define cau_sha256_initialize_output mmcau_sha256_initialize_output
56+
#define cau_sha256_hash_n mmcau_sha256_hash_n
57+
#define cau_sha256_update mmcau_sha256_update
58+
#define cau_sha256_hash mmcau_sha256_hash
59+
60+
/*******************************************************************************
61+
* API
62+
******************************************************************************/
63+
#if defined(__cplusplus)
64+
extern "C" {
65+
#endif
66+
67+
/*!
68+
* @brief AES: Performs an AES key expansion
69+
*
70+
* This function performs an AES key expansion
71+
*
72+
* @param key Pointer to input key (128, 192, 256 bits in length).
73+
* @param key_size Key size in bits (128, 192, 256)
74+
* @param[out] key_sch Pointer to key schedule output (44, 52, 60 longwords)
75+
* @note All pointers must have word (4 bytes) alignment
76+
* @note Table below shows the requirements for the cau_aes_set_key() function when using AES128, AES192 or AES256.@n
77+
* | [in] Key Size (bits) | [out] Key Schedule Size (32 bit data values) |@n
78+
* | :---------------------: | :--------------------------------------------: |@n
79+
* | 128 | 44 |@n
80+
* | 192 | 52 |@n
81+
* | 256 | 60 |
82+
*/
83+
void cau_aes_set_key(const unsigned char *key, const int key_size, unsigned char *key_sch);
84+
85+
/*!
86+
* @brief AES: Encrypts a single 16 byte block
87+
*
88+
* This function encrypts a single 16-byte block for AES128, AES192 and AES256
89+
*
90+
* @param in Pointer to 16-byte block of input plaintext
91+
* @param key_sch Pointer to key schedule (44, 52, 60 longwords)
92+
* @param nr Number of AES rounds (10, 12, 14 = f(key_schedule))
93+
* @param[out] out Pointer to 16-byte block of output ciphertext
94+
* @note All pointers must have word (4 bytes) alignment
95+
* @note Input and output blocks may overlap.@n
96+
* Table below shows the requirements for the cau_aes_encrypt()/cau_aes_decrypt()
97+
* function when using AES128, AES192 or AES256.@n
98+
* | Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |@n
99+
* | :----------: | :--------------------------------: | :-----------------------: |@n
100+
* | AES128 | 44 | 10 |@n
101+
* | AES192 | 52 | 12 |@n
102+
* | AES256 | 60 | 14 |
103+
*/
104+
void cau_aes_encrypt(const unsigned char *in, const unsigned char *key_sch, const int nr, unsigned char *out);
105+
106+
/*!
107+
* @brief AES: Decrypts a single 16-byte block
108+
*
109+
* This function decrypts a single 16-byte block for AES128, AES192 and AES256
110+
*
111+
* @param in Pointer to 16-byte block of input ciphertext
112+
* @param key_sch Pointer to key schedule (44, 52, 60 longwords)
113+
* @param nr Number of AES rounds (10, 12, 14 = f(key_schedule))
114+
* @param[out] out Pointer to 16-byte block of output plaintext
115+
* @note All pointers must have word (4 bytes) alignment
116+
* @note Input and output blocks may overlap.@n
117+
* Table below shows the requirements for the cau_aes_encrypt()/cau_aes_decrypt()
118+
* function when using AES128, AES192 or AES256.@n
119+
* | Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |@n
120+
* | :----------: | :--------------------------------: | :-----------------------: |@n
121+
* | AES128 | 44 | 10 |@n
122+
* | AES192 | 52 | 12 |@n
123+
* | AES256 | 60 | 14 |
124+
*/
125+
void cau_aes_decrypt(const unsigned char *in, const unsigned char *key_sch, const int nr, unsigned char *out);
126+
127+
/*!
128+
* @brief DES: Checks key parity
129+
*
130+
* This function checks the parity of a DES key
131+
*
132+
* @param key 64-bit DES key with parity bits. Must have word (4 bytes) alignment.
133+
* @return 0 no error
134+
* @return -1 parity error
135+
*/
136+
int cau_des_chk_parity(const unsigned char *key);
137+
138+
/*!
139+
* @brief DES: Encrypts a single 8-byte block
140+
*
141+
* This function encrypts a single 8-byte block with DES algorithm.
142+
*
143+
* @param in Pointer to 8-byte block of input plaintext
144+
* @param key Pointer to 64-bit DES key with parity bits
145+
* @param[out] out Pointer to 8-byte block of output ciphertext
146+
* @note All pointers must have word (4 bytes) alignment
147+
* @note Input and output blocks may overlap.
148+
*/
149+
void cau_des_encrypt(const unsigned char *in, const unsigned char *key, unsigned char *out);
150+
151+
/*!
152+
* @brief DES: Decrypts a single 8-byte block
153+
*
154+
* This function decrypts a single 8-byte block with DES algorithm.
155+
*
156+
* @param in Pointer to 8-byte block of input ciphertext
157+
* @param key Pointer to 64-bit DES key with parity bits
158+
* @param[out] out Pointer to 8-byte block of output plaintext
159+
* @note All pointers must have word (4 bytes) alignment
160+
* @note Input and output blocks may overlap.
161+
*/
162+
void cau_des_decrypt(const unsigned char *in, const unsigned char *key, unsigned char *out);
163+
164+
/*!
165+
* @brief MD5: Initializes the MD5 state variables
166+
*
167+
* This function initializes the MD5 state variables.
168+
* The output can be used as input to cau_md5_hash() and cau_md5_hash_n().
169+
*
170+
* @param[out] md5_state Pointer to 128-bit block of md5 state variables: a,b,c,d
171+
* @note All pointers must have word (4 bytes) alignment
172+
*/
173+
void cau_md5_initialize_output(const unsigned char *md5_state);
174+
175+
/*!
176+
* @brief MD5: Updates MD5 state variables with n message blocks
177+
*
178+
* This function updates MD5 state variables for one or more input message blocks
179+
*
180+
* @param msg_data Pointer to start of input message data
181+
* @param num_blks Number of 512-bit blocks to process
182+
* @param[in,out] md5_state Pointer to 128-bit block of MD5 state variables: a,b,c,d
183+
* @note All pointers must have word (4 bytes) alignment
184+
* @note Input message and digest output blocks must not overlap.
185+
* The cau_md5_initialize_output() function must be called when starting a new hash.
186+
* Useful when handling non-contiguous input message blocks.
187+
*/
188+
void cau_md5_hash_n(const unsigned char *msg_data, const int num_blks, unsigned char *md5_state);
189+
190+
/*!
191+
* @brief MD5: Updates MD5 state variables
192+
*
193+
* This function updates MD5 state variables for one or more input message blocks.
194+
* It starts a new hash as it internally calls cau_md5_initialize_output() first.
195+
*
196+
* @param msg_data Pointer to start of input message data
197+
* @param num_blks Number of 512-bit blocks to process
198+
* @param[out] md5_state Pointer to 128-bit block of MD5 state variables: a,b,c,d
199+
* @note All pointers must have word (4 bytes) alignment
200+
* @note Input message and digest output blocks must not overlap.
201+
* The cau_md5_initialize_output() function is not required to be called
202+
* as it is called internally to start a new hash.
203+
* All input message blocks must be contiguous.
204+
*/
205+
void cau_md5_update(const unsigned char *msg_data, const int num_blks, unsigned char *md5_state);
206+
207+
/*!
208+
* @brief MD5: Updates MD5 state variables with one message block
209+
*
210+
* This function updates MD5 state variables for one input message block
211+
*
212+
* @param msg_data Pointer to start of 512-bits of input message data
213+
* @param[in,out] md5_state Pointer to 128-bit block of MD5 state variables: a,b,c,d
214+
* @note All pointers must have word (4 bytes) alignment
215+
* @note Input message and digest output blocks must not overlap.
216+
* The cau_md5_initialize_output() function must be called when starting a new hash.
217+
*/
218+
void cau_md5_hash(const unsigned char *msg_data, unsigned char *md5_state);
219+
220+
/*!
221+
* @brief SHA1: Initializes the SHA1 state variables
222+
*
223+
* This function initializes the SHA1 state variables.
224+
* The output can be used as input to cau_sha1_hash() and cau_sha1_hash_n().
225+
*
226+
* @param[out] sha1_state Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e
227+
* @note All pointers must have word (4 bytes) alignment
228+
*/
229+
void cau_sha1_initialize_output(const unsigned int *sha1_state);
230+
231+
/*!
232+
* @brief SHA1: Updates SHA1 state variables with n message blocks
233+
*
234+
* This function updates SHA1 state variables for one or more input message blocks
235+
*
236+
* @param msg_data Pointer to start of input message data
237+
* @param num_blks Number of 512-bit blocks to process
238+
* @param[in,out] sha1_state Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e
239+
* @note All pointers must have word (4 bytes) alignment
240+
* @note Input message and digest output blocks must not overlap.
241+
* The cau_sha1_initialize_output() function must be called when starting a new hash.
242+
* Useful when handling non-contiguous input message blocks.
243+
*/
244+
void cau_sha1_hash_n(const unsigned char *msg_data, const int num_blks, unsigned int *sha1_state);
245+
246+
/*!
247+
* @brief SHA1: Updates SHA1 state variables
248+
*
249+
* This function updates SHA1 state variables for one or more input message blocks.
250+
* It starts a new hash as it internally calls cau_sha1_initialize_output() first.
251+
*
252+
* @param msg_data Pointer to start of input message data
253+
* @param num_blks Number of 512-bit blocks to process
254+
* @param[out] sha1_state Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e
255+
* @note All pointers must have word (4 bytes) alignment
256+
* @note Input message and digest output blocks must not overlap.
257+
* The cau_sha1_initialize_output() function is not required to be called
258+
* as it is called internally to start a new hash.
259+
* All input message blocks must be contiguous.
260+
*/
261+
void cau_sha1_update(const unsigned char *msg_data, const int num_blks, unsigned int *sha1_state);
262+
263+
/*!
264+
* @brief SHA1: Updates SHA1 state variables with one message block
265+
*
266+
* This function updates SHA1 state variables for one input message block
267+
*
268+
* @param msg_data Pointer to start of 512-bits of input message data
269+
* @param[in,out] sha1_state Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e
270+
* @note All pointers must have word (4 bytes) alignment
271+
* @note Input message and digest output blocks must not overlap.
272+
* The cau_sha1_initialize_output() function must be called when starting a new hash.
273+
*/
274+
void cau_sha1_hash(const unsigned char *msg_data, unsigned int *sha1_state);
275+
276+
/*!
277+
* @brief SHA256: Initializes the SHA256 state variables
278+
*
279+
* This function initializes the SHA256 state variables.
280+
* The output can be used as input to cau_sha256_hash() and cau_sha256_hash_n().
281+
*
282+
* @param[out] sha256_state Pointer to 256-bit block of SHA2 state variables a,b,c,d,e,f,g,h
283+
* @note All pointers must have word (4 bytes) alignment
284+
* @return 0 No error. CAU hardware support for SHA256 is present.
285+
* @return -1 Error. CAU hardware support for SHA256 is not present.
286+
*/
287+
int cau_sha256_initialize_output(const unsigned int *output);
288+
289+
/*!
290+
* @brief SHA256: Updates SHA256 state variables with n message blocks
291+
*
292+
* This function updates SHA256 state variables for one or more input message blocks
293+
*
294+
* @param msg_data Pointer to start of input message data
295+
* @param num_blks Number of 512-bit blocks to process
296+
* @param[in,out] sha256_state Pointer to 256-bit block of SHA2 state variables: a,b,c,d,e,f,g,h
297+
* @note All pointers must have word (4 bytes) alignment
298+
* @note Input message and digest output blocks must not overlap.
299+
* The cau_sha256_initialize_output() function must be called when starting a new hash.
300+
* Useful when handling non-contiguous input message blocks.
301+
*/
302+
void cau_sha256_hash_n(const unsigned char *input, const int num_blks, unsigned int *output);
303+
304+
/*!
305+
* @brief SHA256: Updates SHA256 state variables
306+
*
307+
* This function updates SHA256 state variables for one or more input message blocks.
308+
* It starts a new hash as it internally calls cau_sha256_initialize_output() first.
309+
*
310+
* @param msg_data Pointer to start of input message data
311+
* @param num_blks Number of 512-bit blocks to process
312+
* @param[out] sha256_state Pointer to 256-bit block of SHA2 state variables: a,b,c,d,e,f,g,h
313+
* @note All pointers must have word (4 bytes) alignment
314+
* @note Input message and digest output blocks must not overlap.
315+
* The cau_sha256_initialize_output() function is not required to be called
316+
* as it is called internally to start a new hash.
317+
* All input message blocks must be contiguous.
318+
*/
319+
void cau_sha256_update(const unsigned char *input, const int num_blks, unsigned int *output);
320+
321+
/*!
322+
* @brief SHA256: Updates SHA256 state variables with one message block
323+
*
324+
* This function updates SHA256 state variables for one input message block
325+
*
326+
* @param msg_data Pointer to start of 512-bits of input message data
327+
* @param[in,out] sha256_state Pointer to 256-bit block of SHA2 state variables: a,b,c,d,e,f,g,h
328+
* @note All pointers must have word (4 bytes) alignment
329+
* @note Input message and digest output blocks must not overlap.
330+
* The cau_sha256_initialize_output() function must be called when starting a new hash.
331+
*/
332+
void cau_sha256_hash(const unsigned char *input, unsigned int *output);
333+
334+
#if defined(__cplusplus)
335+
}
336+
#endif
337+
338+
/*! @}*/
339+
#endif /* _CAU_API_H_ */

0 commit comments

Comments
 (0)