[epiphany/wip/ephy-sync: 76/126] sync-crypto: AES encryption/decryption functions



commit 6e5e7b8b35b6f79708fbe1002c21fe74c9b44ce2
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Wed Jul 27 16:03:24 2016 +0300

    sync-crypto: AES encryption/decryption functions

 src/ephy-sync-crypto.c |   35 +++++++++++++++++++++++++++++++++++
 src/ephy-sync-crypto.h |    8 ++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/ephy-sync-crypto.c b/src/ephy-sync-crypto.c
index ad5a1ee..d72a54a 100644
--- a/src/ephy-sync-crypto.c
+++ b/src/ephy-sync-crypto.c
@@ -20,6 +20,7 @@
 
 #include <glib/gstdio.h>
 #include <libsoup/soup.h>
+#include <nettle/aes.h>
 #include <string.h>
 
 #define HAWK_VERSION  1
@@ -972,6 +973,40 @@ out:
   return assertion;
 }
 
+guint8 *
+ephy_sync_crypto_encode_aes_256 (const guint8 *key,
+                                 const guint8 *data,
+                                 gsize         data_length)
+{
+  struct aes256_ctx aes;
+  guint8 *out;
+
+  g_assert (data_length % AES_BLOCK_SIZE == 0);
+
+  out = g_malloc (data_length);
+  aes256_set_encrypt_key (&aes, key);
+  aes256_encrypt (&aes, data_length, out, data);
+
+  return out;
+}
+
+guint8 *
+ephy_sync_crypto_decode_aes_256 (const guint8 *key,
+                                 const guint8 *data,
+                                 gsize         data_length)
+{
+  struct aes256_ctx aes;
+  guint8 *out;
+
+  g_assert (data_length % AES_BLOCK_SIZE == 0);
+
+  out = g_malloc (data_length);
+  aes256_set_decrypt_key (&aes, key);
+  aes256_decrypt (&aes, data_length, out, data);
+
+  return out;
+}
+
 gchar *
 ephy_sync_crypto_encode_hex (guint8 *data,
                              gsize   data_length)
diff --git a/src/ephy-sync-crypto.h b/src/ephy-sync-crypto.h
index f9a6580..902f285 100644
--- a/src/ephy-sync-crypto.h
+++ b/src/ephy-sync-crypto.h
@@ -125,6 +125,14 @@ gchar                      *ephy_sync_crypto_create_assertion        (const gcha
                                                                       guint64                   duration,
                                                                       EphySyncCryptoRSAKeyPair *keypair);
 
+guint8                     *ephy_sync_crypto_encode_aes_256          (const guint8 *key,
+                                                                      const guint8 *data,
+                                                                      gsize         data_length);
+
+guint8                     *ephy_sync_crypto_decode_aes_256          (const guint8 *key,
+                                                                      const guint8 *data,
+                                                                      gsize         data_length);
+
 gchar                      *ephy_sync_crypto_encode_hex              (guint8 *data,
                                                                       gsize   data_length);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]