| M480 BSP V3.05.001 The Board Support Package for M480 Series

Functions
CRYPTO Exported Functions
Standard Driver » CRYPTO Driver

## Functions
void | PRNG_Open (CRPT_T *crpt, uint32_t u32KeySize, uint32_t u32SeedReload, uint32_t u32Seed)
| Open PRNG function. More...
void | PRNG_Start (CRPT_T *crpt)
| Start to generate one PRNG key. More...
void | PRNG_Read (CRPT_T *crpt, uint32_t u32RandKey[])
| Read the PRNG key. More...
void | AES_Open (CRPT_T *crpt, uint32_t u32Channel, uint32_t u32EncDec, uint32_t u32OpMode, uint32_t u32KeySize, uint32_t u32SwapType)
| Open AES encrypt/decrypt function. More...
void | AES_Start (CRPT_T *crpt, uint32_t u32Channel, uint32_t u32DMAMode)
| Start AES encrypt/decrypt. More...
void | AES_SetKey (CRPT_T *crpt, uint32_t u32Channel, uint32_t au32Keys[], uint32_t u32KeySize)
| Set AES keys. More...
void | AES_SetInitVect (CRPT_T *crpt, uint32_t u32Channel, uint32_t au32IV[])
| Set AES initial vectors. More...
void | AES_SetDMATransfer (CRPT_T *crpt, uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt)
| Set AES DMA transfer configuration. More...
void | TDES_Open (CRPT_T *crpt, uint32_t u32Channel, uint32_t u32EncDec, int32_t Is3DES, int32_t Is3Key, uint32_t u32OpMode, uint32_t u32SwapType)
| Open TDES encrypt/decrypt function. More...
void | TDES_Start (CRPT_T *crpt, int32_t u32Channel, uint32_t u32DMAMode)
| Start TDES encrypt/decrypt. More...
void | TDES_SetKey (CRPT_T *crpt, uint32_t u32Channel, uint32_t au32Keys[3][2])
| Set TDES keys. More...
void | TDES_SetInitVect (CRPT_T *crpt, uint32_t u32Channel, uint32_t u32IVH, uint32_t u32IVL)
| Set TDES initial vectors. More...
void | TDES_SetDMATransfer (CRPT_T *crpt, uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt)
| Set TDES DMA transfer configuration. More...
void | SHA_Open (CRPT_T *crpt, uint32_t u32OpMode, uint32_t u32SwapType, uint32_t hmac_key_len)
| Open SHA encrypt function. More...
void | SHA_Start (CRPT_T *crpt, uint32_t u32DMAMode)
| Start SHA encrypt. More...
void | SHA_SetDMATransfer (CRPT_T *crpt, uint32_t u32SrcAddr, uint32_t u32TransCnt)
| Set SHA DMA transfer. More...
void | SHA_Read (CRPT_T *crpt, uint32_t u32Digest[])
| Read the SHA digest. More...
void | ECC_Complete (CRPT_T *crpt)
| ECC interrupt service routine. User application must invoke this function in his CRYPTO_IRQHandler() to let Crypto driver know ECC processing was done. More...
int | ECC_IsPrivateKeyValid (CRPT_T *crpt, E_ECC_CURVE ecc_curve, char private_k[])
| Check if the private key is located in valid range of curve. More...
int32_t | ECC_GeneratePublicKey (CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *private_k, char public_k1[], char public_k2[])
| Given a private key and curve to generate the public key pair. More...
int32_t | ECC_Mutiply (CRPT_T *crpt, E_ECC_CURVE ecc_curve, char x1[], char y1[], char *k, char x2[], char y2[])
| Given a private key and curve to generate the public key pair. More...
int32_t | ECC_GenerateSecretZ (CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *private_k, char public_k1[], char public_k2[], char secret_z[])
| Given a curve parameter, the other party's public key, and one's own private key to generate the secret Z. More...
int32_t | ECC_GenerateSignature (CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *message, char *d, char *k, char *R, char *S)
| ECDSA digital signature generation. More...
int32_t | ECC_VerifySignature (CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *message, char *public_k1, char *public_k2, char *R, char *S)
| ECDSA dogotal signature verification. More...

## Detailed Description

## Function Documentation

## ◆ AES_Open()

void AES_Open | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | u32EncDec,
|  | uint32_t | u32OpMode,
|  | uint32_t | u32KeySize,
|  | uint32_t | u32SwapType
| ) |  |

