forked from panda-re/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/berrange/tags/pull-qcrypto-2016…
…-03-17-3' into staging Merge QCrypto 2016/03/17 v3 # gpg: Signature made Thu 17 Mar 2016 16:51:32 GMT using RSA key ID 15104FDF # gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" # gpg: aka "Daniel P. Berrange <berrange@redhat.com>" * remotes/berrange/tags/pull-qcrypto-2016-03-17-3: crypto: implement the LUKS block encryption format crypto: add block encryption framework crypto: wire up XTS mode for cipher APIs crypto: refactor code for dealing with AES cipher crypto: import an implementation of the XTS cipher mode crypto: add support for the twofish cipher algorithm crypto: add support for the serpent cipher algorithm crypto: add support for the cast5-128 cipher algorithm crypto: skip testing of unsupported cipher algorithms crypto: add support for anti-forensic split algorithm crypto: add support for generating initialization vectors crypto: add support for PBKDF2 algorithm crypto: add cryptographic random byte source Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
- Loading branch information
Showing
45 changed files
with
6,488 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* QEMU Crypto anti forensic information splitter | ||
* | ||
* Copyright (c) 2015-2016 Red Hat, Inc. | ||
* | ||
* Derived from cryptsetup package lib/luks1/af.c | ||
* | ||
* Copyright (C) 2004, Clemens Fruhwirth <clemens@endorphin.org> | ||
* Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "qemu/osdep.h" | ||
#include "crypto/afsplit.h" | ||
#include "crypto/random.h" | ||
|
||
|
||
static void qcrypto_afsplit_xor(size_t blocklen, | ||
const uint8_t *in1, | ||
const uint8_t *in2, | ||
uint8_t *out) | ||
{ | ||
size_t i; | ||
for (i = 0; i < blocklen; i++) { | ||
out[i] = in1[i] ^ in2[i]; | ||
} | ||
} | ||
|
||
|
||
static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash, | ||
size_t blocklen, | ||
uint8_t *block, | ||
Error **errp) | ||
{ | ||
size_t digestlen = qcrypto_hash_digest_len(hash); | ||
|
||
size_t hashcount = blocklen / digestlen; | ||
size_t finallen = blocklen % digestlen; | ||
uint32_t i; | ||
|
||
if (finallen) { | ||
hashcount++; | ||
} else { | ||
finallen = digestlen; | ||
} | ||
|
||
for (i = 0; i < hashcount; i++) { | ||
uint8_t *out = NULL; | ||
size_t outlen = 0; | ||
uint32_t iv = cpu_to_be32(i); | ||
struct iovec in[] = { | ||
{ .iov_base = &iv, | ||
.iov_len = sizeof(iv) }, | ||
{ .iov_base = block + (i * digestlen), | ||
.iov_len = (i == (hashcount - 1)) ? finallen : digestlen }, | ||
}; | ||
|
||
if (qcrypto_hash_bytesv(hash, | ||
in, | ||
G_N_ELEMENTS(in), | ||
&out, &outlen, | ||
errp) < 0) { | ||
return -1; | ||
} | ||
|
||
assert(outlen == digestlen); | ||
memcpy(block + (i * digestlen), out, | ||
(i == (hashcount - 1)) ? finallen : digestlen); | ||
g_free(out); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash, | ||
size_t blocklen, | ||
uint32_t stripes, | ||
const uint8_t *in, | ||
uint8_t *out, | ||
Error **errp) | ||
{ | ||
uint8_t *block = g_new0(uint8_t, blocklen); | ||
size_t i; | ||
int ret = -1; | ||
|
||
for (i = 0; i < (stripes - 1); i++) { | ||
if (qcrypto_random_bytes(out + (i * blocklen), blocklen, errp) < 0) { | ||
goto cleanup; | ||
} | ||
|
||
qcrypto_afsplit_xor(blocklen, | ||
out + (i * blocklen), | ||
block, | ||
block); | ||
if (qcrypto_afsplit_hash(hash, blocklen, block, | ||
errp) < 0) { | ||
goto cleanup; | ||
} | ||
} | ||
qcrypto_afsplit_xor(blocklen, | ||
in, | ||
block, | ||
out + (i * blocklen)); | ||
ret = 0; | ||
|
||
cleanup: | ||
g_free(block); | ||
return ret; | ||
} | ||
|
||
|
||
int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, | ||
size_t blocklen, | ||
uint32_t stripes, | ||
const uint8_t *in, | ||
uint8_t *out, | ||
Error **errp) | ||
{ | ||
uint8_t *block = g_new0(uint8_t, blocklen); | ||
size_t i; | ||
int ret = -1; | ||
|
||
for (i = 0; i < (stripes - 1); i++) { | ||
qcrypto_afsplit_xor(blocklen, | ||
in + (i * blocklen), | ||
block, | ||
block); | ||
if (qcrypto_afsplit_hash(hash, blocklen, block, | ||
errp) < 0) { | ||
goto cleanup; | ||
} | ||
} | ||
|
||
qcrypto_afsplit_xor(blocklen, | ||
in + (i * blocklen), | ||
block, | ||
out); | ||
|
||
ret = 0; | ||
|
||
cleanup: | ||
g_free(block); | ||
return ret; | ||
} |
Oops, something went wrong.