Merge from master into 4.next
[exim.git] / src / src / hash.h
similarity index 55%
rename from src/src/pdkim/hash.h
rename to src/src/hash.h
index afd7ea6a67e039e37b94b1b9d357eb0607602c72..9e91f1aad776ad28b80448a0c1a294bf6f6c8c92 100644 (file)
@@ -1,46 +1,47 @@
 /*
- *  PDKIM - a RFC4871 (DKIM) implementation
+ *  Exim - an Internet mail transport agent
  *
  *  Copyright (C) 2016  Exim maintainers
  *
  *  Hash interface functions
  */
 
-#include "../exim.h"
+#include "exim.h"
 
-#if !defined(DISABLE_DKIM) && !defined(PDKIM_HASH_H)   /* entire file */
-#define PDKIM_HASH_H
+#if !defined(HASH_H)   /* entire file */
+#define HASH_H
 
-#ifndef SUPPORT_TLS
-# error Need SUPPORT_TLS for DKIM
-#endif
-
-#include "crypt_ver.h"
+#include "sha_ver.h"
 #include "blob.h"
 
-#ifdef RSA_OPENSSL
-# include <openssl/rsa.h>
-# include <openssl/ssl.h>
-# include <openssl/err.h>
-#elif defined(RSA_GNUTLS)
-# include <gnutls/gnutls.h>
-# include <gnutls/x509.h>
-#endif
-
-#ifdef SHA_GNUTLS
+#ifdef SHA_OPENSSL
+# include <openssl/sha.h>
+#elif defined SHA_GNUTLS
 # include <gnutls/crypto.h>
 #elif defined(SHA_GCRYPT)
 # include <gcrypt.h>
 #elif defined(SHA_POLARSSL)
-# include "pdkim.h"
-# include "polarssl/sha1.h"
-# include "polarssl/sha2.h"
+# include "pdkim/pdkim.h"              /*XXX ugly */
+# include "pdkim/polarssl/sha1.h"
+# include "pdkim/polarssl/sha2.h"
 #endif
 
-/* Hash context */
+
+/* Hash context for the exim_sha_* routines */
+
+typedef enum hashmethod {
+  HASH_BADTYPE,
+  HASH_SHA1,
+  HASH_SHA256,
+  HASH_SHA3_224,
+  HASH_SHA3_256,
+  HASH_SHA3_384,
+  HASH_SHA3_512,
+} hashmethod;
+
 typedef struct {
-  int sha1;
-  int hashlen;
+  hashmethod   method;
+  int          hashlen;
 
 #ifdef SHA_OPENSSL
   union {
@@ -59,21 +60,17 @@ typedef struct {
     sha1_context sha1;       /* SHA1 block                                */
     sha2_context sha2;       /* SHA256 block                              */
   } u;
-#endif
-
-} hctx;
 
-#if defined(SHA_OPENSSL)
-# include "pdkim.h"
-#elif defined(SHA_GCRYPT)
-# include "pdkim.h"
+#elif defined(SHA_NATIVE)
+  sha1 sha1;
 #endif
 
+} hctx;
 
-extern void     exim_sha_init(hctx *, BOOL);
-extern void     exim_sha_update(hctx *, const char *a, int);
+extern void     exim_sha_init(hctx *, hashmethod);
+extern void     exim_sha_update(hctx *, const uschar *a, int);
 extern void     exim_sha_finish(hctx *, blob *);
 extern int      exim_sha_hashlen(hctx *);
 
-#endif /*DISABLE_DKIM*/
+#endif
 /* End of File */