Open AES encrypt/decrypt function.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | AES channel. Must be 0~3.
  [in] | u32EncDec | 1: AES encode; 0: AES decode
  [in] | u32OpMode | AES operation mode, including: AES_MODE_ECB AES_MODE_CBC AES_MODE_CFB AES_MODE_OFB AES_MODE_CTR AES_MODE_CBC_CS1 AES_MODE_CBC_CS2 AES_MODE_CBC_CS3
  [in] | u32KeySize | is AES key size, including: AES_KEY_SIZE_128 AES_KEY_SIZE_192 AES_KEY_SIZE_256
  [in] | u32SwapType | is AES input/output data swap control, including: AES_NO_SWAP AES_OUT_SWAP AES_IN_SWAP AES_IN_OUT_SWAP

Returns
  None

Definition at line 138 of file crypto.c.

## ◆ AES_SetDMATransfer()

void AES_SetDMATransfer | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | u32SrcAddr,
|  | uint32_t | u32DstAddr,
|  | uint32_t | u32TransCnt
| ) |  |

Set AES DMA transfer configuration.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | AES channel. Must be 0~3.
  [in] | u32SrcAddr | AES DMA source address
  [in] | u32DstAddr | AES DMA destination address
  [in] | u32TransCnt | AES DMA transfer byte count

Returns
  None

Definition at line 219 of file crypto.c.

## ◆ AES_SetInitVect()

void AES_SetInitVect | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | au32IV[]
| ) |  |

Set AES initial vectors.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | AES channel. Must be 0~3.
  [in] | au32IV | A four entry word array contains AES initial vectors.

Returns
  None

Definition at line 197 of file crypto.c.

## ◆ AES_SetKey()

void AES_SetKey | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | au32Keys[],
|  | uint32_t | u32KeySize
| ) |  |

Set AES keys.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | AES channel. Must be 0~3.
  [in] | au32Keys | An word array contains AES keys.
  [in] | u32KeySize | is AES key size, including: AES_KEY_SIZE_128 AES_KEY_SIZE_192 AES_KEY_SIZE_256

Returns
  None

Definition at line 176 of file crypto.c.

## ◆ AES_Start()

void AES_Start | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | u32DMAMode
| ) |  |

Start AES encrypt/decrypt.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | AES channel. Must be 0~3.
  [in] | u32DMAMode | AES DMA control, including: CRYPTO_DMA_ONE_SHOT One shop AES encrypt/decrypt. CRYPTO_DMA_CONTINUE Continuous AES encrypt/decrypt. CRYPTO_DMA_LAST Last AES encrypt/decrypt of a series of AES_Start.

Returns
  None

Definition at line 159 of file crypto.c.

## ◆ ECC_Complete()

void ECC_Complete | ( | CRPT_T * | crpt | ) |

ECC interrupt service routine. User application must invoke this function in his CRYPTO_IRQHandler() to let Crypto driver know ECC processing was done.

HIDDEN_SYMBOLS

Parameters

  [in] | crpt | Reference to Crypto module.

Returns
  none

Definition at line 1139 of file crypto.c.

## ◆ ECC_GeneratePublicKey()

int32_t ECC_GeneratePublicKey | ( | CRPT_T * | crpt,
|  | E_ECC_CURVE | ecc_curve,
|  | char * | private_k,
|  | char | public_k1[],
|  | char | public_k2[]
| ) |  |

Given a private key and curve to generate the public key pair.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | private_k | The input private key.
  [in] | ecc_curve | The pre-defined ECC curve.
  [out] | public_k1 | The output public key 1.
  [out] | public_k2 | The output public key 2.

Returns
  0 Success.
  -1 "ecc_curve" value is invalid.

Definition at line 1212 of file crypto.c.

## ◆ ECC_GenerateSecretZ()

int32_t ECC_GenerateSecretZ | ( | CRPT_T * | crpt,
|  | E_ECC_CURVE | ecc_curve,
|  | char * | private_k,
|  | char | public_k1[],
|  | char | public_k2[],
|  | char | secret_z[]
| ) |  |

Given a curve parameter, the other party's public key, and one's own private key to generate the secret Z.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | ecc_curve | The pre-defined ECC curve.
  [in] | private_k | One's own private key.
  [in] | public_k1 | The other party's publick key 1.
  [in] | public_k2 | The other party's publick key 2.
  [out] | secret_z | The ECC CDH secret Z.

Returns
  0 Success.
  -1 "ecc_curve" value is invalid.

Definition at line 1325 of file crypto.c.

## ◆ ECC_GenerateSignature()

int32_t ECC_GenerateSignature | ( | CRPT_T * | crpt,
|  | E_ECC_CURVE | ecc_curve,
|  | char * | message,
|  | char * | d,
|  | char * | k,
|  | char * | R,
|  | char * | S
| ) |  |

ECDSA digital signature generation.

