]> git.wh0rd.org - dump.git/blame - common/transformation.h
Encryption (and compression as plugins) support.
[dump.git] / common / transformation.h
CommitLineData
e3956dfb
SP
1#include <config.h>
2#include <bsdcompat.h>
3#include <protocols/dumprestore.h>
4
5#ifndef __P
6#include <sys/cdefs.h>
7#endif
8
9#ifdef HAVE_LZO
10#include <minilzo.h>
11#endif /* HAVE_LZO */
12
13#ifdef HAVE_OPENSSL
14#include <openssl/evp.h>
15#include <openssl/rand.h>
16#include <openssl/pkcs12.h>
17#endif
18
19#ifndef _transformation_H
20#define _transformation_H
21
22/*
23 * Compression/encryption hooks.
24 *
25 * Open questions:
26 * 1. should it be a failure if compress/decompress is called and we DON'T have the code included?
27 */
28
29typedef struct transformation {
30 int enc;
31 union {
32#ifdef HAVE_LZO
33 struct {
34 lzo_align_t __LZO_MMODEL *LZO_WorkMem;
35 } lzo;
36#endif /* HAVE_LZO */
37#ifdef HAVE_ZLIB
38 struct {
39 int complvl;
40 } zlib;
41#endif /* HAVE_ZLIB */
42#ifdef HAVE_BZLIB
43 struct {
44 int complvl;
45 } bzlib;
46#endif /* HAVE_ZLIB */
47#ifdef HAVE_OPENSSL
48 struct {
49 int complvl;
50
51 // encryption/decryption key
52 unsigned char key[EVP_MAX_KEY_LENGTH];
53 unsigned int keylen;
54
55 // crypto
56 const EVP_CIPHER *cipher;
57 const EVP_MD *digest;
58 ENGINE *engine;
59
60 // this assumes we're multi-process but not multi-threaded
61 EVP_CIPHER_CTX *dataCtx;
62 EVP_CIPHER_CTX *ivCtx;
63 } ssl;
64#endif
65 } state;
66
67 /*
68 * The name of the compression/encryption algorithm, for
69 * display purposes.
70 */
71 const char *name;
72
73 /*
74 * Is this mandatory even if the size of the buffer increases?
75 * As a general rule compression is optional * and encryption is
76 * mandatory.
77 */
78 int mandatory;
79
80 /*
81 * Initialize the system.
82 * (mode: 1 = compress/encrypt, 0 = decompress/decrypt)
83 */
84 int (*initialize) __P((struct transformation *xform, int mode));
85
86 /*
87 * Shut down the system
88 */
89 int (*shutdown) __P((struct transformation *xform));
90
91 /*
92 * Do anything necessary after forking the process.
93 */
94 int (*startNewTape) __P((struct transformation *xform,
95 struct tapebuf *tpbin, unsigned long *destlen));
96
97 /*
98 * The dump process is master-slave with the actual
99 * disk and dump tape access handled by the slave processes.
100 * This method performs any initialization required by
101 * the latter process. (E.g., some encryption libraries
102 * must be reinitialized.)
103 */
104 int (*startDiskIOProcess) __P((struct transformation *xform));
105
106 /*
107 * Clean up everything before the slave process ends.
108 */
109 int (*endDiskIOProcess) __P((struct transformation *xform));
110
111 /*
112 * Compress/encrypt buffer.
113 */
114 int (*compress) __P((struct transformation *xform, struct tapebuf *, unsigned long *destlen,
115 const char *src, int srclen));
116
117 /*
118 * Decompress/decrypt buffer.
119 */
120 int (*decompress) __P((struct transformation *xform, struct tapebuf *, unsigned long *destlen,
121 const char *src, int srclen, char **reason));
122
123} Transformation;
124
125extern Transformation transformation_null;
126
127#ifdef HAVE_LZO
128extern Transformation *transformation_lzo_factory(int enc);
129#endif /* HAVE_ZLIB */
130
131#ifdef HAVE_ZLIB
132extern Transformation *transformation_zlib_factory(int enc, int complvl);
133#endif /* HAVE_ZLIB */
134
135#ifdef HAVE_BZLIB
136extern Transformation *transformation_bzlib_factory(int enc, int complvl);
137#endif /* HAVE_BZLIB */
138
139#ifdef HAVE_OPENSSL
140extern Transformation *transformation_ssl_factory(int enc, int complvl,
141 const char *ciphername, const char *digestname);
142#endif /* HAVE_OPENSSL */
143
144#endif /* _transformation_H */