Go to the documentation of this file.
   32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL 
   35 #include "stm32f2xx.h" 
   36 #include "stm32f2xx_hal.h" 
   45 #if (STM32F2XX_CRYPTO_CIPHER_SUPPORT == ENABLED) 
   56    __HAL_RCC_CRYP_CLK_ENABLE();
 
   63 #if (DES_SUPPORT == ENABLED) 
   76    uint8_t *output, 
size_t length, uint32_t mode)
 
   89    CRYP->K1LR = context->
ks[0];
 
   90    CRYP->K1RR = context->
ks[1];
 
  101    CRYP->CR |= CRYP_CR_FFLUSH;
 
  103    CRYP->CR |= CRYP_CR_CRYPEN;
 
  109       while((CRYP->SR & CRYP_SR_IFNF) == 0)
 
  114       CRYP->DIN = __UNALIGNED_UINT32_READ(input);
 
  115       CRYP->DIN = __UNALIGNED_UINT32_READ(input + 4);
 
  118       while((CRYP->SR & CRYP_SR_OFNE) == 0)
 
  124       __UNALIGNED_UINT32_WRITE(output, temp);
 
  126       __UNALIGNED_UINT32_WRITE(output + 4, temp);
 
  163    if(context == NULL || key == NULL)
 
  209 #if (DES3_SUPPORT == ENABLED) 
  222    uint8_t *output, 
size_t length, uint32_t mode)
 
  235    CRYP->K1LR = context->
k1.
ks[0];
 
  236    CRYP->K1RR = context->
k1.
ks[1];
 
  237    CRYP->K2LR = context->
k2.
ks[0];
 
  238    CRYP->K2RR = context->
k2.
ks[1];
 
  239    CRYP->K3LR = context->
k3.
ks[0];
 
  240    CRYP->K3RR = context->
k3.
ks[1];
 
  251    CRYP->CR |= CRYP_CR_FFLUSH;
 
  253    CRYP->CR |= CRYP_CR_CRYPEN;
 
  259       while((CRYP->SR & CRYP_SR_IFNF) == 0)
 
  264       CRYP->DIN = __UNALIGNED_UINT32_READ(input);
 
  265       CRYP->DIN = __UNALIGNED_UINT32_READ(input + 4);
 
  268       while((CRYP->SR & CRYP_SR_OFNE) == 0)
 
  274       __UNALIGNED_UINT32_WRITE(output, temp);
 
  276       __UNALIGNED_UINT32_WRITE(output + 4, temp);
 
  313    if(context == NULL || key == NULL)
 
  328    else if(keyLen == 16)
 
  340    else if(keyLen == 24)
 
  392 #if (AES_SUPPORT == ENABLED) 
  404    temp = CRYP->CR & ~CRYP_CR_KEYSIZE;
 
  407    if(context->
nr == 10)
 
  413       CRYP->K2LR = context->
ek[0];
 
  414       CRYP->K2RR = context->
ek[1];
 
  415       CRYP->K3LR = context->
ek[2];
 
  416       CRYP->K3RR = context->
ek[3];
 
  418    else if(context->
nr == 12)
 
  424       CRYP->K1LR = context->
ek[0];
 
  425       CRYP->K1RR = context->
ek[1];
 
  426       CRYP->K2LR = context->
ek[2];
 
  427       CRYP->K2RR = context->
ek[3];
 
  428       CRYP->K3LR = context->
ek[4];
 
  429       CRYP->K3RR = context->
ek[5];
 
  437       CRYP->K0LR = context->
ek[0];
 
  438       CRYP->K0RR = context->
ek[1];
 
  439       CRYP->K1LR = context->
ek[2];
 
  440       CRYP->K1RR = context->
ek[3];
 
  441       CRYP->K2LR = context->
ek[4];
 
  442       CRYP->K2RR = context->
ek[5];
 
  443       CRYP->K3LR = context->
ek[6];
 
  444       CRYP->K3RR = context->
ek[7];
 
  460    uint8_t *output, 
size_t length, uint32_t mode)
 
  471    if((mode & CRYP_CR_ALGODIR) != 0)
 
  478       CRYP->CR |= CRYP_CR_CRYPEN;
 
  481       while((CRYP->SR & CRYP_SR_BUSY) != 0)
 
  486       temp = CRYP->CR & ~CRYP_CR_ALGOMODE;
 
  487       CRYP->CR = temp | mode;
 
  508    CRYP->CR |= CRYP_CR_FFLUSH;
 
  510    CRYP->CR |= CRYP_CR_CRYPEN;
 
  516       while((CRYP->SR & CRYP_SR_IFNF) == 0)
 
  521       CRYP->DIN = __UNALIGNED_UINT32_READ(input);
 
  522       CRYP->DIN = __UNALIGNED_UINT32_READ(input + 4);
 
  523       CRYP->DIN = __UNALIGNED_UINT32_READ(input + 8);
 
  524       CRYP->DIN = __UNALIGNED_UINT32_READ(input + 12);
 
  527       while((CRYP->SR & CRYP_SR_OFNE) == 0)
 
  533       __UNALIGNED_UINT32_WRITE(output, temp);
 
  535       __UNALIGNED_UINT32_WRITE(output + 4, temp);
 
  537       __UNALIGNED_UINT32_WRITE(output + 8, temp);
 
  539       __UNALIGNED_UINT32_WRITE(output + 12, temp);
 
  557       while((CRYP->SR & CRYP_SR_IFNF) == 0)
 
  562       CRYP->DIN = buffer[0];
 
  563       CRYP->DIN = buffer[1];
 
  564       CRYP->DIN = buffer[2];
 
  565       CRYP->DIN = buffer[3];
 
  568       while((CRYP->SR & CRYP_SR_OFNE) == 0)
 
  573       buffer[0] = CRYP->DOUT;
 
  574       buffer[1] = CRYP->DOUT;
 
  575       buffer[2] = CRYP->DOUT;
 
  576       buffer[3] = CRYP->DOUT;
 
  617    if(context == NULL || key == NULL)
 
  626    else if(keyLen == 24)
 
  631    else if(keyLen == 32)
 
  646    for(i = 0; i < keyLen; i++)
 
  686 #if (ECB_SUPPORT == ENABLED) 
  699    const uint8_t *
