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