2 * QEMU Crypto anti forensic information splitter
4 * Copyright (c) 2015-2016 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #ifndef QCRYPTO_AFSPLIT_H
22 #define QCRYPTO_AFSPLIT_H
24 #include "crypto/hash.h"
27 * This module implements the anti-forensic splitter that is specified
28 * as part of the LUKS format:
30 * http://clemens.endorphin.org/cryptography
31 * http://clemens.endorphin.org/TKS1-draft.pdf
33 * The core idea is to take a short piece of data (key material)
34 * and process it to expand it to a much larger piece of data.
35 * The expansion process is reversible, to obtain the original
36 * short data. The key property of the expansion is that if any
37 * byte in the larger data set is changed / missing, it should be
38 * impossible to recreate the original short data.
41 * <title>Creating a large split key for storage</title>
44 * uint32_t stripes = 32768; // To produce a 1 MB split key
45 * uint8_t *masterkey = ....a 32-byte AES key...
48 * splitkey = g_new0(uint8_t, nkey * stripes);
50 * if (qcrypto_afsplit_encode(QCRYPTO_HASH_ALG_SHA256,
52 * masterkey, splitkey, errp) < 0) {
58 * ...store splitkey somewhere...
66 * <title>Retrieving a master key from storage</title>
69 * uint32_t stripes = 32768; // To produce a 1 MB split key
71 * uint8_t *splitkey = .... read in 1 MB of data...
73 * masterkey = g_new0(uint8_t, nkey);
75 * if (qcrypto_afsplit_decode(QCRYPTO_HASH_ALG_SHA256,
77 * splitkey, masterkey, errp) < 0) {
83 * ..decrypt data with masterkey...
92 * qcrypto_afsplit_encode:
93 * @hash: the hash algorithm to use for data expansion
94 * @blocklen: the size of @in in bytes
95 * @stripes: the number of times to expand @in in size
96 * @in: the master key to be expanded in size
97 * @out: preallocated buffer to hold the split key
98 * @errp: pointer to a NULL-initialized error object
100 * Split the data in @in, which is @blocklen bytes in
101 * size, to form a larger piece of data @out, which is
102 * @blocklen * @stripes bytes in size.
104 * Returns: 0 on success, -1 on error;
106 int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash
,
114 * qcrypto_afsplit_decode:
115 * @hash: the hash algorithm to use for data compression
116 * @blocklen: the size of @out in bytes
117 * @stripes: the number of times to decrease @in in size
118 * @in: the split key to be recombined
119 * @out: preallocated buffer to hold the master key
120 * @errp: pointer to a NULL-initialized error object
122 * Join the data in @in, which is @blocklen * @stripes
123 * bytes in size, to form the original small piece of
124 * data @out, which is @blocklen bytes in size.
126 * Returns: 0 on success, -1 on error;
128 int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash
,
135 #endif /* QCRYPTO_AFSPLIT_H */