Copyright updates:
[exim.git] / src / src / hash.h
1 /*
2  *  Exim - an Internet mail transport agent
3  *  Copyright (c) The Exim Maintainers 1995 - 2022
4  *
5  *  Hash interface functions
6  */
7
8 #include "exim.h"
9
10 #if !defined(HASH_H)    /* entire file */
11 #define HASH_H
12
13 #include "sha_ver.h"
14
15 #ifdef SHA_OPENSSL
16 # include <openssl/sha.h>
17 #elif defined SHA_GNUTLS
18 # include <gnutls/crypto.h>
19 #elif defined(SHA_GCRYPT)
20 # include <gcrypt.h>
21 #elif defined(SHA_POLARSSL)
22 # include "pdkim/pdkim.h"               /*XXX ugly */
23 # include "pdkim/polarssl/sha1.h"
24 # include "pdkim/polarssl/sha2.h"
25 #endif
26
27
28 /* Hash context for the exim_sha_* routines */
29
30 typedef enum hashmethod {
31   HASH_BADTYPE,
32   HASH_NULL,
33   HASH_SHA1,
34
35   HASH_SHA2_256,
36   HASH_SHA2_384,
37   HASH_SHA2_512,
38
39   HASH_SHA3_224,
40   HASH_SHA3_256,
41   HASH_SHA3_384,
42   HASH_SHA3_512,
43 } hashmethod;
44
45 typedef struct {
46   hashmethod    method;
47   int           hashlen;
48
49 #ifdef SHA_OPENSSL
50   union {
51     SHA_CTX      sha1;       /* SHA1 block                                */
52     SHA256_CTX   sha2_256;   /* SHA256 or 224 block                       */
53     SHA512_CTX   sha2_512;   /* SHA512 or 384 block                       */
54 #ifdef EXIM_HAVE_SHA3
55     EVP_MD_CTX * mctx;       /* SHA3 block                                */
56 #endif
57   } u;
58
59 #elif defined(SHA_GNUTLS)
60   gnutls_hash_hd_t sha;      /* Either SHA1 or SHA256 block               */
61
62 #elif defined(SHA_GCRYPT)
63   gcry_md_hd_t sha;          /* Either SHA1 or SHA256 block               */
64
65 #elif defined(SHA_POLARSSL)
66   union {
67     sha1_context sha1;       /* SHA1 block                                */
68     sha2_context sha2;       /* SHA256 block                              */
69   } u;
70
71 #elif defined(SHA_NATIVE)
72   sha1 sha1;
73 #endif
74
75 } hctx;
76
77 extern BOOL     exim_sha_init(hctx *, hashmethod);
78 extern void     exim_sha_update(hctx *, const uschar *a, int);
79 extern void     exim_sha_update_string(hctx *, const uschar *a);
80 extern void     exim_sha_finish(hctx *, blob *);
81
82 #endif
83 /* End of File */