]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/crypto.h
Merge the Bacula Encryption branch to HEAD.
[bacula/bacula] / bacula / src / lib / crypto.h
1 /*
2  * crypto.h Encryption support functions
3  *
4  * Author: Landon Fuller <landonf@opendarwin.org>
5  *
6  * Version $Id$
7  *
8  * Copyright (C) 2005 Kern Sibbald
9  *
10  * This file was contributed to the Bacula project by Landon Fuller.
11  *
12  * Landon Fuller has been granted a perpetual, worldwide, non-exclusive,
13  * no-charge, royalty-free, irrevocable copyright * license to reproduce,
14  * prepare derivative works of, publicly display, publicly perform,
15  * sublicense, and distribute the original work contributed by Landon Fuller
16  * to the Bacula project in source or object form.
17  *
18  * If you wish to license these contributions under an alternate open source
19  * license please contact Landon Fuller <landonf@opendarwin.org>.
20  */
21 /*
22    Copyright (C) 2005 Kern Sibbald
23
24    This program is free software; you can redistribute it and/or
25    modify it under the terms of the GNU General Public License
26    version 2 as amended with additional clauses defined in the
27    file LICENSE in the main source directory.
28
29    This program is distributed in the hope that it will be useful,
30    but WITHOUT ANY WARRANTY; without even the implied warranty of
31    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
32    the file LICENSE for additional details.
33
34  */
35
36 #ifndef __CRYPTO_H_
37 #define __CRYPTO_H_
38
39 /* Opaque X509 Public/Private Key Pair Structure */
40 typedef struct X509_Keypair X509_KEYPAIR;
41
42 /* Opaque Message Digest Structure */
43 typedef struct Digest DIGEST;
44
45 /* Opaque Message Signature Structure */
46 typedef struct Signature SIGNATURE;
47
48 /* PEM Decryption Passphrase Callback */
49 typedef int (CRYPTO_PEM_PASSWD_CB) (char *buf, int size, const void *userdata);
50
51 /* Digest Types */
52 typedef enum {
53    /* These are stored on disk and MUST NOT change */
54    CRYPTO_DIGEST_NONE = 0,
55    CRYPTO_DIGEST_MD5 = 1,
56    CRYPTO_DIGEST_SHA1 = 2,
57    CRYPTO_DIGEST_SHA256 = 3,
58    CRYPTO_DIGEST_SHA512 = 4
59 } crypto_digest_t;
60
61 /* Crypto API Errors */
62 typedef enum {
63    CRYPTO_ERROR_NONE           = 0, /* No error */
64    CRYPTO_ERROR_NOSIGNER       = 1, /* Signer not found */
65    CRYPTO_ERROR_INVALID_DIGEST = 2, /* Unsupported digest algorithm */
66    CRYPTO_ERROR_BAD_SIGNATURE  = 3, /* Signature is invalid */
67    CRYPTO_ERROR_INTERNAL       = 4  /* Internal Error */
68 } crypto_error_t;
69
70 /* Message Digest Sizes */
71 #define CRYPTO_DIGEST_MD5_SIZE 16     /* 128 bits */
72 #define CRYPTO_DIGEST_SHA1_SIZE 20    /* 160 bits */
73 #define CRYPTO_DIGEST_SHA256_SIZE 32  /* 256 bits */
74 #define CRYPTO_DIGEST_SHA512_SIZE 64  /* 512 bits */
75
76 /* Maximum Message Digest Size */
77 #ifdef HAVE_OPENSSL
78
79 /* Let OpenSSL define it */
80 #define CRYPTO_DIGEST_MAX_SIZE EVP_MAX_MD_SIZE
81
82 #else /* HAVE_OPENSSL */
83
84 /*
85  * This must be kept in sync with the available message digest algorithms.
86  * Just in case someone forgets, I've added assertions
87  * to crypto_digest_finalize().
88  *      MD5: 128 bits
89  *      SHA-1: 160 bits
90  */
91 #ifndef HAVE_SHA2
92 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA1_SIZE
93 #else
94 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA512_SIZE
95 #endif
96
97 #endif /* HAVE_OPENSSL */
98
99 #endif /* __CRYPTO_H_ */