HIDDEN_SYMBOLS

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | ecc_curve | The pre-defined ECC curve.
  [in] | message | The hash value of source context.
  [in] | d | The private key.
  [in] | k | The selected random integer.
  [out] | R | R of the (R,S) pair digital signature
  [out] | S | S of the (R,S) pair digital signature

Returns
  0 Success.
  -1 "ecc_curve" value is invalid.

Definition at line 1431 of file crypto.c.

## ◆ ECC_IsPrivateKeyValid()

int ECC_IsPrivateKeyValid | ( | CRPT_T * | crpt,
|  | E_ECC_CURVE | ecc_curve,
|  | char | private_k[]
| ) |  |

Check if the private key is located in valid range of curve.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | ecc_curve | The pre-defined ECC curve.
  [in] | private_k | The input private key.

Returns
  1 Is valid.
  0 Is not valid.
  -1 Invalid curve.

Definition at line 1165 of file crypto.c.

## ◆ ECC_Mutiply()

int32_t ECC_Mutiply | ( | CRPT_T * | crpt,
|  | E_ECC_CURVE | ecc_curve,
|  | char | x1[],
|  | char | y1[],
|  | char * | k,
|  | char | x2[],
|  | char | y2[]
| ) |  |

Given a private key and curve to generate the public key pair.

Parameters

  [in] | crpt | Reference to Crypto module.
  [out] | x1 | The x-coordinate of input point.
  [out] | y1 | The y-coordinate of input point.
  [in] | k | The private key
  [in] | ecc_curve | The pre-defined ECC curve.
  [out] | x2 | The x-coordinate of output point.
  [out] | y2 | The y-coordinate of output point.

Returns
  0 Success.
  -1 "ecc_curve" value is invalid.

Definition at line 1267 of file crypto.c.

## ◆ ECC_VerifySignature()

int32_t ECC_VerifySignature | ( | CRPT_T * | crpt,
|  | E_ECC_CURVE | ecc_curve,
|  | char * | message,
|  | char * | public_k1,
|  | char * | public_k2,
|  | char * | R,
|  | char * | S
| ) |  |

ECDSA dogotal signature verification.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | ecc_curve | The pre-defined ECC curve.
  [in] | message | The hash value of source context.
  [in] | public_k1 | The public key 1.
  [in] | public_k2 | The public key 2.
  [in] | R | R of the (R,S) pair digital signature
  [in] | S | S of the (R,S) pair digital signature

Returns
  0 Success.
  -1 "ecc_curve" value is invalid.
  -2 Verification failed.

Definition at line 1665 of file crypto.c.

## ◆ PRNG_Open()

void PRNG_Open | ( | CRPT_T * | crpt,
|  | uint32_t | u32KeySize,
|  | uint32_t | u32SeedReload,
|  | uint32_t | u32Seed
| ) |  |

Open PRNG function.

HIDDEN_SYMBOLS

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32KeySize | is PRNG key size, including: PRNG_KEY_SIZE_64 PRNG_KEY_SIZE_128 PRNG_KEY_SIZE_192 PRNG_KEY_SIZE_256
  [in] | u32SeedReload | is PRNG seed reload or not, including: PRNG_SEED_CONT PRNG_SEED_RELOAD
  [in] | u32Seed | The new seed. Only valid when u32SeedReload is PRNG_SEED_RELOAD.

Returns
  None

Definition at line 71 of file crypto.c.

## ◆ PRNG_Read()

void PRNG_Read | ( | CRPT_T * | crpt,
|  | uint32_t | u32RandKey[]
| ) |  |

Read the PRNG key.

Parameters

  [in] | crpt | Reference to Crypto module.
  [out] | u32RandKey | The key buffer to store newly generated PRNG key.

Returns
  None

Definition at line 98 of file crypto.c.

## ◆ PRNG_Start()

void PRNG_Start | ( | CRPT_T * | crpt | ) |

Start to generate one PRNG key.

Parameters

  [in] | crpt | Reference to Crypto module.

Returns
  None

Definition at line 87 of file crypto.c.

## ◆ SHA_Open()

void SHA_Open | ( | CRPT_T * | crpt,
|  | uint32_t | u32OpMode,
|  | uint32_t | u32SwapType,
|  | uint32_t | hmac_key_len
| ) |  |

Open SHA encrypt function.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32OpMode | SHA operation mode, including: SHA_MODE_SHA1 SHA_MODE_SHA224 SHA_MODE_SHA256 SHA_MODE_SHA384 SHA_MODE_SHA512
  [in] | u32SwapType | is SHA input/output data swap control, including: SHA_NO_SWAP SHA_OUT_SWAP SHA_IN_SWAP SHA_IN_OUT_SWAP
  [in] | hmac_key_len | HMAC key byte count

Returns
  None

