summaryrefslogtreecommitdiff
path: root/crypto/cipher.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2015-07-01 18:10:33 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2015-07-08 13:11:01 +0200
commit62893b67cd82bbd48b013c1cec25f0d863612c80 (patch)
treefdcded03d2afd85f14e082d1264808ac8b0e4abb /crypto/cipher.c
parentca38a4cc9e36647437b837b346a41981fb8880cd (diff)
downloadqemu-62893b67cd82bbd48b013c1cec25f0d863612c80.tar.gz
qemu-62893b67cd82bbd48b013c1cec25f0d863612c80.tar.bz2
qemu-62893b67cd82bbd48b013c1cec25f0d863612c80.zip
crypto: add a gcrypt cipher implementation
If we are linking to gnutls already and gnutls is built against gcrypt, then we should use gcrypt as a cipher backend in preference to our built-in backend. This will be used when linking against GNUTLS 1.x and many GNUTLS 2.x versions. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <1435770638-25715-6-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'crypto/cipher.c')
-rw-r--r--crypto/cipher.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 0944827fa1..ed4d854a13 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -20,6 +20,7 @@
#include "crypto/cipher.h"
+
static size_t alg_key_len[QCRYPTO_CIPHER_ALG_LAST] = {
[QCRYPTO_CIPHER_ALG_AES_128] = 16,
[QCRYPTO_CIPHER_ALG_AES_192] = 24,
@@ -46,4 +47,26 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgorithm alg,
return true;
}
+#if defined(CONFIG_GNUTLS_GCRYPT)
+static uint8_t *
+qcrypto_cipher_munge_des_rfb_key(const uint8_t *key,
+ size_t nkey)
+{
+ uint8_t *ret = g_new0(uint8_t, nkey);
+ size_t i;
+ for (i = 0; i < nkey; i++) {
+ uint8_t r = key[i];
+ r = (r & 0xf0) >> 4 | (r & 0x0f) << 4;
+ r = (r & 0xcc) >> 2 | (r & 0x33) << 2;
+ r = (r & 0xaa) >> 1 | (r & 0x55) << 1;
+ ret[i] = r;
+ }
+ return ret;
+}
+#endif /* CONFIG_GNUTLS_GCRYPT */
+
+#ifdef CONFIG_GNUTLS_GCRYPT
+#include "crypto/cipher-gcrypt.c"
+#else
#include "crypto/cipher-builtin.c"
+#endif