| 1 | /* |
| 2 | * PDKIM - a RFC4871 (DKIM) implementation |
| 3 | * |
| 4 | * Copyright (C) 2016 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 | |
| 31 | #ifdef SIGN_OPENSSL |
| 32 | |
| 33 | typedef struct { |
| 34 | EVP_PKEY * key; |
| 35 | } es_ctx; |
| 36 | |
| 37 | typedef struct { |
| 38 | EVP_PKEY * key; |
| 39 | } ev_ctx; |
| 40 | |
| 41 | #elif defined(SIGN_GNUTLS) |
| 42 | |
| 43 | typedef struct { |
| 44 | gnutls_x509_privkey_t key; |
| 45 | } es_ctx; |
| 46 | |
| 47 | typedef struct { |
| 48 | gnutls_pubkey_t key; |
| 49 | } ev_ctx; |
| 50 | |
| 51 | #elif defined(SIGN_GCRYPT) |
| 52 | |
| 53 | typedef struct { |
| 54 | int keytype; |
| 55 | gcry_mpi_t n; |
| 56 | gcry_mpi_t e; |
| 57 | gcry_mpi_t d; |
| 58 | gcry_mpi_t p; |
| 59 | gcry_mpi_t q; |
| 60 | gcry_mpi_t dp; |
| 61 | gcry_mpi_t dq; |
| 62 | gcry_mpi_t qp; |
| 63 | } es_ctx; |
| 64 | |
| 65 | typedef struct { |
| 66 | int keytype; |
| 67 | gcry_mpi_t n; |
| 68 | gcry_mpi_t e; |
| 69 | } ev_ctx; |
| 70 | |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | extern void exim_dkim_init(void); |
| 75 | extern blob * exim_dkim_data_append(blob *, int *, uschar *); |
| 76 | |
| 77 | extern const uschar * exim_dkim_signing_init(uschar *, es_ctx *); |
| 78 | extern const uschar * exim_dkim_sign(es_ctx *, hashmethod, blob *, blob *); |
| 79 | extern const uschar * exim_dkim_verify_init(blob *, ev_ctx *); |
| 80 | extern const uschar * exim_dkim_verify(ev_ctx *, hashmethod, blob *, blob *); |
| 81 | |
| 82 | #endif /*DISABLE_DKIM*/ |
| 83 | /* End of File */ |