CC13xx Driver Library
[rom_crypto.h] Software Crypto

Data Structures

struct  SHA256_memory_t
 A SHA256_memory_t variable of this type must be allocated before running any SHA256 functions. More...
 

Functions

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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void ECC_initialize (uint32_t *pWorkzone)
 Pass pointer to ECC memory allocation to ECC engine. More...
 
uint8_t ECC_generateKey (uint32_t *randString, uint32_t *privateKey, uint32_t *publicKey_x, uint32_t *publicKey_y)
 Generate a key. More...
 
uint8_t ECC_ECDSA_sign (uint32_t *secretKey, uint32_t *text, uint32_t *randString, uint32_t *sign1, uint32_t *sign2)
 Sign data. More...
 
uint8_t ECC_ECDSA_verify (uint32_t *publicKey_x, uint32_t *publicKey_y, uint32_t *text, uint32_t *sign1, uint32_t *sign2)
 Verify signature. More...
 
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. More...
 
uint8_t SHA256_runFullAlgorithm (SHA256_memory_t *memory, uint8_t *pBufIn, uint32_t bufLen, uint8_t *pBufOut)
 Perform SHA256 on the input data. More...
 
uint8_t SHA256_initialize (SHA256_memory_t *workZone)
 Intializes the SHA256 engine. More...
 
uint8_t SHA256_execute (SHA256_memory_t *config, uint8_t *pBufIn, uint32_t bufLen)
 Perform SHA256. More...
 
uint8_t SHA256_output (SHA256_memory_t *memory, uint8_t *pBufOut)
 Complete the process by passing the modified data back. More...
 

Detailed Description

Function Documentation

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.

Parameters
decryptFlagDecryption flag.
  • true for authentication with decryption.
  • false for authentication only.
MACLenLength of MAC in bytes.
noncePointer to random nonce. Nonce length = 15 - ccmLVal.
cipherTextPointer to text to decrypt, input and output.
textLenLength of text to decrypt.
addDataBufPointer to additional data for authentication
addBufLenAdditional authentication buffer length.
aesKeyPointer to the AES key or key expansion buffer.
MACPointer to 16 byte Message Authentication Code output buffer.
ccmLValCCM L value to be used. Values {2,3}.
Returns
Zero when Successful.
102 {
103  return aes_ccm_decrypt(decryptFlag, MACLen, nonce, cipherText, textLen,
104  addDataBuf, addBufLen, aesKey, MAC, ccmLVal);
105 
106 }
aes_ccm_decrypt_t aes_ccm_decrypt
Definition: rom_crypto.c:79
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.

Parameters
encryptFlagEncryption flag.
  • set to true for authentication with encryption.
  • set to false for authentication only.
MACLenLength of MAC in bytes.
noncePointer to random nonce. Nonce length = 15 - ccmLVal.
plainTextPointer to text to encrypt, input and output.
textLenLength of text to encrypt.
addDataBufPointer to additional data for authentication
addBufLenAdditional authentication buffer length.
aesKeyPointer to the AES key or key expansion buffer.
MACPointer to 16 byte Message Authentication Code output buffer.
ccmLValCCM L value to be used. Values {2,3}.
Returns
Zero when successful.
89 {
90  return aes_ccm_encrypt(encryptFlag, MACLen, nonce, plainText, textLen,
91  addDataBuf, addBufLen, aesKey, MAC, ccmLVal);
92 }
aes_ccm_encrypt_t aes_ccm_encrypt
Definition: rom_crypto.c:74
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.

Parameters
cipherTextPointer to text to decrypt
textLenLength of text.
aesKeyPointer to 128 bit key used to encrypt text.
noncePointer to 4 byte nonce.
initVectorPointer to 8 byte random initialization vector.
Returns
None
135 {
136  return aes_ctr_decrypt(cipherText, textLen, aesKey, nonce, initVector);
137 }
aes_ctr_decrypt_t aes_ctr_decrypt
Definition: rom_crypto.c:115
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.

Parameters
plainTextPointer to text to encrypt.
textLenLength of text.
aesKeyPointer to 128 bit key used to encrypt text.
noncePointer to 4 byte nonce.
initVectorPointer to 8 byte random initialization vector.
Returns
None
124 {
125  return aes_ctr_encrypt(plainText, textLen, aesKey, nonce, initVector);
126 }
aes_ctr_encrypt_t aes_ctr_encrypt
Definition: rom_crypto.c:111
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.

Parameters
textPointer to data to decrypt.
textLenLength of text.
aesKeyPointer to 128 bit key used to decrypt. This is the same key that was used to originally encrypt this data.
Returns
None
66 {
67  aes_ecb_decrypt(text, textLen, aesKey);
68 }
aes_ecb_decrypt_t aes_ecb_decrypt
Definition: rom_crypto.c:50
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.

