CC13xx Driver Library
rom_crypto.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: rom_crypto.h
3 * Revised: 2015-07-16 12:12:04 +0200 (Thu, 16 Jul 2015)
4 * Revision: 44151
5 *
6 * Description: This header file is the API to the AES, ECC and SHA256
7 * functions built into ROM on the CC26xx.
8 *
9 * Copyright (c) 2015, Texas Instruments Incorporated
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1) Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 *
18 * 2) Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 *
22 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
23 * be used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 *******************************************************************************/
39 
40 //*****************************************************************************
41 //
46 //
47 //*****************************************************************************
48 
49 #ifndef ROM_CRYPTO_H
50 #define ROM_CRYPTO_H
51 
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
58 
59 //*****************************************************************************
69 //*****************************************************************************
70 extern void AES_ECB_EncryptData(uint8_t *text, uint16_t textLen, uint8_t *aesKey);
71 
72 //*****************************************************************************
83 //*****************************************************************************
84 extern void AES_ECB_DecryptData(uint8_t *text, uint16_t textLen, uint8_t *aesKey);
85 
86 //*****************************************************************************
105 //*****************************************************************************
106 extern int8_t AES_CCM_EncryptData(uint8_t encryptFlag, uint8_t MACLen, uint8_t *nonce,
107  uint8_t *plainText, uint16_t textLen,
108  uint8_t *addDataBuf, uint16_t addBufLen,
109  uint8_t *aesKey, uint8_t *MAC, uint8_t ccmLVal);
110 
111 //*****************************************************************************
130 //*****************************************************************************
131 extern int8_t AES_CCM_DecryptData(uint8_t decryptFlag, uint8_t MACLen, uint8_t *nonce,
132  uint8_t *cipherText, uint16_t textLen,
133  uint8_t *addDataBuf, uint16_t addBufLen,
134  uint8_t *aesKey, uint8_t *MAC, uint8_t ccmLVal);
135 
136 //*****************************************************************************
148 //*****************************************************************************
149 extern uint8_t AES_CTR_EncryptData(uint8_t *plainText, uint16_t textLen,
150  uint8_t *aesKey, uint8_t *nonce,
151  uint8_t *initVector);
152 
153 //*****************************************************************************
165 //*****************************************************************************
166 extern uint8_t AES_CTR_DecryptData(uint8_t *cipherText, uint16_t textLen,
167  uint8_t *aesKey, uint8_t *nonce,
168  uint8_t *initVector);
169 
171 
172 /* Window size, valid values are 2,3,4,5.
173  * Higher the value, faster the computation at the expense of memory usage.
174  *
175  * Recommended workzone size (in 4-byte words)
176  * Window size: 3, Workzone size: 275
177  *
178  */
179 #define ECC_WINDOW_SIZE 3
180 
181 /*
182  * ECC Supported Curves, define one:
183  * ECC_PRIME_NIST256_CURVE
184  */
185 #define ECC_PRIME_NIST256_CURVE
186 
187 /*
188  * ECC Return Status Flags.
189  */
190 // Scalar multiplication status
191 #define ECC_MODULUS_EVEN 0xDC
192 #define ECC_MODULUS_LARGER_THAN_255_WORDS 0xD2
193 #define ECC_MODULUS_LENGTH_ZERO 0x08
194 #define ECC_MODULUS_MSW_IS_ZERO 0x30
195 #define ECC_SCALAR_TOO_LONG 0x35
196 #define ECC_SCALAR_LENGTH_ZERO 0x53
197 #define ECC_ORDER_TOO_LONG 0xC6
198 #define ECC_ORDER_LENGTH_ZERO 0x6C
199 #define ECC_X_COORD_TOO_LONG 0x3C
200 #define ECC_X_COORD_LENGTH_ZERO 0xC3
201 #define ECC_Y_COORD_TOO_LONG 0x65
202 #define ECC_Y_COORD_LENGTH_ZERO 0x56
203 #define ECC_A_COEF_TOO_LONG 0x5C
204 #define ECC_A_COEF_LENGTH_ZERO 0xC5
205 #define ECC_BAD_WINDOW_SIZE 0x66
206 #define ECC_SCALAR_MUL_OK 0x99
207 
208 // ECDSA and ECDH status
209 #define ECC_ORDER_LARGER_THAN_255_WORDS 0x28
210 #define ECC_ORDER_EVEN 0x82
211 #define ECC_ORDER_MSW_IS_ZERO 0x23
212 #define ECC_ECC_KEY_TOO_LONG 0x25
213 #define ECC_ECC_KEY_LENGTH_ZERO 0x52
214 #define ECC_DIGEST_TOO_LONG 0x27
215 #define ECC_DIGEST_LENGTH_ZERO 0x72
216 #define ECC_ECDSA_SIGN_OK 0x32
217 #define ECC_ECDSA_INVALID_SIGNATURE 0x5A
218 #define ECC_ECDSA_VALID_SIGNATURE 0xA5
219 #define ECC_SIG_P1_TOO_LONG 0x11
220 #define ECC_SIG_P1_LENGTH_ZERO 0x12
221 #define ECC_SIG_P2_TOO_LONG 0x22
222 #define ECC_SIG_P2_LENGTH_ZERO 0x21
223 
224 #define ECC_ECDSA_KEYGEN_OK ECC_SCALAR_MUL_OK
225 #define ECC_ECDH_KEYGEN_OK ECC_SCALAR_MUL_OK
226 #define ECC_ECDH_COMMON_KEY_OK ECC_SCALAR_MUL_OK
227 
228 //*****************************************************************************
241 //*****************************************************************************
242  extern void ECC_initialize(uint32_t *pWorkzone);
243 
244 //*****************************************************************************
257 //*****************************************************************************
258 extern uint8_t ECC_generateKey(uint32_t *randString, uint32_t *privateKey,
259  uint32_t *publicKey_x, uint32_t *publicKey_y);
260 
261 //*****************************************************************************
273 //*****************************************************************************
274 extern uint8_t ECC_ECDSA_sign(uint32_t *secretKey, uint32_t *text, uint32_t *randString,
275  uint32_t *sign1, uint32_t *sign2);
276 
277 //*****************************************************************************
289 //*****************************************************************************
290 extern uint8_t ECC_ECDSA_verify(uint32_t *publicKey_x, uint32_t *publicKey_y,
291  uint32_t *text, uint32_t *sign1, uint32_t *sign2);
292 
293 //*****************************************************************************
305 //*****************************************************************************
306 extern uint8_t ECC_ECDH_computeSharedSecret(uint32_t *privateKey,
307  uint32_t *publicKey_x,
308  uint32_t *publicKey_y,
309  uint32_t *sharedSecret_x,
310  uint32_t *sharedSecret_y);
311 
312 
314 
317 typedef struct
318 {
319  uint32_t state[8];
320  uint32_t textLen[2];
321  uint32_t W[16];
323 
324 //*****************************************************************************
339 //*****************************************************************************
340 extern uint8_t SHA256_runFullAlgorithm(SHA256_memory_t *memory, uint8_t *pBufIn,
341  uint32_t bufLen, uint8_t *pBufOut);
342 
343 //*****************************************************************************
354 //*****************************************************************************
355 extern uint8_t SHA256_initialize(SHA256_memory_t *workZone);
356 
357 //*****************************************************************************
369 //*****************************************************************************
370 extern uint8_t SHA256_execute(SHA256_memory_t *config, uint8_t *pBufIn,
371  uint32_t bufLen);
372 
373 //*****************************************************************************
382 //*****************************************************************************
383 extern uint8_t SHA256_output(SHA256_memory_t *memory, uint8_t *pBufOut);
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 
389 #endif /* ROM_CRYPTO_H */
390 
391 //*****************************************************************************
392 //
396 //
397 //*****************************************************************************
uint8_t SHA256_initialize(SHA256_memory_t *workZone)
Intializes the SHA256 engine.
Definition: rom_crypto.c:285
A SHA256_memory_t variable of this type must be allocated before running any SHA256 functions...
Definition: rom_crypto.h:317
uint8_t AES_CTR_DecryptData(uint8_t *cipherText, uint16_t textLen, uint8_t *aesKey, uint8_t *nonce, uint8_t *initVector)
Decrypt ciphertext using the AES key, nonce and initialization vector.
Definition: rom_crypto.c:132
uint8_t AES_CTR_EncryptData(uint8_t *plainText, uint16_t textLen, uint8_t *aesKey, uint8_t *nonce, uint8_t *initVector)
Encrypt plaintext using the AES key, nonce and initialization vector.
Definition: rom_crypto.c:121
int8_t AES_CCM_DecryptData(uint8_t decryptFlag, uint8_t MACLen, uint8_t *nonce, uint8_t *cipherText, uint16_t textLen, uint8_t *addDataBuf, uint16_t addBufLen, uint8_t *aesKey, uint8_t *MAC, uint8_t ccmLVal)
Authenticate and optionally decrypt message cipherText.
Definition: rom_crypto.c:98
uint8_t ECC_generateKey(uint32_t *randString, uint32_t *privateKey, uint32_t *publicKey_x, uint32_t *publicKey_y)
Generate a key.
Definition: rom_crypto.c:213
uint8_t SHA256_execute(SHA256_memory_t *config, uint8_t *pBufIn, uint32_t bufLen)
Perform SHA256.
Definition: rom_crypto.c:294
void AES_ECB_DecryptData(uint8_t *text, uint16_t textLen, uint8_t *aesKey)
Use a random 128 bit key to decrypt data with the AES.
Definition: rom_crypto.c:65
int8_t AES_CCM_EncryptData(uint8_t encryptFlag, uint8_t MACLen, uint8_t *nonce, uint8_t *plainText, uint16_t textLen, uint8_t *addDataBuf, uint16_t addBufLen, uint8_t *aesKey, uint8_t *MAC, uint8_t ccmLVal)
Authenticate and optionally encrypt message plainText.
Definition: rom_crypto.c:85
uint8_t ECC_ECDSA_sign(uint32_t *secretKey, uint32_t *text, uint32_t *randString, uint32_t *sign1, uint32_t *sign2)
Sign data.
Definition: rom_crypto.c:225
void AES_ECB_EncryptData(uint8_t *text, uint16_t textLen, uint8_t *aesKey)
Use a random 128 bit key to encrypt data with the AES.
Definition: rom_crypto.c:56
uint8_t ECC_ECDH_computeSharedSecret(uint32_t *privateKey, uint32_t *publicKey_x, uint32_t *publicKey_y, uint32_t *sharedSecret_x, uint32_t *sharedSecret_y)
Compute the shared secret.
Definition: rom_crypto.c:247
uint8_t SHA256_output(SHA256_memory_t *memory, uint8_t *pBufOut)
Complete the process by passing the modified data back.
Definition: rom_crypto.c:303
void ECC_initialize(uint32_t *pWorkzone)
Pass pointer to ECC memory allocation to ECC engine.
Definition: rom_crypto.c:167
uint8_t SHA256_runFullAlgorithm(SHA256_memory_t *memory, uint8_t *pBufIn, uint32_t bufLen, uint8_t *pBufOut)
Perform SHA256 on the the input data.
Definition: rom_crypto.c:275
uint8_t ECC_ECDSA_verify(uint32_t *publicKey_x, uint32_t *publicKey_y, uint32_t *text, uint32_t *sign1, uint32_t *sign2)
Verify signature.
Definition: rom_crypto.c:236