96a0720fd46d2cdf4c17f27216d8d7343581643a
[exim.git] / src / src / pdkim / signing.h
1 /*
2 * PDKIM - a RFC4871 (DKIM) implementation
3 *
4 * Copyright (C) 1995 - 2018 Exim maintainers
5 *
6 * RSA signing/verification interface
7 */
8
9 #include "../exim.h"
10
11 #ifndef DISABLE_DKIM /* entire file */
12
13 #include "crypt_ver.h"
14
15 #ifdef SIGN_OPENSSL
16 # include <openssl/rsa.h>
17 # include <openssl/ssl.h>
18 # include <openssl/err.h>
19 #elif defined(SIGN_GNUTLS)
20 # include <gnutls/gnutls.h>
21 # include <gnutls/x509.h>
22 # include <gnutls/abstract.h>
23 #elif defined(SIGN_GCRYPT)
24 # include <gcrypt.h>
25 # include <libtasn1.h>
26 #endif
27
28 #include "../blob.h"
29
30 typedef enum {
31 KEYTYPE_RSA,
32 KEYTYPE_ED25519
33 } keytype;
34
35 typedef enum {
36 KEYFMT_DER, /* an asn.1 structure */
37 KEYFMT_ED25519_BARE /* just the key */
38 } keyformat;
39
40
41 #ifdef SIGN_OPENSSL
42
43 typedef struct {
44 keytype keytype;
45 EVP_PKEY * key;
46 } es_ctx;
47
48 typedef struct {
49 keytype keytype;
50 EVP_PKEY * key;
51 } ev_ctx;
52
53 #elif defined(SIGN_GNUTLS)
54
55 typedef struct {
56 keytype keytype;
57 gnutls_privkey_t key;
58 } es_ctx;
59
60 typedef struct {
61 keytype keytype;
62 gnutls_pubkey_t key;
63 } ev_ctx;
64
65 #elif defined(SIGN_GCRYPT)
66
67 typedef struct {
68 keytype keytype;
69 gcry_mpi_t n;
70 gcry_mpi_t e;
71 gcry_mpi_t d;
72 gcry_mpi_t p;
73 gcry_mpi_t q;
74 gcry_mpi_t dp;
75 gcry_mpi_t dq;
76 gcry_mpi_t qp;
77 } es_ctx;
78
79 typedef struct {
80 keytype keytype;
81 gcry_mpi_t n;
82 gcry_mpi_t e;
83 } ev_ctx;
84
85 #endif
86
87
88 extern void exim_dkim_init(void);
89 extern gstring * exim_dkim_data_append(gstring *, uschar *);
90
91 extern const uschar * exim_dkim_signing_init(const uschar *, es_ctx *);
92 extern const uschar * exim_dkim_sign(es_ctx *, hashmethod, blob *, blob *);
93 extern const uschar * exim_dkim_verify_init(blob *, keyformat, ev_ctx *);
94 extern const uschar * exim_dkim_verify(ev_ctx *, hashmethod, blob *, blob *);
95
96 #endif /*DISABLE_DKIM*/
97 /* End of File */