afd7ea6a67e039e37b94b1b9d357eb0607602c72
[exim.git] / src / src / pdkim / hash.h
1 /*
2  *  PDKIM - a RFC4871 (DKIM) implementation
3  *
4  *  Copyright (C) 2016  Exim maintainers
5  *
6  *  Hash interface functions
7  */
8
9 #include "../exim.h"
10
11 #if !defined(DISABLE_DKIM) && !defined(PDKIM_HASH_H)    /* entire file */
12 #define PDKIM_HASH_H
13
14 #ifndef SUPPORT_TLS
15 # error Need SUPPORT_TLS for DKIM
16 #endif
17
18 #include "crypt_ver.h"
19 #include "blob.h"
20
21 #ifdef RSA_OPENSSL
22 # include <openssl/rsa.h>
23 # include <openssl/ssl.h>
24 # include <openssl/err.h>
25 #elif defined(RSA_GNUTLS)
26 # include <gnutls/gnutls.h>
27 # include <gnutls/x509.h>
28 #endif
29
30 #ifdef SHA_GNUTLS
31 # include <gnutls/crypto.h>
32 #elif defined(SHA_GCRYPT)
33 # include <gcrypt.h>
34 #elif defined(SHA_POLARSSL)
35 # include "pdkim.h"
36 # include "polarssl/sha1.h"
37 # include "polarssl/sha2.h"
38 #endif
39
40 /* Hash context */
41 typedef struct {
42   int sha1;
43   int hashlen;
44
45 #ifdef SHA_OPENSSL
46   union {
47     SHA_CTX      sha1;       /* SHA1 block                                */
48     SHA256_CTX   sha2;       /* SHA256 block                              */
49   } u;
50
51 #elif defined(SHA_GNUTLS)
52   gnutls_hash_hd_t sha;      /* Either SHA1 or SHA256 block               */
53
54 #elif defined(SHA_GCRYPT)
55   gcry_md_hd_t sha;          /* Either SHA1 or SHA256 block               */
56
57 #elif defined(SHA_POLARSSL)
58   union {
59     sha1_context sha1;       /* SHA1 block                                */
60     sha2_context sha2;       /* SHA256 block                              */
61   } u;
62 #endif
63
64 } hctx;
65
66 #if defined(SHA_OPENSSL)
67 # include "pdkim.h"
68 #elif defined(SHA_GCRYPT)
69 # include "pdkim.h"
70 #endif
71
72
73 extern void     exim_sha_init(hctx *, BOOL);
74 extern void     exim_sha_update(hctx *, const char *a, int);
75 extern void     exim_sha_finish(hctx *, blob *);
76 extern int      exim_sha_hashlen(hctx *);
77
78 #endif  /*DISABLE_DKIM*/
79 /* End of File */