1 /* 2 Bacula(R) - The Network Backup Solution 3 4 Copyright (C) 2000-2020 Kern Sibbald 5 6 The original author of Bacula is Kern Sibbald, with contributions 7 from many others, a complete list can be found in the file AUTHORS. 8 9 You may use this file and others of this release according to the 10 license defined in the LICENSE file, which includes the Affero General 11 Public License, v3.0 ("AGPLv3") and some additional permissions and 12 terms pursuant to its AGPLv3 Section 7. 13 14 This notice must be preserved when any source code is 15 conveyed and/or propagated. 16 17 Bacula(R) is a registered trademark of Kern Sibbald. 18 */ 19 /* 20 * crypto.h Encryption support functions 21 * 22 * Author: Landon Fuller <landonf@opendarwin.org> 23 * 24 * Version $Id$ 25 * 26 * This file was contributed to the Bacula project by Landon Fuller. 27 * 28 * Landon Fuller has been granted a perpetual, worldwide, non-exclusive, 29 * no-charge, royalty-free, irrevocable copyright * license to reproduce, 30 * prepare derivative works of, publicly display, publicly perform, 31 * sublicense, and distribute the original work contributed by Landon Fuller 32 * to the Bacula project in source or object form. 33 * 34 * If you wish to license these contributions under an alternate open source 35 * license please contact Landon Fuller <landonf@opendarwin.org>. 36 */ 37 38 #ifndef __CRYPTO_H_ 39 #define __CRYPTO_H_ 40 41 /* Opaque X509 Public/Private Key Pair Structure */ 42 typedef struct X509_Keypair X509_KEYPAIR; 43 44 /* Opaque Message Digest Structure */ 45 /* Digest is defined (twice) in crypto.c */ 46 typedef struct Digest DIGEST; 47 48 /* Opaque Message Signature Structure */ 49 typedef struct Signature SIGNATURE; 50 51 /* Opaque PKI Symmetric Key Data Structure */ 52 typedef struct Crypto_Session CRYPTO_SESSION; 53 54 /* Opaque Encryption/Decryption Context Structure */ 55 typedef struct Cipher_Context CIPHER_CONTEXT; 56 57 /* PEM Decryption Passphrase Callback */ 58 typedef int (CRYPTO_PEM_PASSWD_CB) (char *buf, int size, const void *userdata); 59 60 /* Digest Types */ 61 typedef enum { 62 /* These are stored on disk and MUST NOT change */ 63 CRYPTO_DIGEST_NONE = 0, 64 CRYPTO_DIGEST_MD5 = 1, 65 CRYPTO_DIGEST_SHA1 = 2, 66 CRYPTO_DIGEST_SHA256 = 3, 67 CRYPTO_DIGEST_SHA512 = 4 68 } crypto_digest_t; 69 70 71 #ifdef HAVE_SHA2 72 # define CRYPTO_DIGEST_DEFAULT CRYPTO_DIGEST_SHA256 73 #else 74 # define CRYPTO_DIGEST_DEFAULT CRYPTO_DIGEST_SHA1 75 #endif 76 77 /* Cipher Types */ 78 typedef enum { 79 /* These are not stored on disk */ 80 CRYPTO_CIPHER_AES_128_CBC, /* Keep AES128 as the first one */ 81 CRYPTO_CIPHER_AES_192_CBC, 82 CRYPTO_CIPHER_AES_256_CBC, 83 CRYPTO_CIPHER_BLOWFISH_CBC 84 } crypto_cipher_t; 85 86 /* Crypto API Errors */ 87 typedef enum { 88 CRYPTO_ERROR_NONE = 0, /* No error */ 89 CRYPTO_ERROR_NOSIGNER = 1, /* Signer not found */ 90 CRYPTO_ERROR_NORECIPIENT = 2, /* Recipient not found */ 91 CRYPTO_ERROR_INVALID_DIGEST = 3, /* Unsupported digest algorithm */ 92 CRYPTO_ERROR_INVALID_CRYPTO = 4, /* Unsupported encryption algorithm */ 93 CRYPTO_ERROR_BAD_SIGNATURE = 5, /* Signature is invalid */ 94 CRYPTO_ERROR_DECRYPTION = 6, /* Decryption error */ 95 CRYPTO_ERROR_INTERNAL = 7 /* Internal Error */ 96 } crypto_error_t; 97 98 /* Message Digest Sizes */ 99 #define CRYPTO_DIGEST_MD5_SIZE 16 /* 128 bits */ 100 #define CRYPTO_DIGEST_SHA1_SIZE 20 /* 160 bits */ 101 #define CRYPTO_DIGEST_SHA256_SIZE 32 /* 256 bits */ 102 #define CRYPTO_DIGEST_SHA512_SIZE 64 /* 512 bits */ 103 104 /* Maximum Message Digest Size */ 105 #ifdef HAVE_OPENSSL 106 107 /* Let OpenSSL define a few things */ 108 #define CRYPTO_DIGEST_MAX_SIZE EVP_MAX_MD_SIZE 109 #define CRYPTO_CIPHER_MAX_BLOCK_SIZE EVP_MAX_BLOCK_LENGTH 110 111 #else /* HAVE_OPENSSL */ 112 113 /* 114 * This must be kept in sync with the available message digest algorithms. 115 * Just in case someone forgets, I've added assertions 116 * to crypto_digest_finalize(). 117 * MD5: 128 bits 118 * SHA-1: 160 bits 119 */ 120 #ifndef HAVE_SHA2 121 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA1_SIZE 122 #else 123 #define CRYPTO_DIGEST_MAX_SIZE CRYPTO_DIGEST_SHA512_SIZE 124 #endif 125 126 /* Dummy Value */ 127 #define CRYPTO_CIPHER_MAX_BLOCK_SIZE 0 128 129 #endif /* HAVE_OPENSSL */ 130 131 #endif /* __CRYPTO_H_ */ 132