2 * Exim - an Internet mail transport agent
4 * Copyright (C) 2016 Exim maintainers
6 * Hash interface functions
12 # error Need SUPPORT_TLS for DKIM
21 # include <openssl/rsa.h>
22 # include <openssl/ssl.h>
23 # include <openssl/err.h>
24 #elif defined(RSA_GNUTLS)
25 # include <gnutls/gnutls.h>
26 # include <gnutls/x509.h>
27 # ifdef RSA_VERIFY_GNUTLS
28 # include <gnutls/abstract.h>
34 /******************************************************************************/
38 exim_sha_init(hctx * h, BOOL sha1)
41 h->hashlen = sha1 ? 20 : 32;
43 SHA1_Init (&h->u.sha1);
45 SHA256_Init(&h->u.sha2);
50 exim_sha_update(hctx * h, const uschar * data, int len)
53 SHA1_Update (&h->u.sha1, data, len);
55 SHA256_Update(&h->u.sha2, data, len);
60 exim_sha_finish(hctx * h, blob * b)
62 b->data = store_get(b->len = h->hashlen);
65 SHA1_Final (b->data, &h->u.sha1);
67 SHA256_Final(b->data, &h->u.sha2);
72 #elif defined(SHA_GNUTLS)
73 /******************************************************************************/
76 exim_sha_init(hctx * h, BOOL sha1)
79 h->hashlen = sha1 ? 20 : 32;
80 gnutls_hash_init(&h->sha, sha1 ? GNUTLS_DIG_SHA1 : GNUTLS_DIG_SHA256);
85 exim_sha_update(hctx * h, const uschar * data, int len)
87 gnutls_hash(h->sha, data, len);
92 exim_sha_finish(hctx * h, blob * b)
94 b->data = store_get(b->len = h->hashlen);
95 gnutls_hash_output(h->sha, b->data);
100 #elif defined(SHA_GCRYPT)
101 /******************************************************************************/
104 exim_sha_init(hctx * h, BOOL sha1)
107 h->hashlen = sha1 ? 20 : 32;
108 gcry_md_open(&h->sha, sha1 ? GCRY_MD_SHA1 : GCRY_MD_SHA256, 0);
113 exim_sha_update(hctx * h, const uschar * data, int len)
115 gcry_md_write(h->sha, data, len);
120 exim_sha_finish(hctx * h, blob * b)
122 b->data = store_get(b->len = h->hashlen);
123 memcpy(b->data, gcry_md_read(h->sha, 0), h->hashlen);
129 #elif defined(SHA_POLARSSL)
130 /******************************************************************************/
133 exim_sha_init(hctx * h, BOOL sha1)
136 h->hashlen = sha1 ? 20 : 32;
138 sha1_starts(&h->u.sha1);
140 sha2_starts(&h->u.sha2, 0);
145 exim_sha_update(hctx * h, const uschar * data, int len)
148 sha1_update(h->u.sha1, US data, len);
150 sha2_update(h->u.sha2, US data, len);
155 exim_sha_finish(hctx * h, blob * b)
157 b->data = store_get(b->len = h->hashlen);
160 sha1_finish(h->u.sha1, b->data);
162 sha2_finish(h->u.sha2, b->data);
166 /******************************************************************************/
168 /* Common to all library versions */
170 exim_sha_hashlen(hctx * h)
172 return h->sha1 ? 20 : 32;