crypto_openssl.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef __crypto_openssl_h
  2. #define __crypto_openssl_h
  3. #ifndef CONFIG
  4. #define CONFIG "config.h"
  5. #endif // CONFIG
  6. #include CONFIG
  7. #include <openssl/opensslv.h>
  8. #include <openssl/sha.h>
  9. #include <openssl/hmac.h>
  10. #include <openssl/aes.h>
  11. #include "crypto.h"
  12. #define Sha256(d, l, h) SHA256(d, l, h)
  13. int_fast8_t Sha256Hmac(BYTE* key, BYTE* restrict data, DWORD len, BYTE* restrict hmac);
  14. #ifndef _OPENSSL_NO_HMAC
  15. #define Sha256HmacCtx HMAC_CTX
  16. #else
  17. typedef struct {
  18. SHA256_CTX ShaCtx;
  19. BYTE OPad[64];
  20. } Sha256HmacCtx;
  21. #endif
  22. #ifndef _OPENSSL_NO_HMAC
  23. #define Sha256HmacInit(c, k, l) Sha256HmacInit_OpenSSL(c, k, l)
  24. #define Sha256HmacFinish(c, h) Sha256HmacFinish_OpenSSL(c, h, NULL)
  25. #if OPENSSL_VERSION_NUMBER >= 0x10000000L
  26. #define Sha256HmacUpdate(c, d, l) HMAC_Update(c, d, l)
  27. #else // OPENSSL_VERSION_NUMBER < 0x10000000L
  28. #define Sha256HmacUpdate(c, d, l) (HMAC_Update(c, d, l), !0)
  29. #endif // OPENSSL_VERSION_NUMBER >= 0x10000000L
  30. int Sha256HmacInit_OpenSSL(HMAC_CTX *c, const void *k, int l);
  31. int Sha256HmacFinish_OpenSSL(HMAC_CTX *c, unsigned char *h, unsigned int *l);
  32. #else // _OPENSSL_NO_HMAC
  33. int _Sha256HmacInit(Sha256HmacCtx *Ctx, BYTE *key, size_t klen);
  34. int _Sha256HmacUpdate(Sha256HmacCtx *Ctx, BYTE *data, size_t len);
  35. int _Sha256HmacFinish(Sha256HmacCtx *Ctx, BYTE *hmac, void* dummy);
  36. #define Sha256HmacInit(c, k, l) _Sha256HmacInit(c, k, l)
  37. #define Sha256HmacFinish(c, h) _Sha256HmacFinish(c, h, NULL)
  38. #define Sha256HmacUpdate(c, d, l) _Sha256HmacUpdate(c, d, l)
  39. #endif // _OPENSSL_NO_HMAC
  40. extern const BYTE AesKeyV4[];
  41. #endif // __crypto_openssl_h