p, uint8_t *
c, 
size_t length)
 
  706 #if (DES_SUPPORT == ENABLED) 
  728 #if (DES3_SUPPORT == ENABLED) 
  750 #if (AES_SUPPORT == ENABLED) 
  809    const uint8_t *
c, uint8_t *
p, 
size_t length)
 
  816 #if (DES_SUPPORT == ENABLED) 
  839 #if (DES3_SUPPORT == ENABLED) 
  862 #if (AES_SUPPORT == ENABLED) 
  911 #if (CBC_SUPPORT == ENABLED) 
  925    uint8_t *
iv, 
const uint8_t *
p, uint8_t *
c, 
size_t length)
 
  932 #if (DES_SUPPORT == ENABLED) 
  954 #if (DES3_SUPPORT == ENABLED) 
  976 #if (AES_SUPPORT == ENABLED) 
 1008             c[i] = 
p[i] ^ 
iv[i];
 
 1048    uint8_t *
iv, 
const uint8_t *
c, uint8_t *
p, 
size_t length)
 
 1055 #if (DES_SUPPORT == ENABLED) 
 1078 #if (DES3_SUPPORT == ENABLED) 
 1101 #if (AES_SUPPORT == ENABLED) 
 1165 #if (CTR_SUPPORT == ENABLED && AES_SUPPORT == ENABLED) 
 1180    uint8_t *
t, 
const uint8_t *
p, uint8_t *
c, 
size_t length)
 
 1239             for(i = 0; i < 
n; i++)
 
  
void des3ProcessData(Des3Context *context, uint8_t *iv, const uint8_t *input, uint8_t *output, size_t length, uint32_t mode)
Perform Triple DES encryption or decryption.
void desDecryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using DES algorithm.
error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
CipherAlgoDecryptBlock decryptBlock
STM32F2 hardware cryptographic accelerator.
void aesDecryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using AES algorithm.
Collection of AEAD algorithms.
#define CRYP_CR_ALGOMODE_DES_ECB
void aesProcessData(AesContext *context, uint8_t *iv, const uint8_t *input, uint8_t *output, size_t length, uint32_t mode)
Perform AES encryption or decryption.
#define CRYP_CR_KEYSIZE_128B
#define CRYP_CR_DATATYPE_8B
error_t ctrEncrypt(const CipherAlgo *cipher, void *context, uint_t m, uint8_t *t, const uint8_t *p, uint8_t *c, size_t length)
CTR encryption.
#define CRYP_CR_ALGOMODE_AES_ECB
error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using AES algorithm.
CipherAlgoEncryptBlock encryptBlock
error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen)
Initialize a DES context using the supplied key.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
void desProcessData(DesContext *context, uint8_t *iv, const uint8_t *input, uint8_t *output, size_t length, uint32_t mode)
Perform DES encryption or decryption.
#define osMemcpy(dest, src, length)
OsMutex stm32f2xxCryptoMutex
STM32F2 cipher hardware accelerator.
#define CRYP_CR_ALGOMODE_AES_CBC
void des3DecryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using Triple DES algorithm.
@ ERROR_INVALID_KEY_LENGTH
General definitions for cryptographic algorithms.
#define CRYP_CR_ALGOMODE_TDES_ECB
Block cipher modes of operation.
#define CRYP_CR_ALGOMODE_AES_CTR
void desEncryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using DES algorithm.
Triple DES algorithm context.
#define CRYP_CR_ALGOMODE_DES_CBC
#define CRYP_CR_KEYSIZE_256B
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Common interface for encryption algorithms.
error_t ecbDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *c, uint8_t *p, size_t length)
ECB decryption.
#define CRYP_CR_ALGOMODE_TDES_CBC
error_t ecbEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *p, uint8_t *c, size_t length)
ECB encryption.
void aesLoadKey(AesContext *context)
Load AES key.
#define osMemset(p, value, length)
error_t des3Init(Des3Context *context, const uint8_t *key, size_t keyLen)
Initialize a Triple DES context using the supplied key.
#define CRYP_CR_ALGOMODE_AES_KEY
void ctrIncBlock(uint8_t *ctr, uint32_t inc, size_t blockSize, size_t m)
Increment counter block.
error_t crypInit(void)
CRYP module initialization.
#define CRYP_CR_KEYSIZE_192B
void des3EncryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using Triple DES algorithm.