]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/crypto.h
commit changes
[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) 2006 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 /* Opaque PKI Symmetric Key Data Structure */
49 typedef struct Crypto_Session CRYPTO_SESSION;
50
51 /* Opaque Encryption/Decryption Context Structure */
52 typedef struct Cipher_Context CIPHER_CONTEXT;
53
54 /* PEM Decryption Passphrase Callback */
55 typedef int (CRYPTO_PEM_PASSWD_CB) (char *buf, int size, const void *userdata);
56
57 /* Digest Types */
58 typedef enum {
59    /* These are stored on disk and MUST NOT change */
60    CRYPTO_DIGEST_NONE = 0,
61    CRYPTO_DIGEST_MD5 = 1,
62    CRYPTO_DIGEST_SHA1 = 2,
63    CRYPTO_DIGEST_SHA256 = 3,
64    CRYPTO_DIGEST_SHA512 = 4
65 } crypto_digest_t;
66
67 /* Cipher Types */
68 typedef enum {
69    /* These are not stored on disk */
70    CRYPTO_CIPHER_AES_128_CBC,
71    CRYPTO_CIPHER_AES_192_CBC,
72    CRYPTO_CIPHER_AES_256_CBC,
73    CRYPTO_CIPHER_BLOWFISH_CBC
74 } crypto_cipher_t;
75
76 /* Crypto API Errors */
77 typedef enum {
78    CRYPTO_ERROR_NONE           = 0, /* No error */
79    CRYPTO_ERROR_NOSIGNER       = 1, /* Signer not found */
80    CRYPTO_ERROR_NORECIPIENT    = 2, /* Recipient not found */
81    CRYPTO_ERROR_INVALID_DIGEST = 3, /* Unsupported digest algorithm */
82    CRYPTO_ERROR_INVALID_CRYPTO = 4, /* Unsupported encryption algorithm */
83    CRYPTO_ERROR_BAD_SIGNATURE  = 5, /* Signature is invalid */
84    CRYPTO_ERROR_DECRYPTION     = 6, /* Decryption error */
85    CRYPTO_ERROR_INTERNAL       = 7  /* Internal Error */
86 } crypto_error_t;
87
88 /* Message Digest Sizes */
89 #define CRYPTO_DIGEST_MD5_SIZE 16     /* 128 bits */
90 #define CRYPTO_DIGEST_SHA1_SIZE 20    /* 160 bits */
91 #define CRYPTO_DIGEST_SHA256_SIZE 32  /* 256 bits */
92 #define CRYPTO_DIGEST_SHA512_SIZE 64  /* 512 bits */
93
94 /* Maximum Message Digest Size */
95 #ifdef HAVE_OPENSSL
96
97 /* Let OpenSSL define a few things */
98 #define CRYPTO_DIGEST_MAX_SIZE         EVP_MAX_MD_SIZE
99 #define CRYPTO_CIPHER_MAX_BLOCK_SIZE   EVP_MAX_BLOCK_LENGTH
100
101 #else /* HAVE_OPENSSL */
102
103 /*
104  * This must be kept in sync with the available message digest algorithms.
105  * Just in case someone forgets, I've added assertions
106  * to crypto_digest_finalize().
107  *      MD5: 128 bits
108  *      SHA-1: 160 bits
109  */
110 #ifndef HAVE_SHA2
111 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA1_SIZE
112 #else
113 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA512_SIZE
114 #endif
115
116 /* Dummy Value */
117 #define CRYPTO_CIPHER_MAX_BLOCK_SIZE 0
118
119 #endif /* HAVE_OPENSSL */
120
121 #endif /* __CRYPTO_H_ */