68 #define AESBUSY_TIMEOUT ((uint32_t) 0x00010000) 107 uint8_t* Input, uint32_t Ilength, uint8_t* Output)
111 __IO uint32_t counter = 0;
112 uint32_t busystatus = 0;
114 uint32_t keyaddr = (uint32_t)Key;
115 uint32_t inputaddr = (uint32_t)Input;
116 uint32_t outputaddr = (uint32_t)Output;
126 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
128 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
130 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
132 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
136 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
138 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
140 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
142 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
144 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
146 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
150 AES_CRYP_KeyInitStructure.
CRYP_Key0Left = __REV(*(uint32_t*)(keyaddr));
152 AES_CRYP_KeyInitStructure.
CRYP_Key0Right= __REV(*(uint32_t*)(keyaddr));
154 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
156 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
158 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
160 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
162 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
164 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
195 if (busystatus !=
RESET)
232 for(i=0; ((i<Ilength) && (status !=
ERROR)); i+=16)
253 if (busystatus !=
RESET)
295 uint16_t Keysize, uint8_t *Input, uint32_t Ilength,
301 __IO uint32_t counter = 0;
302 uint32_t busystatus = 0;
304 uint32_t keyaddr = (uint32_t)Key;
305 uint32_t inputaddr = (uint32_t)Input;
306 uint32_t outputaddr = (uint32_t)Output;
307 uint32_t ivaddr = (uint32_t)InitVectors;
317 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
319 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
321 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
323 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
327 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
329 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
331 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
333 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
335 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
337 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
341 AES_CRYP_KeyInitStructure.
CRYP_Key0Left = __REV(*(uint32_t*)(keyaddr));
343 AES_CRYP_KeyInitStructure.
CRYP_Key0Right= __REV(*(uint32_t*)(keyaddr));
345 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
347 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
349 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
351 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
353 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
355 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
362 AES_CRYP_IVInitStructure.
CRYP_IV0Left = __REV(*(uint32_t*)(ivaddr));
364 AES_CRYP_IVInitStructure.
CRYP_IV0Right= __REV(*(uint32_t*)(ivaddr));
366 AES_CRYP_IVInitStructure.
CRYP_IV1Left = __REV(*(uint32_t*)(ivaddr));
368 AES_CRYP_IVInitStructure.
CRYP_IV1Right= __REV(*(uint32_t*)(ivaddr));
397 if (busystatus !=
RESET)
435 for(i=0; ((i<Ilength) && (status !=
ERROR)); i+=16)
455 if (busystatus !=
RESET)
497 uint16_t Keysize, uint8_t *Input, uint32_t Ilength,
503 __IO uint32_t counter = 0;
504 uint32_t busystatus = 0;
506 uint32_t keyaddr = (uint32_t)Key;
507 uint32_t inputaddr = (uint32_t)Input;
508 uint32_t outputaddr = (uint32_t)Output;
509 uint32_t ivaddr = (uint32_t)InitVectors;
519 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
521 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
523 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
525 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
529 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
531 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
533 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
535 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
537 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
539 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
543 AES_CRYP_KeyInitStructure.
CRYP_Key0Left = __REV(*(uint32_t*)(keyaddr));
545 AES_CRYP_KeyInitStructure.
CRYP_Key0Right= __REV(*(uint32_t*)(keyaddr));
547 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
549 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
551 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
553 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
555 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
557 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
563 AES_CRYP_IVInitStructure.
CRYP_IV0Left = __REV(*(uint32_t*)(ivaddr));
565 AES_CRYP_IVInitStructure.
CRYP_IV0Right= __REV(*(uint32_t*)(ivaddr));
567 AES_CRYP_IVInitStructure.
CRYP_IV1Left = __REV(*(uint32_t*)(ivaddr));
569 AES_CRYP_IVInitStructure.
CRYP_IV1Right= __REV(*(uint32_t*)(ivaddr));
606 for(i=0; ((i<Ilength) && (status !=
ERROR)); i+=16)
626 if (busystatus !=
RESET)
671 uint8_t *Key, uint16_t Keysize,
672 uint8_t *Input, uint32_t ILength,
673 uint8_t *
Header, uint32_t HLength,
674 uint8_t *Output, uint8_t *AuthTAG)
679 __IO uint32_t counter = 0;
680 uint32_t busystatus = 0;
682 uint32_t keyaddr = (uint32_t)Key;
683 uint32_t inputaddr = (uint32_t)Input;
684 uint32_t outputaddr = (uint32_t)Output;
685 uint32_t ivaddr = (uint32_t)InitVectors;
686 uint32_t headeraddr = (uint32_t)Header;
687 uint32_t tagaddr = (uint32_t)AuthTAG;
688 uint64_t headerlength = HLength * 8;
689 uint64_t inputlength = ILength * 8;
690 uint32_t loopcounter = 0;
699 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
701 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
703 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
705 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
709 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
711 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
713 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
715 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
717 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
719 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
723 AES_CRYP_KeyInitStructure.
CRYP_Key0Left = __REV(*(uint32_t*)(keyaddr));
725 AES_CRYP_KeyInitStructure.
CRYP_Key0Right= __REV(*(uint32_t*)(keyaddr));
727 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
729 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
731 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
733 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
735 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
737 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
744 AES_CRYP_IVInitStructure.
CRYP_IV0Left = __REV(*(uint32_t*)(ivaddr));
746 AES_CRYP_IVInitStructure.
CRYP_IV0Right= __REV(*(uint32_t*)(ivaddr));
748 AES_CRYP_IVInitStructure.
CRYP_IV1Left = __REV(*(uint32_t*)(ivaddr));
750 AES_CRYP_IVInitStructure.
CRYP_IV1Right= __REV(*(uint32_t*)(ivaddr));
798 for(loopcounter = 0; (loopcounter < HLength); loopcounter+=16)
824 if (busystatus !=
RESET)
846 for(loopcounter = 0; ((loopcounter < ILength) && (status !=
ERROR)); loopcounter+=16)
870 if (busystatus !=
RESET)
918 tagaddr = (uint32_t)AuthTAG;
973 for(loopcounter = 0; (loopcounter < HLength); loopcounter+=16)
997 if (busystatus !=
RESET)
1019 for(loopcounter = 0; ((loopcounter < ILength) && (status !=
ERROR)); loopcounter+=16)
1041 if (busystatus !=
RESET)
1085 tagaddr = (uint32_t)AuthTAG;
1126 uint8_t* Nonce, uint32_t NonceSize,
1127 uint8_t *Key, uint16_t Keysize,
1128 uint8_t *Input, uint32_t ILength,
1129 uint8_t *
Header, uint32_t HLength, uint8_t *HBuffer,
1131 uint8_t *AuthTAG, uint32_t TAGSize)
1136 __IO uint32_t counter = 0;
1137 uint32_t busystatus = 0;
1139 uint32_t keyaddr = (uint32_t)Key;
1140 uint32_t inputaddr = (uint32_t)Input;
1141 uint32_t outputaddr = (uint32_t)Output;
1142 uint32_t headeraddr = (uint32_t)Header;
1143 uint32_t tagaddr = (uint32_t)AuthTAG;
1144 uint32_t headersize = HLength;
1145 uint32_t loopcounter = 0;
1146 uint32_t bufferidx = 0;
1147 uint8_t blockb0[16] = {0};
1148 uint8_t ctr[16] = {0};
1149 uint32_t temptag[4] = {0};
1150 uint32_t ctraddr = (uint32_t)ctr;
1151 uint32_t b0addr = (uint32_t)blockb0;
1157 if(headersize < 65280)
1159 HBuffer[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
1160 HBuffer[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
1166 HBuffer[bufferidx++] = 0xFF;
1167 HBuffer[bufferidx++] = 0xFE;
1168 HBuffer[bufferidx++] = headersize & 0xff000000;
1169 HBuffer[bufferidx++] = headersize & 0x00ff0000;
1170 HBuffer[bufferidx++] = headersize & 0x0000ff00;
1171 HBuffer[bufferidx++] = headersize & 0x000000ff;
1175 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
1177 HBuffer[bufferidx++] = Header[loopcounter];
1180 if ((headersize % 16) != 0)
1183 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
1185 HBuffer[loopcounter] = 0;
1188 headersize = ((headersize/16) + 1) * 16;
1191 headeraddr = (uint32_t)HBuffer;
1199 blockb0[0] |= 0u | (((( (uint8_t) TAGSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - NonceSize) - 1) & 0x07);
1201 for (loopcounter = 0; loopcounter < NonceSize; loopcounter++)
1203 blockb0[loopcounter+1] = Nonce[loopcounter];
1205 for ( ; loopcounter < 13; loopcounter++)
1207 blockb0[loopcounter+1] = 0;
1210 blockb0[14] = ((ILength >> 8) & 0xFF);
1211 blockb0[15] = (ILength & 0xFF);
1220 ctr[0] = blockb0[0] & 0x07;
1222 for(loopcounter = 1; loopcounter < NonceSize + 1; loopcounter++)
1224 ctr[loopcounter] = blockb0[loopcounter];
1236 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
1238 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
1240 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
1242 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
1246 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
1248 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
1250 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
1252 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
1254 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
1256 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
1260 AES_CRYP_KeyInitStructure.
CRYP_Key0Left = __REV(*(uint32_t*)(keyaddr));
1262 AES_CRYP_KeyInitStructure.
CRYP_Key0Right= __REV(*(uint32_t*)(keyaddr));
1264 AES_CRYP_KeyInitStructure.
CRYP_Key1Left = __REV(*(uint32_t*)(keyaddr));
1266 AES_CRYP_KeyInitStructure.
CRYP_Key1Right= __REV(*(uint32_t*)(keyaddr));
1268 AES_CRYP_KeyInitStructure.
CRYP_Key2Left = __REV(*(uint32_t*)(keyaddr));
1270 AES_CRYP_KeyInitStructure.
CRYP_Key2Right= __REV(*(uint32_t*)(keyaddr));
1272 AES_CRYP_KeyInitStructure.
CRYP_Key3Left = __REV(*(uint32_t*)(keyaddr));
1274 AES_CRYP_KeyInitStructure.
CRYP_Key3Right= __REV(*(uint32_t*)(keyaddr));
1281 AES_CRYP_IVInitStructure.
CRYP_IV0Left = (__REV(*(uint32_t*)(ctraddr)));
1283 AES_CRYP_IVInitStructure.
CRYP_IV0Right= (__REV(*(uint32_t*)(ctraddr)));
1285 AES_CRYP_IVInitStructure.
CRYP_IV1Left = (__REV(*(uint32_t*)(ctraddr)));
1287 AES_CRYP_IVInitStructure.
CRYP_IV1Right= (__REV(*(uint32_t*)(ctraddr)));
1311 b0addr = (uint32_t)blockb0;
1343 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
1367 if (busystatus !=
RESET)
1389 for(loopcounter = 0; ((loopcounter < ILength) && (status !=
ERROR)); loopcounter+=16)
1411 if (busystatus !=
RESET)
1447 ctraddr = (uint32_t)ctr;
1489 b0addr = (uint32_t)blockb0;
1521 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
1545 if (busystatus !=
RESET)
1567 for(loopcounter = 0; ((loopcounter < ILength) && (status !=
ERROR)); loopcounter+=16)
1589 if (busystatus !=
RESET)
1625 ctraddr = (uint32_t)ctr;
1647 for(loopcounter = 0; (loopcounter < TAGSize); loopcounter++)
1650 *((uint8_t*)tagaddr+loopcounter) = *((uint8_t*)temptag+loopcounter);
#define CRYP_KeySize_128b
#define CRYP_AlgoDir_Decrypt
#define CRYP_AlgoMode_AES_CBC
void CRYP_Init(CRYP_InitTypeDef *CRYP_InitStruct)
Initializes the CRYP peripheral according to the specified parameters in the CRYP_InitStruct.
#define CRYP_Phase_Payload
ErrorStatus CRYP_AES_ECB(uint8_t Mode, uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using AES in ECB Mode.
#define CRYP_AlgoMode_AES_CCM
#define CRYP_DataType_32b
#define CRYP_AlgoMode_AES_CTR
void CRYP_FIFOFlush(void)
Flushes the IN and OUT FIFOs (that is read and write pointers of the FIFOs are reset) ...
static volatile uint8_t * status
void CRYP_PhaseConfig(uint32_t CRYP_Phase)
Configures the AES-CCM and AES-GCM phases.
uint32_t CRYP_DataOut(void)
Returns the last data entered into the output FIFO.
ErrorStatus CRYP_AES_CTR(uint8_t Mode, uint8_t InitVectors[16], uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using AES in CTR Mode.
ErrorStatus CRYP_AES_CCM(uint8_t Mode, uint8_t *Nonce, uint32_t NonceSize, uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t ILength, uint8_t *Header, uint32_t HLength, uint8_t *HBuffer, uint8_t *Output, uint8_t *AuthTAG, uint32_t TAGSize)
Encrypt and decrypt using AES in CCM Mode. The GCM and CCM modes are available only on STM32F437x Dev...
#define CRYP_AlgoDir_Encrypt
ErrorStatus CRYP_AES_GCM(uint8_t Mode, uint8_t InitVectors[16], uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t ILength, uint8_t *Header, uint32_t HLength, uint8_t *Output, uint8_t *AuthTAG)
Encrypt and decrypt using AES in GCM Mode. The GCM and CCM modes are available only on STM32F437x Dev...
FlagStatus CRYP_GetFlagStatus(uint8_t CRYP_FLAG)
Checks whether the specified CRYP flag is set or not.
void CRYP_DataIn(uint32_t Data)
Writes data in the Data Input register (DIN).
FunctionalState CRYP_GetCmdStatus(void)
Returns whether CRYP peripheral is enabled or disabled.
#define CRYP_KeySize_256b
ErrorStatus CRYP_AES_CBC(uint8_t Mode, uint8_t InitVectors[16], uint8_t *Key, uint16_t Keysize, uint8_t *Input, uint32_t Ilength, uint8_t *Output)
Encrypt and decrypt using AES in CBC Mode.
#define CRYP_Phase_Header
#define CRYP_AlgoMode_AES_GCM
CRYP Key(s) structure definition.
This file contains all the functions prototypes for the Cryptographic processor(CRYP) firmware librar...
void CRYP_Cmd(FunctionalState NewState)
Enables or disables the CRYP peripheral.
#define CRYP_AlgoMode_AES_ECB
void CRYP_KeyInit(CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
Initializes the CRYP Keys according to the specified parameters in the CRYP_KeyInitStruct.
#define CRYP_AlgoMode_AES_Key
CRYP Initialization Vectors (IV) structure definition.
void CRYP_KeyStructInit(CRYP_KeyInitTypeDef *CRYP_KeyInitStruct)
Fills each CRYP_KeyInitStruct member with its default value.
#define CRYP_KeySize_192b
void CRYP_IVInit(CRYP_IVInitTypeDef *CRYP_IVInitStruct)
Initializes the CRYP Initialization Vectors(IV) according to the specified parameters in the CRYP_IVI...
CRYP Init structure definition.