]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/crypto.h
Remove obsolete .cvsignore files.
[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  * This file was contributed to the Bacula project by Landon Fuller.
9  *
10  * Landon Fuller has been granted a perpetual, worldwide, non-exclusive,
11  * no-charge, royalty-free, irrevocable copyright * license to reproduce,
12  * prepare derivative works of, publicly display, publicly perform,
13  * sublicense, and distribute the original work contributed by Landon Fuller
14  * to the Bacula project in source or object form.
15  *
16  * If you wish to license these contributions under an alternate open source
17  * license please contact Landon Fuller <landonf@opendarwin.org>.
18  */
19 /*
20    Bacula® - The Network Backup Solution
21
22    Copyright (C) 2005-2006 Free Software Foundation Europe e.V.
23
24    The main author of Bacula is Kern Sibbald, with contributions from
25    many others, a complete list can be found in the file AUTHORS.
26    This program is Free Software; you can redistribute it and/or
27    modify it under the terms of version two of the GNU General Public
28    License as published by the Free Software Foundation plus additions
29    that are listed in the file LICENSE.
30
31    This program is distributed in the hope that it will be useful, but
32    WITHOUT ANY WARRANTY; without even the implied warranty of
33    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34    General Public License for more details.
35
36    You should have received a copy of the GNU General Public License
37    along with this program; if not, write to the Free Software
38    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39    02110-1301, USA.
40
41    Bacula® is a registered trademark of John Walker.
42    The licensor of Bacula is the Free Software Foundation Europe
43    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
44    Switzerland, email:ftf@fsfeurope.org.
45 */
46
47 #ifndef __CRYPTO_H_
48 #define __CRYPTO_H_
49
50 /* Opaque X509 Public/Private Key Pair Structure */
51 typedef struct X509_Keypair X509_KEYPAIR;
52
53 /* Opaque Message Digest Structure */
54 typedef struct Digest DIGEST;
55
56 /* Opaque Message Signature Structure */
57 typedef struct Signature SIGNATURE;
58
59 /* Opaque PKI Symmetric Key Data Structure */
60 typedef struct Crypto_Session CRYPTO_SESSION;
61
62 /* Opaque Encryption/Decryption Context Structure */
63 typedef struct Cipher_Context CIPHER_CONTEXT;
64
65 /* PEM Decryption Passphrase Callback */
66 typedef int (CRYPTO_PEM_PASSWD_CB) (char *buf, int size, const void *userdata);
67
68 /* Digest Types */
69 typedef enum {
70    /* These are stored on disk and MUST NOT change */
71    CRYPTO_DIGEST_NONE = 0,
72    CRYPTO_DIGEST_MD5 = 1,
73    CRYPTO_DIGEST_SHA1 = 2,
74    CRYPTO_DIGEST_SHA256 = 3,
75    CRYPTO_DIGEST_SHA512 = 4
76 } crypto_digest_t;
77
78 /* Cipher Types */
79 typedef enum {
80    /* These are not stored on disk */
81    CRYPTO_CIPHER_AES_128_CBC,
82    CRYPTO_CIPHER_AES_192_CBC,
83    CRYPTO_CIPHER_AES_256_CBC,
84    CRYPTO_CIPHER_BLOWFISH_CBC
85 } crypto_cipher_t;
86
87 /* Crypto API Errors */
88 typedef enum {
89    CRYPTO_ERROR_NONE           = 0, /* No error */
90    CRYPTO_ERROR_NOSIGNER       = 1, /* Signer not found */
91    CRYPTO_ERROR_NORECIPIENT    = 2, /* Recipient not found */
92    CRYPTO_ERROR_INVALID_DIGEST = 3, /* Unsupported digest algorithm */
93    CRYPTO_ERROR_INVALID_CRYPTO = 4, /* Unsupported encryption algorithm */
94    CRYPTO_ERROR_BAD_SIGNATURE  = 5, /* Signature is invalid */
95    CRYPTO_ERROR_DECRYPTION     = 6, /* Decryption error */
96    CRYPTO_ERROR_INTERNAL       = 7  /* Internal Error */
97 } crypto_error_t;
98
99 /* Message Digest Sizes */
100 #define CRYPTO_DIGEST_MD5_SIZE 16     /* 128 bits */
101 #define CRYPTO_DIGEST_SHA1_SIZE 20    /* 160 bits */
102 #define CRYPTO_DIGEST_SHA256_SIZE 32  /* 256 bits */
103 #define CRYPTO_DIGEST_SHA512_SIZE 64  /* 512 bits */
104
105 /* Maximum Message Digest Size */
106 #ifdef HAVE_OPENSSL
107
108 /* Let OpenSSL define a few things */
109 #define CRYPTO_DIGEST_MAX_SIZE         EVP_MAX_MD_SIZE
110 #define CRYPTO_CIPHER_MAX_BLOCK_SIZE   EVP_MAX_BLOCK_LENGTH
111
112 #else /* HAVE_OPENSSL */
113
114 /*
115  * This must be kept in sync with the available message digest algorithms.
116  * Just in case someone forgets, I've added assertions
117  * to crypto_digest_finalize().
118  *      MD5: 128 bits
119  *      SHA-1: 160 bits
120  */
121 #ifndef HAVE_SHA2
122 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA1_SIZE
123 #else
124 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA512_SIZE
125 #endif
126
127 /* Dummy Value */
128 #define CRYPTO_CIPHER_MAX_BLOCK_SIZE 0
129
130 #endif /* HAVE_OPENSSL */
131
132 #endif /* __CRYPTO_H_ */