crypto.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef __crypto_h
  2. #define __crypto_h
  3. #ifndef CONFIG
  4. #define CONFIG "config.h"
  5. #endif // CONFIG
  6. #include CONFIG
  7. #include "types.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <errno.h>
  12. #include "endian.h"
  13. #include <stdint.h>
  14. #define AES_KEY_BYTES (16) // 128 Bits
  15. #define AES_BLOCK_BYTES (16)
  16. #define AES_BLOCK_WORDS (AES_BLOCK_BYTES / sizeof(DWORD))
  17. #define AES_KEY_DWORDS (AES_KEY_BYTES / sizeof(DWORD))
  18. #define V4_KEY_BYTES (20) // 160 Bits
  19. #define ROR32(v, n) ( (v) << (32 - n) | (v) >> n )
  20. void XorBlock(const BYTE *const in, const BYTE *out);
  21. void AesCmacV4(BYTE *data, size_t len, BYTE *hash);
  22. extern const BYTE AesKeyV5[];
  23. extern const BYTE AesKeyV6[];
  24. typedef struct {
  25. DWORD Key[48]; // Supports a maximum of 160 key bits!
  26. uint_fast8_t rounds;
  27. } AesCtx;
  28. void AesInitKey(AesCtx *Ctx, const BYTE *Key, int_fast8_t IsV6, int AesKeyBytes);
  29. void AesEncryptBlock(const AesCtx *const Ctx, BYTE *block);
  30. void AesDecryptBlock(const AesCtx *const Ctx, BYTE *block);
  31. void AesEncryptCbc(const AesCtx *const Ctx, BYTE *restrict iv, BYTE *restrict data, size_t *restrict len);
  32. void AesDecryptCbc(const AesCtx *const Ctx, BYTE *iv, BYTE *data, size_t len);
  33. void MixColumnsR(BYTE *restrict state);
  34. #if defined(_CRYPTO_OPENSSL)
  35. #include "crypto_openssl.h"
  36. #elif defined(_CRYPTO_POLARSSL)
  37. #include "crypto_polarssl.h"
  38. #elif defined(_CRYPTO_WINDOWS)
  39. #include "crypto_windows.h"
  40. #else
  41. #include "crypto_internal.h"
  42. #endif
  43. #endif // __crypto_h