Definition at line 372 of file crypto.c.

## ◆ SHA_Read()

void SHA_Read | ( | CRPT_T * | crpt,
|  | uint32_t | u32Digest[]
| ) |  |

Read the SHA digest.

Parameters

  [in] | crpt | Reference to Crypto module.
  [out] | u32Digest | The SHA encrypt output digest.

Returns
  None

Definition at line 422 of file crypto.c.

## ◆ SHA_SetDMATransfer()

void SHA_SetDMATransfer | ( | CRPT_T * | crpt,
|  | uint32_t | u32SrcAddr,
|  | uint32_t | u32TransCnt
| ) |  |

Set SHA DMA transfer.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32SrcAddr | SHA DMA source address
  [in] | u32TransCnt | SHA DMA transfer byte count

Returns
  None

Definition at line 410 of file crypto.c.

## ◆ SHA_Start()

void SHA_Start | ( | CRPT_T * | crpt,
|  | uint32_t | u32DMAMode
| ) |  |

Start SHA encrypt.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32DMAMode | TDES DMA control, including: CRYPTO_DMA_ONE_SHOT One shop SHA encrypt. CRYPTO_DMA_CONTINUE Continuous SHA encrypt. CRYPTO_DMA_LAST Last SHA encrypt of a series of SHA_Start.

Returns
  None

Definition at line 397 of file crypto.c.

## ◆ TDES_Open()

void TDES_Open | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | u32EncDec,
|  | int32_t | Is3DES,
|  | int32_t | Is3Key,
|  | uint32_t | u32OpMode,
|  | uint32_t | u32SwapType
| ) |  |

Open TDES encrypt/decrypt function.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | TDES channel. Must be 0~3.
  [in] | u32EncDec | 1: TDES encode; 0: TDES decode
  [in] | Is3DES | 1: TDES; 0: DES
  [in] | Is3Key | 1: TDES 3 key mode; 0: TDES 2 key mode
  [in] | u32OpMode | TDES operation mode, including: TDES_MODE_ECB TDES_MODE_CBC TDES_MODE_CFB TDES_MODE_OFB TDES_MODE_CTR
  [in] | u32SwapType | is TDES input/output data swap control and word swap control, including: TDES_NO_SWAP TDES_WHL_SWAP TDES_OUT_SWAP TDES_OUT_WHL_SWAP TDES_IN_SWAP TDES_IN_WHL_SWAP TDES_IN_OUT_SWAP TDES_IN_OUT_WHL_SWAP

Returns
  None

Definition at line 258 of file crypto.c.

## ◆ TDES_SetDMATransfer()

void TDES_SetDMATransfer | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | u32SrcAddr,
|  | uint32_t | u32DstAddr,
|  | uint32_t | u32TransCnt
| ) |  |

Set TDES DMA transfer configuration.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | TDES channel. Must be 0~3.
  [in] | u32SrcAddr | TDES DMA source address
  [in] | u32DstAddr | TDES DMA destination address
  [in] | u32TransCnt | TDES DMA transfer byte count

Returns
  None

Definition at line 340 of file crypto.c.

## ◆ TDES_SetInitVect()

void TDES_SetInitVect | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | u32IVH,
|  | uint32_t | u32IVL
| ) |  |

Set TDES initial vectors.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | TDES channel. Must be 0~3.
  [in] | u32IVH | TDES initial vector high word.
  [in] | u32IVL | TDES initial vector low word.

Returns
  None

Definition at line 320 of file crypto.c.

## ◆ TDES_SetKey()

void TDES_SetKey | ( | CRPT_T * | crpt,
|  | uint32_t | u32Channel,
|  | uint32_t | au32Keys[3][2]
| ) |  |

Set TDES keys.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | TDES channel. Must be 0~3.
  [in] | au32Keys | The TDES keys. au32Keys[0][0] is Key0 high word and au32Keys[0][1] is key0 low word.

Returns
  None

Definition at line 297 of file crypto.c.

## ◆ TDES_Start()

void TDES_Start | ( | CRPT_T * | crpt,
|  | int32_t | u32Channel,
|  | uint32_t | u32DMAMode
| ) |  |

Start TDES encrypt/decrypt.

Parameters

  [in] | crpt | Reference to Crypto module.
  [in] | u32Channel | TDES channel. Must be 0~3.
  [in] | u32DMAMode | TDES DMA control, including: CRYPTO_DMA_ONE_SHOT One shop TDES encrypt/decrypt. CRYPTO_DMA_CONTINUE Continuous TDES encrypt/decrypt. CRYPTO_DMA_LAST Last TDES encrypt/decrypt of a series of TDES_Start.

Returns
  None

Definition at line 284 of file crypto.c.