Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
36 #include "gd32f20x_cau.h"
45 #if (GD32F2XX_CRYPTO_CIPHER_SUPPORT == ENABLED)
56 rcu_periph_clock_enable(RCU_CAU);
63 #if (DES_SUPPORT == ENABLED)
76 if(context == NULL || key == NULL)
100 cau_text_struct text;
103 text.input = (uint8_t *) input;
104 text.output = output;
110 cau_des_ecb(CAU_ENCRYPT, (uint8_t *) context->
ks, &text);
125 cau_text_struct text;
128 text.input = (uint8_t *) input;
129 text.output = output;
135 cau_des_ecb(CAU_DECRYPT, (uint8_t *) context->
ks, &text);
141 #if (DES3_SUPPORT == ENABLED)
154 if(context == NULL || key == NULL)
158 if(keyLen != 8 && keyLen != 16 && keyLen != 24)
178 cau_text_struct text;
181 text.input = (uint8_t *) input;
182 text.output = output;
188 cau_tdes_ecb(CAU_ENCRYPT, (uint8_t *) context->
k1.
ks, &text);
203 cau_text_struct text;
206 text.input = (uint8_t *) input;
207 text.output = output;
213 cau_tdes_ecb(CAU_DECRYPT, (uint8_t *) context->
k1.
ks, &text);
219 #if (AES_SUPPORT == ENABLED)
232 if(context == NULL || key == NULL)
236 if(keyLen != 16 && keyLen != 24 && keyLen != 32)
243 context->
nr = keyLen * 8;
259 cau_text_struct text;
262 text.input = (uint8_t *) input;
263 text.output = output;
269 cau_aes_ecb(CAU_ENCRYPT, (uint8_t *) context->
ek, context->
nr, &text);
284 cau_text_struct text;
287 text.input = (uint8_t *) input;
288 text.output = output;
294 cau_aes_ecb(CAU_DECRYPT, (uint8_t *) context->
ek, context->
nr, &text);
300 #if (ECB_SUPPORT == ENABLED)
313 const uint8_t *
p, uint8_t *
c,
size_t length)
316 cau_text_struct text;
322 text.input = (uint8_t *)
p;
326 #if (DES_SUPPORT == ENABLED)
345 status = cau_des_ecb(CAU_ENCRYPT, (uint8_t *) desContext->
ks, &text);
357 #if (DES3_SUPPORT == ENABLED)
376 status = cau_tdes_ecb(CAU_ENCRYPT, (uint8_t *) des3Context->
k1.
ks, &text);
388 #if (AES_SUPPORT == ENABLED)
407 status = cau_aes_ecb(CAU_ENCRYPT, (uint8_t *) aesContext->
ek,
408 aesContext->
nr, &text);
457 const uint8_t *
c, uint8_t *
p,
size_t length)
460 cau_text_struct text;
466 text.input = (uint8_t *)
c;
470 #if (DES_SUPPORT == ENABLED)
489 status = cau_des_ecb(CAU_DECRYPT, (uint8_t *) desContext->
ks, &text);
501 #if (DES3_SUPPORT == ENABLED)
520 status = cau_tdes_ecb(CAU_DECRYPT, (uint8_t *) des3Context->
k1.
ks, &text);
532 #if (AES_SUPPORT == ENABLED)
551 status = cau_aes_ecb(CAU_DECRYPT, (uint8_t *) aesContext->
ek,
552 aesContext->
nr, &text);
590 #if (CBC_SUPPORT == ENABLED)
604 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
607 cau_text_struct text;
613 text.input = (uint8_t *)
p;
617 #if (DES_SUPPORT == ENABLED)
636 status = cau_des_cbc(CAU_ENCRYPT, (uint8_t *) desContext->
ks,
iv, &text);
648 #if (DES3_SUPPORT == ENABLED)
667 status = cau_tdes_cbc(CAU_ENCRYPT, (uint8_t *) des3Context->
k1.
ks,
iv, &text);
679 #if (AES_SUPPORT == ENABLED)
698 status = cau_aes_cbc(CAU_ENCRYPT, (uint8_t *) aesContext->
ek,
699 aesContext->
nr,
iv, &text);
761 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
764 cau_text_struct text;
770 text.input = (uint8_t *)
c;
774 #if (DES_SUPPORT == ENABLED)
793 status = cau_des_cbc(CAU_DECRYPT, (uint8_t *) desContext->
ks,
iv, &text);
805 #if (DES3_SUPPORT == ENABLED)
824 status = cau_tdes_cbc(CAU_DECRYPT, (uint8_t *) des3Context->
k1.
ks,
iv, &text);
836 #if (AES_SUPPORT == ENABLED)
855 status = cau_aes_cbc(CAU_DECRYPT, (uint8_t *) aesContext->
ek,
856 aesContext->
nr,
iv, &text);
909 #if (CTR_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
924 uint8_t *
t,
const uint8_t *
p, uint8_t *
c,
size_t length)
927 cau_text_struct text;
953 while(
length > 0 && status == SUCCESS)
961 text.input = (uint8_t *)
p;
966 status = cau_aes_ctr(CAU_ENCRYPT, (uint8_t *) aesContext->
ek,
967 aesContext->
nr,
t, &text);
997 for(i = 0; i <
n; i++)
CipherAlgoDecryptBlock decryptBlock
error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen)
Initialize a DES context using the supplied key.
Collection of AEAD algorithms.
void aesDecryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using AES algorithm.
CipherAlgoEncryptBlock encryptBlock
void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using AES algorithm.
error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
error_t des3Init(Des3Context *context, const uint8_t *key, size_t keyLen)
Initialize a Triple DES context using the supplied key.
error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
@ ERROR_FAILURE
Generic error code.
void desDecryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using DES algorithm.
@ ERROR_INVALID_KEY_LENGTH
General definitions for cryptographic algorithms.
error_t ecbDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *c, uint8_t *p, size_t length)
ECB decryption.
Block cipher modes of operation.
error_t cauInit(void)
CAU module initialization.
error_t ecbEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *p, uint8_t *c, size_t length)
ECB encryption.
Triple DES algorithm context.
OsMutex gd32f2xxCryptoMutex
void des3DecryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using Triple DES algorithm.
GD32F2 cipher hardware accelerator.
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.
void desEncryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using DES algorithm.
GD32F2 hardware cryptographic accelerator.
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.
void ctrIncBlock(uint8_t *ctr, uint32_t inc, size_t blockSize, size_t m)
Increment counter block.
void des3EncryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using Triple DES algorithm.
error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
Key expansion.