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