Added rijndael (AES) to cipher list.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 2 Oct 2000 18:31:46 +0000 (18:31 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 2 Oct 2000 18:31:46 +0000 (18:31 +0000)
lib/silccrypt/rijndael.c
lib/silccrypt/rijndael.h
lib/silccrypt/silccipher.c

index f6d5b1de390289124c73457bde42f332f0bcf6cb..1f7cadadcd13f3320bc627190b472bc9f2433b58 100644 (file)
@@ -1,4 +1,5 @@
 /* Modified for SILC. -Pekka */
+/* The AES */
 
 /* This is an independent implementation of the encryption algorithm:   */
 /*                                                                      */
@@ -41,6 +42,131 @@ Mean:          500 cycles =    51.2 mbits/sec
 #include "silcincludes.h"
 #include "rijndael.h"
 
+/* 
+ * SILC Crypto API for Rijndael
+ */
+
+/* Sets the key for the cipher. */
+
+SILC_CIPHER_API_SET_KEY(rijndael)
+{
+  rijndael_set_key((RijndaelContext *)context, (unsigned int *)key, keylen);
+  return 1;
+}
+
+/* Sets the string as a new key for the cipher. The string is first
+   hashed and then used as a new key. */
+
+SILC_CIPHER_API_SET_KEY_WITH_STRING(rijndael)
+{
+  /*  unsigned char key[md5_hash_len];
+  SilcMarsContext *ctx = (SilcMarsContext *)context;
+
+  make_md5_hash(string, &key);
+  memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
+  memset(&key, 'F', sizeoof(key));
+  */
+
+  return 1;
+}
+
+/* Returns the size of the cipher context. */
+
+SILC_CIPHER_API_CONTEXT_LEN(rijndael)
+{
+  return sizeof(RijndaelContext);
+}
+
+/* Encrypts with the cipher in CBC mode. Source and destination buffers
+   maybe one and same. */
+
+SILC_CIPHER_API_ENCRYPT_CBC(rijndael)
+{
+  unsigned int *in, *out, *tiv;
+  unsigned int tmp[4];
+  int i;
+
+  in = (unsigned int *)src;
+  out = (unsigned int *)dst;
+  tiv = (unsigned int *)iv;
+
+  tmp[0] = in[0] ^ tiv[0];
+  tmp[1] = in[1] ^ tiv[1];
+  tmp[2] = in[2] ^ tiv[2];
+  tmp[3] = in[3] ^ tiv[3];
+  rijndael_encrypt((RijndaelContext *)context, tmp, out);
+  in += 4;
+  out += 4;
+
+  for (i = 16; i < len; i += 16) {
+    tmp[0] = in[0] ^ out[0 - 4];
+    tmp[1] = in[1] ^ out[1 - 4];
+    tmp[2] = in[2] ^ out[2 - 4];
+    tmp[3] = in[3] ^ out[3 - 4];
+    rijndael_encrypt((RijndaelContext *)context, tmp, out);
+    in += 4;
+    out += 4;
+  }
+
+  tiv[0] = out[0 - 4];
+  tiv[1] = out[1 - 4];
+  tiv[2] = out[2 - 4];
+  tiv[3] = out[3 - 4];
+
+  return TRUE;
+}
+
+/* Decrypts with the cipher in CBC mode. Source and destination buffers
+   maybe one and same. */
+
+SILC_CIPHER_API_DECRYPT_CBC(rijndael)
+{
+  unsigned int *tiv, *in, *out;
+  unsigned int tmp[4], tmp2[4];
+  int i;
+
+  in = (unsigned int *)src;
+  out = (unsigned int *)dst;
+  tiv = (unsigned int *)iv;
+
+  tmp[0] = in[0];
+  tmp[1] = in[1];
+  tmp[2] = in[2];
+  tmp[3] = in[3];
+  rijndael_decrypt((RijndaelContext *)context, in, out);
+  out[0] ^= tiv[0];
+  out[1] ^= tiv[1];
+  out[2] ^= tiv[2];
+  out[3] ^= tiv[3];
+  in += 4;
+  out += 4;
+
+  for (i = 16; i < len; i += 16) {
+    tmp2[0] = tmp[0];
+    tmp2[1] = tmp[1];
+    tmp2[2] = tmp[2];
+    tmp2[3] = tmp[3];
+    tmp[0] = in[0];
+    tmp[1] = in[1];
+    tmp[2] = in[2];
+    tmp[3] = in[3];
+    rijndael_decrypt((RijndaelContext *)context, in, out);
+    out[0] ^= tmp2[0];
+    out[1] ^= tmp2[1];
+    out[2] ^= tmp2[2];
+    out[3] ^= tmp2[3];
+    in += 4;
+    out += 4;
+  }
+
+  tiv[0] = tmp[0];
+  tiv[1] = tmp[1];
+  tiv[2] = tmp[2];
+  tiv[3] = tmp[3];
+
+  return TRUE;
+}
+
 #define LARGE_TABLES
 
 u1byte  pow_tab[256];
index 6307a5e245d52182a17878fb32da83e82313143f..15fc3c8f8a9a30f4aa0407877692ef66dbd4571b 100644 (file)
 /*
  * $Id$
  * $Log$
- * Revision 1.1  2000/06/27 11:36:55  priikone
- * Initial revision
+ * Revision 1.2  2000/10/02 18:31:46  priikone
+ *     Added rijndael (AES) to cipher list.
+ *
+ * Revision 1.1.1.1  2000/06/27 11:36:55  priikone
+ *     Importet from internal CVS/Added Log headers.
  *
  *
  */
  * SILC Crypto API for Rijndael
  */
 
-/* Sets the key for the cipher. */
-
-SILC_CIPHER_API_SET_KEY(rijndael)
-{
-  rijndael_set_key((RijndaelContext *)context, (unsigned int *)key, keylen);
-  return TRUE;
-}
-
-/* Sets the string as a new key for the cipher. The string is first
-   hashed and then used as a new key. */
-
-SILC_CIPHER_API_SET_KEY_WITH_STRING(rijndael)
-{
-  /*  unsigned char key[md5_hash_len];
-  SilcMarsContext *ctx = (SilcMarsContext *)context;
-
-  make_md5_hash(string, &key);
-  memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
-  memset(&key, 'F', sizeoof(key));
-  */
-
-  return TRUE;
-}
-
-/* Returns the size of the cipher context. */
-
-SILC_CIPHER_API_CONTEXT_LEN(rijnadel)
-{
-  return sizeof(RijndaelContext);
-}
-
-/* Encrypts with the cipher in CBC mode. Source and destination buffers
-   maybe one and same. */
-
-SILC_CIPHER_API_ENCRYPT_CBC(rijndael)
-{
-  unsigned int *in, *out, *tiv;
-  unsigned int tmp[4];
-  int i;
-
-  in = (unsigned int *)src;
-  out = (unsigned int *)dst;
-  tiv = (unsigned int *)iv;
-
-  tmp[0] = in[0] ^ tiv[0];
-  tmp[1] = in[1] ^ tiv[1];
-  tmp[2] = in[2] ^ tiv[2];
-  tmp[3] = in[3] ^ tiv[3];
-  rijndael_encrypt((RijndaelContext *)context, tmp, out);
-  in += 4;
-  out += 4;
-
-  for (i = 16; i < len; i += 16) {
-    tmp[0] = in[0] ^ out[0 - 4];
-    tmp[1] = in[1] ^ out[1 - 4];
-    tmp[2] = in[2] ^ out[2 - 4];
-    tmp[3] = in[3] ^ out[3 - 4];
-    rijndael_encrypt((RijndaelContext *)context, tmp, out);
-    in += 4;
-    out += 4;
-  }
-
-  return TRUE;
-}
-
-/* Decrypts with the cipher in CBC mode. Source and destination buffers
-   maybe one and same. */
-
-SILC_CIPHER_API_DECRYPT_CBC(rijndael)
-{
-  unsigned int *in, *out, *tiv;
-  unsigned int tmp[4], tmp2[4];
-  int i;
-
-  in = (unsigned int *)src;
-  out = (unsigned int *)dst;
-  tiv = (unsigned int *)iv;
-
-  tmp[0] = in[0];
-  tmp[1] = in[1];
-  tmp[2] = in[2];
-  tmp[3] = in[3];
-  rijndael_decrypt((RijndaelContext *)context, in, out);
-  out[0] ^= tiv[0];
-  out[1] ^= tiv[1];
-  out[2] ^= tiv[2];
-  out[3] ^= tiv[3];
-  in += 4;
-  out += 4;
-
-  for (i = 16; i < len; i += 16) {
-    tmp2[0] = tmp[0];
-    tmp2[1] = tmp[1];
-    tmp2[2] = tmp[2];
-    tmp2[3] = tmp[3];
-    tmp[0] = in[0];
-    tmp[1] = in[1];
-    tmp[2] = in[2];
-    tmp[3] = in[3];
-    rijndael_decrypt((RijndaelContext *)context, in, out);
-    out[0] ^= tmp2[0];
-    out[1] ^= tmp2[1];
-    out[2] ^= tmp2[2];
-    out[3] ^= tmp2[3];
-    in += 4;
-    out += 4;
-  }
+SILC_CIPHER_API_SET_KEY(rijndael);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(rijndael);
+SILC_CIPHER_API_CONTEXT_LEN(rijndael);
+SILC_CIPHER_API_ENCRYPT_CBC(rijndael);
+SILC_CIPHER_API_DECRYPT_CBC(rijndael);
 
-  return TRUE;
-}
 
 #endif
index 65bd3cc01c5c9f506a811f45a1496dd9bdfcf6e4..57506141be0a421fa9c6abef3fc96a9061088734 100644 (file)
@@ -20,6 +20,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.4  2000/10/02 18:31:46  priikone
+ *     Added rijndael (AES) to cipher list.
+ *
  * Revision 1.3  2000/09/28 11:28:20  priikone
  *     Changed cipher list order.
  *
@@ -56,6 +59,9 @@ SilcCipherObject silc_cipher_builtin_list[] =
   { "twofish", 16, 16, silc_twofish_set_key, silc_twofish_set_key_with_string,
     silc_twofish_encrypt_cbc, silc_twofish_decrypt_cbc, 
     silc_twofish_context_len },
+  { "rijndael", 16, 16, silc_rijndael_set_key, 
+    silc_rijndael_set_key_with_string, silc_rijndael_encrypt_cbc,
+    silc_rijndael_decrypt_cbc, silc_rijndael_context_len },
   { "rc6", 16, 16, silc_rc6_set_key, silc_rc6_set_key_with_string,
     silc_rc6_encrypt_cbc, silc_rc6_decrypt_cbc, 
     silc_rc6_context_len },