Setup for >2 sha methods
[exim.git] / src / src / hash.h
1 /*
2  *  Exim - an Internet mail transport agent
3  *
4  *  Copyright (C) 2016  Exim maintainers
5  *
6  *  Hash interface functions
7  */
8
9 #include "exim.h"
10
11 #if !defined(HASH_H)    /* entire file */
12 #define HASH_H
13
14 #include "sha_ver.h"
15 #include "blob.h"
16
17 #ifdef SHA_OPENSSL
18 # include <openssl/sha.h>
19 #elif defined SHA_GNUTLS
20 # include <gnutls/crypto.h>
21 #elif defined(SHA_GCRYPT)
22 # include <gcrypt.h>
23 #elif defined(SHA_POLARSSL)
24 # include "pdkim/pdkim.h"               /*XXX ugly */
25 # include "pdkim/polarssl/sha1.h"
26 # include "pdkim/polarssl/sha2.h"
27 #endif
28
29
30 /* Hash context for the exim_sha_* routines */
31
32 typedef enum hashmethod {
33   HASH_SHA1,
34   HASH_SHA256,
35   HASH_SHA3
36 } hashmethod;
37
38 typedef struct {
39   hashmethod    method;
40   int           hashlen;
41
42 #ifdef SHA_OPENSSL
43   union {
44     SHA_CTX      sha1;       /* SHA1 block                                */
45     SHA256_CTX   sha2;       /* SHA256 block                              */
46   } u;
47
48 #elif defined(SHA_GNUTLS)
49   gnutls_hash_hd_t sha;      /* Either SHA1 or SHA256 block               */
50
51 #elif defined(SHA_GCRYPT)
52   gcry_md_hd_t sha;          /* Either SHA1 or SHA256 block               */
53
54 #elif defined(SHA_POLARSSL)
55   union {
56     sha1_context sha1;       /* SHA1 block                                */
57     sha2_context sha2;       /* SHA256 block                              */
58   } u;
59
60 #elif defined(SHA_NATIVE)
61   sha1 sha1;
62 #endif
63
64 } hctx;
65
66 extern void     exim_sha_init(hctx *, hashmethod);
67 extern void     exim_sha_update(hctx *, const uschar *a, int);
68 extern void     exim_sha_finish(hctx *, blob *);
69 extern int      exim_sha_hashlen(hctx *);
70
71 #endif
72 /* End of File */