Parameters
textPointer to data to encrypt.
textLenLength of text.
aesKeyPointer to 128 bit key used to encrypt text.
Returns
None
57 {
58  aes_ecb_encrypt(text, textLen, aesKey);
59 }
aes_ecb_encrypt_t aes_ecb_encrypt
Definition: rom_crypto.c:47
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.

Parameters
privateKeyPointer to private key, input.
publicKey_xPointer to public key X-coordinate, input.
publicKey_yPointer to public key Y-coordinate, input.
sharedSecret_xPointer to shared secret X-coordinate, output.
sharedSecret_yPointer to shared secret Y-coordinate, output.
Returns
Status
250 {
251  return (uint8_t)ecdh_computeSharedSecret((uint32_t*)privateKey, (uint32_t*)publicKey_x,
252  (uint32_t*)publicKey_y, (uint32_t*)sharedSecret_x,
253  (uint32_t*)sharedSecret_y);
254 }
ecdh_computeSharedSecret_t ecdh_computeSharedSecret
Definition: rom_crypto.c:207
uint8_t ECC_ECDSA_sign ( uint32_t *  secretKey,
uint32_t *  text,
uint32_t *  randString,
uint32_t *  sign1,
uint32_t *  sign2 
)

Sign data.

Parameters
secretKeyPointer to the secret key, input.
textPointer to the message, input.
randStringPointer to random string, input.
sign1Pointer to signature part 1, output.
sign2Pointer to signature part 2, output.
Returns
Status
227 {
228  return (uint8_t)ecc_ecdsa_sign((uint32_t*)secretKey, (uint32_t*)text, (uint32_t*)randString,
229  (uint32_t*)sign1, (uint32_t*)sign2);
230 }
ecdsa_sign_t ecc_ecdsa_sign
Definition: rom_crypto.c:201
uint8_t ECC_ECDSA_verify ( uint32_t *  publicKey_x,
uint32_t *  publicKey_y,
uint32_t *  text,
uint32_t *  sign1,
uint32_t *  sign2 
)

Verify signature.

Parameters
publicKey_xPointer to public key X-coordinate, input.
publicKey_yPointer to public key Y-coordinate, input.
textPointer to message data, input.
sign1Pointer to signature part 1, input.
sign2Pointer to signature part 2, input.
Returns
Status
238 {
239  return (uint8_t)ecc_ecdsa_verify((uint32_t*)publicKey_x, (uint32_t*)publicKey_y, (uint32_t*)text,
240  (uint32_t*)sign1, (uint32_t*)sign2);
241 }
ecdsa_verify_t ecc_ecdsa_verify
Definition: rom_crypto.c:204
uint8_t ECC_generateKey ( uint32_t *  randString,
uint32_t *  privateKey,
uint32_t *  publicKey_x,
uint32_t *  publicKey_y 
)

Generate a key.

This is used for both ECDH and ECDSA.

Parameters
randStringPointer to random string, input.
privateKeyPointer to the private key, output.
publicKey_xPointer to public key X-coordinate, output.
publicKey_yPointer to public key Y-coordinate, output.
Returns
Status
215 {
216  return (uint8_t)ecc_generatekey((uint32_t*)randString, (uint32_t*)privateKey,
217  (uint32_t*)publicKey_x, (uint32_t*)publicKey_y);
218 
219 }
ecc_keygen_t ecc_generatekey
Definition: rom_crypto.c:198
void ECC_initialize ( uint32_t *  pWorkzone)

Pass pointer to ECC memory allocation to ECC engine.

This function can be called again to point the ECC workzone at a different memory buffer.

Parameters
pWorkzonePointer to memory allocated for computations, input. See description at beginning of ECC section for memory requirements.
Returns
None
168 {
169  // Initialize curve parameters
170  //data_p = (uint32_t *)PARAM_P;
171  *((uint32_t **)0x20004f48) = (uint32_t *)PARAM_P;
172 
173  //data_r = (uint32_t *)PARAM_R;
174  *((uint32_t **)0x20004f4c) = (uint32_t *)PARAM_R;
175 
176  //data_a = (uint32_t *)PARAM_A;
177  *((uint32_t **)0x20004f50) = (uint32_t *)PARAM_A;
178 
179  //data_b = (uint32_t *)PARAM_B;
180  *((uint32_t **)0x20004fa8) = (uint32_t *)PARAM_B;
181 
182  //data_Gx = (uint32_t *)PARAM_GX;
183  *((uint32_t **)0x20004fa0) = (uint32_t *)PARAM_GX;
184 
185  //data_Gy = (uint32_t *)PARAM_GY;
186  *((uint32_t **)0x20004fa4) = (uint32_t *)PARAM_GY;
187 
188  // Initialize window size
189  //win = (uint8_t) ECC_WINDOW_SIZE;
190  *((uint8_t *)0x20004f40) = (uint8_t) ECC_WINDOW_SIZE;
191 
192  // Initialize work zone
193  //workzone = (uint32_t *) pWorkzone;
194  *((uint32_t **)0x20004f44) = (uint32_t *) pWorkzone;
195 }
#define PARAM_P
Definition: rom_crypto.c:143
#define PARAM_R
Definition: rom_crypto.c:146
#define PARAM_A
Definition: rom_crypto.c:149
#define PARAM_GX
Definition: rom_crypto.c:155
#define PARAM_GY
Definition: rom_crypto.c:158
#define ECC_WINDOW_SIZE
Definition: rom_crypto.h:179
#define PARAM_B
Definition: rom_crypto.c:152
uint8_t SHA256_execute ( SHA256_memory_t config,
uint8_t *  pBufIn,
uint32_t  bufLen 
)

