1
0

crypto.h 1.5 KB

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