aes.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Created by #Suyghur, on 2021/06/11.
  3. //
  4. #ifndef EYUANGAMESDK_KTX_AES_H
  5. #define EYUANGAMESDK_KTX_AES_H
  6. // #define the macros below to 1/0 to enable/disable the mode of operation.
  7. //
  8. // CBC enables AES encryption in CBC-mode of operation.
  9. // CTR enables encryption in counter-mode.
  10. // ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously.
  11. // The #ifndef-guard allows it to be configured before #include'ing or at compile time.
  12. #ifndef CBC
  13. #define CBC 1
  14. #endif
  15. #ifndef ECB
  16. #define ECB 1
  17. #endif
  18. #ifndef CTR
  19. #define CTR 1
  20. #endif
  21. #define AES128 1
  22. //#define AES192 1
  23. //#define AES256 1
  24. #if defined(ECB) && (ECB == 1)
  25. void AES_ECB_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *output, const uint32_t length);
  26. void AES_ECB_decrypt(const uint8_t *input, const uint8_t *key, uint8_t *output, const uint32_t length);
  27. #endif // #if defined(ECB) && (ECB == !)
  28. #if defined(CBC) && (CBC == 1)
  29. void AES_CBC_encrypt_buffer(uint8_t *output, uint8_t *input, uint32_t length, const uint8_t *key, const uint8_t *iv);
  30. void AES_CBC_decrypt_buffer(uint8_t *output, uint8_t *input, uint32_t length, const uint8_t *key, const uint8_t *iv);
  31. #endif // #if defined(CBC) && (CBC == 1)
  32. #if defined(CTR) && (CTR == 1)
  33. /* Same function for encrypting as for decrypting. Note no IV/nonce should ever be reused with the same key */
  34. void AES_CTR_xcrypt_buffer(uint8_t *output, uint8_t *input, uint32_t length, const uint8_t *key, const uint8_t *nonce);
  35. #endif // #if defined(CTR) && (CTR == 1)
  36. #endif //EYUANGAMESDK_KTX_AES_H