Perform SHA256.

Must call SHA256_output() to receive output from this operation.

Parameters
configPointer to memory for operations, input.
pBufInPointer to input text, input.
bufLenLength of input, input.
Returns
Status
295 {
296  return (uint8_t)sha256_execute(memory,pBufIn, bufLen);
297 }
sha256_process_t sha256_execute
Definition: rom_crypto.c:266
uint8_t SHA256_initialize ( SHA256_memory_t workZone)

Intializes the SHA256 engine.

This function must be called once before all other SHA256 functions other than SHA256_runFullAlgorithm().

Parameters
workZonePointer to memory for operations, input.
Returns
Status
286 {
287  return (uint8_t)sha256_initialize(memory);
288 }
sha256_init_t sha256_initialize
Definition: rom_crypto.c:263
uint8_t SHA256_output ( SHA256_memory_t memory,
uint8_t *  pBufOut 
)

Complete the process by passing the modified data back.

Parameters
memoryPointer to memory for operations, input.
pBufOutPointer to output buffer, output. Buffer must be at least 32 bytes long.
Returns
Status
304 {
305  return (uint8_t)sha256_output(memory, pBufOut);
306 }
sha256_final_t sha256_output
Definition: rom_crypto.c:269
uint8_t SHA256_runFullAlgorithm ( SHA256_memory_t memory,
uint8_t *  pBufIn,
uint32_t  bufLen,
uint8_t *  pBufOut 
)

Perform SHA256 on the input data.

The input and output buffer can point to the same memory. This is the equivalent of calling SHA256_initialize(), SHA256_execute() and SHA256_output() sequentially.

Parameters
memoryPointer to memory for operations, input.
pBufInPointer to input buffer, input.
bufLenLength of input.
pBufOutPointer to output buffer, output.
Returns
Status
277 {
278  return (uint8_t)sha256_runfullalg(memory, pBufOut, pBufIn, bufLen);
279 }
sha256_full_t sha256_runfullalg
Definition: rom_crypto.c:260

Macro Definition Documentation

#define ECC_A_COEF_LENGTH_ZERO   0xC5
#define ECC_A_COEF_TOO_LONG   0x5C
#define ECC_BAD_WINDOW_SIZE   0x66
#define ECC_DIGEST_LENGTH_ZERO   0x72
#define ECC_DIGEST_TOO_LONG   0x27
#define ECC_ECC_KEY_LENGTH_ZERO   0x52
#define ECC_ECC_KEY_TOO_LONG   0x25
#define ECC_ECDH_COMMON_KEY_OK   ECC_SCALAR_MUL_OK
#define ECC_ECDH_KEYGEN_OK   ECC_SCALAR_MUL_OK
#define ECC_ECDSA_INVALID_SIGNATURE   0x5A
#define ECC_ECDSA_KEYGEN_OK   ECC_SCALAR_MUL_OK
#define ECC_ECDSA_SIGN_OK   0x32
#define ECC_ECDSA_VALID_SIGNATURE   0xA5
#define ECC_MODULUS_EVEN   0xDC
#define ECC_MODULUS_LARGER_THAN_255_WORDS   0xD2
#define ECC_MODULUS_LENGTH_ZERO   0x08
#define ECC_MODULUS_MSW_IS_ZERO   0x30
#define ECC_ORDER_EVEN   0x82
#define ECC_ORDER_LARGER_THAN_255_WORDS   0x28
#define ECC_ORDER_LENGTH_ZERO   0x6C
#define ECC_ORDER_MSW_IS_ZERO   0x23
#define ECC_ORDER_TOO_LONG   0xC6
#define ECC_PRIME_NIST256_CURVE
#define ECC_SCALAR_LENGTH_ZERO   0x53
#define ECC_SCALAR_MUL_OK   0x99
#define ECC_SCALAR_TOO_LONG   0x35
#define ECC_SIG_P1_LENGTH_ZERO   0x12
#define ECC_SIG_P1_TOO_LONG   0x11
#define ECC_SIG_P2_LENGTH_ZERO   0x21
#define ECC_SIG_P2_TOO_LONG   0x22
#define ECC_WINDOW_SIZE   3

Referenced by ECC_initialize().

#define ECC_X_COORD_LENGTH_ZERO   0xC3
#define ECC_X_COORD_TOO_LONG   0x3C
#define ECC_Y_COORD_LENGTH_ZERO   0x56
#define ECC_Y_COORD_TOO_LONG   0x65