updates. SILC.0.2.1
authorPekka Riikonen <priikone@silcnet.org>
Wed, 2 May 2001 18:50:29 +0000 (18:50 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 2 May 2001 18:50:29 +0000 (18:50 +0000)
15 files changed:
CHANGES
TODO
apps/silc/client_ops.c
apps/silc/clientutil.c
apps/silcd/silcd.c
lib/silccrypt/Makefile.am
lib/silccrypt/aes.h
lib/silccrypt/blowfish.c
lib/silccrypt/blowfish.h
lib/silccrypt/cast.c
lib/silccrypt/cast.h
lib/silccrypt/ciphers.h
lib/silccrypt/rc5.c
lib/silccrypt/rc5.h
lib/silccrypt/rc5_internal.h

diff --git a/CHANGES b/CHANGES
index eabc3f068d8a14cfb8845a2b007fd7de3f766829..9cf38b378bdb6689d9a0de7298053b1bbc1e483f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@ Wed May  2 20:50:49 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
          than the new one.  For now, the client keys are saved with the
          new filename format.  The affected file silc/client_ops.c.
 
          than the new one.  For now, the client keys are saved with the
          new filename format.  The affected file silc/client_ops.c.
 
+       * Implemented the Cipher API for the rest of the ciphers that
+         did not implement it or implemented it the wrong way.
+
 Wed May  2 13:31:26 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Register default ciphers and stuff when using the -S option
 Wed May  2 13:31:26 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Register default ciphers and stuff when using the -S option
diff --git a/TODO b/TODO
index 1dbb0e64718d01d9c09dd71771c5b9b26462e9a4..266b3f52cfc20e674d7a8aa7b61c9c09709fb4fa 100644 (file)
--- a/TODO
+++ b/TODO
@@ -57,8 +57,7 @@ TODO/bugs In SILC Server
 TODO/bugs In SILC Libraries
 ===========================
 
 TODO/bugs In SILC Libraries
 ===========================
 
- o Some of the ciphers in lib/silccrypt does not implement the SILC
-   Crypto API correctly.
+ o IPv6 support for ID's and into the code.
 
  o Compression routines are missing.  The protocol supports packet
    compression thus it must be implemented.  SILC Comp API must be
 
  o Compression routines are missing.  The protocol supports packet
    compression thus it must be implemented.  SILC Comp API must be
@@ -66,7 +65,8 @@ TODO/bugs In SILC Libraries
    not in distribution), but it is not used yet, and it requires some
    tweaking on the Makefiles (we want static lib not shared).
 
    not in distribution), but it is not used yet, and it requires some
    tweaking on the Makefiles (we want static lib not shared).
 
- o IPv6 support for ID's and into the code.
+ o The CAST cipher is not compiled currently due to compilation errors;
+   check those.  Cast is in lib/silccrypt/cast.c.
 
 
 TODO After 1.0
 
 
 TODO After 1.0
index 59079fb453056769486daeea65f23cff6db42290..23c0b7202fee640aafaa3705862865124fdbf714 100644 (file)
@@ -1015,7 +1015,7 @@ int silc_verify_public_key(SilcClient client,
                  "server" : "client");
 
   if (pk_type != SILC_SKE_PK_TYPE_SILC) {
                  "server" : "client");
 
   if (pk_type != SILC_SKE_PK_TYPE_SILC) {
-    silc_say(client, conn, "We don't support %s key type %d", 
+    silc_say(client, conn, "We don't support %s public key type %d", 
             entity, pk_type);
     return FALSE;
   }
             entity, pk_type);
     return FALSE;
   }
@@ -1024,19 +1024,29 @@ int silc_verify_public_key(SilcClient client,
   if (!pw)
     return FALSE;
 
   if (!pw)
     return FALSE;
 
-  /* Replace all whitespaces with `_'. */
-  fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
-  for (i = 0; i < strlen(fingerprint); i++)
-    if (fingerprint[i] == ' ')
-      fingerprint[i] = '_';
-
   memset(filename, 0, sizeof(filename));
   memset(file, 0, sizeof(file));
   memset(filename, 0, sizeof(filename));
   memset(file, 0, sizeof(file));
-  snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
-  snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s", 
-          pw->pw_dir, entity, file);
-  silc_free(fingerprint);
 
 
+  if (conn_type == SILC_SOCKET_TYPE_SERVER ||
+      conn_type == SILC_SOCKET_TYPE_ROUTER) {
+    snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity, 
+            conn->sock->hostname, conn->sock->port);
+    snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s", 
+            pw->pw_dir, entity, file);
+  } else {
+    /* Replace all whitespaces with `_'. */
+    fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
+    for (i = 0; i < strlen(fingerprint); i++)
+      if (fingerprint[i] == ' ')
+       fingerprint[i] = '_';
+    
+    snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
+    snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s", 
+            pw->pw_dir, entity, file);
+    silc_free(fingerprint);
+  }
+
+  /* Take fingerprint of the public key */
   fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
 
   /* Check whether this key already exists */
   fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
 
   /* Check whether this key already exists */
index 95a37422e75a815a0bc0a4d900899f28c3fef5b9..1bcc9c8bc3fde0d889130218400c74f69c6c3ed3 100644 (file)
@@ -357,7 +357,7 @@ New pair of keys will be created.  Please, answer to following questions.\n\
   }
 
   if (!silc_pkcs_is_supported(pkcs_name)) {
   }
 
   if (!silc_pkcs_is_supported(pkcs_name)) {
-    fprintf(stderr, "Unsupported PKCS `%s'", pkcs_name);
+    fprintf(stderr, "Unknown PKCS `%s'", pkcs_name);
     return FALSE;
   }
 
     return FALSE;
   }
 
index 186deb82aa05c197db58ddbe447b2ea8cbf3b4e4..482df6b49e3e5ce36fa2cef06e9acdae0df42c8c 100644 (file)
@@ -138,6 +138,10 @@ int main(int argc, char **argv)
 
   if (opt_create_keypair == TRUE) {
     /* Create new key pair and exit */
 
   if (opt_create_keypair == TRUE) {
     /* Create new key pair and exit */
+    silc_cipher_register_default();
+    silc_pkcs_register_default();
+    silc_hash_register_default();
+    silc_hmac_register_default();
     silc_server_create_key_pair(opt_pkcs, opt_bits, opt_keypath,
                                NULL, NULL, NULL);
     exit(0);
     silc_server_create_key_pair(opt_pkcs, opt_bits, opt_keypath,
                                NULL, NULL, NULL);
     exit(0);
index 933f5e163cca4a93ed4c0ea3d4febef13479a4be..741b1dc05e90369dd66ad26519596de095978ec9 100644 (file)
@@ -22,7 +22,6 @@ noinst_LIBRARIES = libsilccrypt.a
 
 libsilccrypt_a_SOURCES = \
        none.c \
 
 libsilccrypt_a_SOURCES = \
        none.c \
-       blowfish.c \
        rc5.c \
        rc6.c \
        mars.c \
        rc5.c \
        rc6.c \
        mars.c \
index 97d684d2c0817f247cbae4d1205237731c20ab07..d505f90ceb3e322d0b9aaed5457d8e7509f2459c 100644 (file)
   GNU General Public License for more details.
 
 */
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.1  2001/02/26 17:32:08  priikone
- *     updates.
- *
- * 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.
- *
- *
- */
 
 #ifndef RIJNDAEL_H
 #define RIJNDAEL_H
 
 #ifndef RIJNDAEL_H
 #define RIJNDAEL_H
@@ -47,5 +33,4 @@ SILC_CIPHER_API_CONTEXT_LEN(aes);
 SILC_CIPHER_API_ENCRYPT_CBC(aes);
 SILC_CIPHER_API_DECRYPT_CBC(aes);
 
 SILC_CIPHER_API_ENCRYPT_CBC(aes);
 SILC_CIPHER_API_DECRYPT_CBC(aes);
 
-
 #endif
 #endif
index 03d381aece1538f5898555abb41e5e1b1023d12e..cf6fe609400dec5ca0973db6d342cb1188b62abe 100644 (file)
 #include "silcincludes.h"
 #include "blowfish.h"
 
 #include "silcincludes.h"
 #include "blowfish.h"
 
+/* 
+ * SILC Crypto API for Blowfish
+ */
+
+/* Sets the key for the cipher. */
+
+SILC_CIPHER_API_SET_KEY(blowfish)
+{
+  blowfish_set_key((BlowfishContext *)context, (unsigned char *)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(blowfish)
+{
+  /*  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(blowfish)
+{
+  return sizeof(BlowfishContext);
+}
+
+/* Encrypts with the cipher in CBC mode. Source and destination buffers
+   maybe one and same. */
+
+SILC_CIPHER_API_ENCRYPT_CBC(blowfish)
+{
+  uint32 tiv[4];
+  int i;
+
+  SILC_CBC_GET_IV(tiv, iv);
+
+  SILC_CBC_ENC_PRE(tiv, src);
+  blowfish_encrypt((BlowfishContext *)context, tiv, tiv, 16);
+  SILC_CBC_ENC_POST(tiv, dst, src);
+
+  for (i = 16; i < len; i += 16) {
+    SILC_CBC_ENC_PRE(tiv, src);
+    blowfish_encrypt((BlowfishContext *)context, tiv, tiv, 16);
+    SILC_CBC_ENC_POST(tiv, dst, src);
+  }
+
+  SILC_CBC_PUT_IV(tiv, iv);
+
+  return TRUE;
+}
+
+/* Decrypts with the cipher in CBC mode. Source and destination buffers
+   maybe one and same. */
+
+SILC_CIPHER_API_DECRYPT_CBC(blowfish)
+{
+  uint32 tmp[4], tmp2[4], tiv[4];
+  int i;
+
+  SILC_CBC_GET_IV(tiv, iv);
+
+  SILC_CBC_DEC_PRE(tmp, src);
+  blowfish_decrypt((BlowfishContext *)context, tmp, tmp2, 16);
+  SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+
+  for (i = 16; i < len; i += 16) {
+    SILC_CBC_DEC_PRE(tmp, src);
+    blowfish_decrypt((BlowfishContext *)context, tmp, tmp2, 16);
+    SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+  }
+  
+  SILC_CBC_PUT_IV(tiv, iv);
+  
+  return TRUE;
+}
+
 static u32 bf_pbox[16 + 2] =
 {
     0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
 static u32 bf_pbox[16 + 2] =
 {
     0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
index 3bc8a18e820e2870627fdf196a5be126e3b772b8..64634636cae80d9d2a33b55f6678eae5ca39650d 100644 (file)
   GNU General Public License for more details.
 
 */
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.2  2001/04/03 19:54:10  priikone
- *     updates. New data types.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:54  priikone
- *     Importet from internal CVS/Added Log headers.
- *
- *
- */
 
 #ifndef BLOWFISH_H
 #define BLOWFISH_H
 
 #ifndef BLOWFISH_H
 #define BLOWFISH_H
  * SILC Crypto API for Blowfish
  */
 
  * SILC Crypto API for Blowfish
  */
 
-/* Sets the key for the cipher. */
-
-SILC_CIPHER_API_SET_KEY(blowfish)
-{
-  blowfish_set_key((BlowfishContext *)context, 
-                  (unsigned char *)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(blowfish)
-{
-  SilcHash hash;
-  unsigned char key[16];
-
-  silc_hash_alloc("md5", &hash);
-  hash->make_hash(hash, string, stringlen, key);
-
-  blowfish_set_key((BlowfishContext *)context, key, sizeof(key));
-
-  silc_hash_free(hash);
-  memset(&key, 'F', sizeof(key));
-  
-  return TRUE;
-}
-
-/* Returns the size of the cipher context. */
-
-SILC_CIPHER_API_CONTEXT_LEN(blowfish)
-{
-  return sizeof(BlowfishContext);
-}
-
-/* Encrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_ENCRYPT_CBC(blowfish)
-{
-  uint32 *in, *out, *tiv;
-  uint32 tmp[4];
-  int i;
-
-  in = (uint32 *)src;
-  out = (uint32 *)dst;
-  tiv = (uint32 *)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];
-  blowfish_encrypt((BlowfishContext *)context, tmp, out, 16);
-  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];
-    blowfish_encrypt((BlowfishContext *)context, tmp, out, 16);
-    in += 4;
-    out += 4;
-  }
-
-  return 1;
-}
-
-/* Decrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_DECRYPT_CBC(blowfish)
-{
-  uint32 *in, *out, *tiv;
-  int i;
-
-  in = (uint32 *)src;
-  out = (uint32 *)dst;
-  tiv = (uint32 *)iv;
-
-  blowfish_decrypt((BlowfishContext *)context, in, out, 16);
-  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) {
-    blowfish_decrypt((BlowfishContext *)context, in, out, 16);
-    out[0] ^= in[0 - 4];
-    out[1] ^= in[1 - 4];
-    out[2] ^= in[2 - 4];
-    out[3] ^= in[3 - 4];
-    in += 4;
-    out += 4;
-  }
-
-  return 1;
-}
+SILC_CIPHER_API_SET_KEY(blowfish);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(blowfish);
+SILC_CIPHER_API_CONTEXT_LEN(blowfish);
+SILC_CIPHER_API_ENCRYPT_CBC(blowfish);
+SILC_CIPHER_API_DECRYPT_CBC(blowfish);
 
 #endif
 
 #endif
index 1f066dfffaabf9c7cb33933e550df4506046af28..565159ccda1c25651f7d07ab15b84c0b4787e1e7 100644 (file)
@@ -60,7 +60,98 @@ Mean:          674 cycles =    38.0 mbits/sec
 \r
 #include "silcincludes.h"\r
 #include "cast.h"\r
 \r
 #include "silcincludes.h"\r
 #include "cast.h"\r
+\r
+#define io_swap\r
     \r
     \r
+/* \r
+ * SILC Crypto API for Cast-256\r
+ */\r
+\r
+/* Sets the key for the cipher. */\r
+\r
+SILC_CIPHER_API_SET_KEY(cast)\r
+{\r
+  uint32 k[8];\r
+\r
+  SILC_GET_WORD_KEY(key, k, keylen);\r
+  cast_set_key((CastContext *)context, k, keylen);\r
+\r
+  return TRUE;\r
+}\r
+\r
+/* Sets the string as a new key for the cipher. The string is first\r
+   hashed and then used as a new key. */\r
+\r
+SILC_CIPHER_API_SET_KEY_WITH_STRING(cast)\r
+{\r
+  /*  unsigned char key[md5_hash_len];\r
+  SilcMarsContext *ctx = (SilcMarsContext *)context;\r
+\r
+  make_md5_hash(string, &key);\r
+  memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);\r
+  memset(&key, 'F', sizeoof(key));\r
+  */\r
+\r
+  return 1;\r
+}\r
+\r
+/* Returns the size of the cipher context. */\r
+\r
+SILC_CIPHER_API_CONTEXT_LEN(cast)\r
+{\r
+  return sizeof(CastContext);\r
+}\r
+\r
+/* Encrypts with the cipher in CBC mode. Source and destination buffers\r
+   maybe one and same. */\r
+\r
+SILC_CIPHER_API_ENCRYPT_CBC(cast)\r
+{\r
+  uint32 tiv[4];\r
+  int i;\r
+\r
+  SILC_CBC_GET_IV(tiv, iv);\r
+\r
+  SILC_CBC_ENC_PRE(tiv, src);\r
+  cast_encrypt((CastContext *)context, tiv, tiv);\r
+  SILC_CBC_ENC_POST(tiv, dst, src);\r
+\r
+  for (i = 16; i < len; i += 16) {\r
+    SILC_CBC_ENC_PRE(tiv, src);\r
+    cast_encrypt((CastContext *)context, tiv, tiv);\r
+    SILC_CBC_ENC_POST(tiv, dst, src);\r
+  }\r
+\r
+  SILC_CBC_PUT_IV(tiv, iv);\r
+\r
+  return TRUE;\r
+}\r
+\r
+/* Decrypts with the cipher in CBC mode. Source and destination buffers\r
+   maybe one and same. */\r
+\r
+SILC_CIPHER_API_DECRYPT_CBC(cast)\r
+{\r
+  uint32 tmp[4], tmp2[4], tiv[4];\r
+  int i;\r
+\r
+  SILC_CBC_GET_IV(tiv, iv);\r
+\r
+  SILC_CBC_DEC_PRE(tmp, src);\r
+  cast_decrypt((CastContext *)context, tmp, tmp2);\r
+  SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);\r
+\r
+  for (i = 16; i < len; i += 16) {\r
+    SILC_CBC_DEC_PRE(tmp, src);\r
+    cast_decrypt((CastContext *)context, tmp, tmp2); \r
+    SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);\r
+  }\r
+  \r
+  SILC_CBC_PUT_IV(tiv, iv);\r
+  \r
+  return TRUE;\r
+}\r
+\r
 u4byte s_box[4][256] = \r
 { {\r
     0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9C004dd3, \r
 u4byte s_box[4][256] = \r
 { {\r
     0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9C004dd3, \r
@@ -244,50 +335,50 @@ u4byte s_box[4][256] =
   }\r
 };\r
 \r
   }\r
 };\r
 \r
-#define f1(y,x,kr,km)           \\r
-    t  = rotl(km + x, kr);      \\r
-    u  = s_box[0][byte(t,3)];   \\r
-    u ^= s_box[1][byte(t,2)];   \\r
-    u -= s_box[2][byte(t,1)];   \\r
-    u += s_box[3][byte(t,0)];   \\r
+#define f1(y,x,kr,km)                          \\r
+    t  = rotl(km + x, kr);                     \\r
+    u  = s_box[0][byte(t,3)];                  \\r
+    u ^= s_box[1][byte(t,2)];                  \\r
+    u -= s_box[2][byte(t,1)];                  \\r
+    u += s_box[3][byte(t,0)];                  \\r
     y ^= u\r
 \r
     y ^= u\r
 \r
-#define f2(y,x,kr,km)           \\r
-    t  = rotl(km ^ x, kr);      \\r
-    u  = s_box[0][byte(t,3)];   \\r
-    u -= s_box[1][byte(t,2)];   \\r
-    u += s_box[2][byte(t,1)];   \\r
-    u ^= s_box[3][byte(t,0)];   \\r
+#define f2(y,x,kr,km)                          \\r
+    t  = rotl(km ^ x, kr);                     \\r
+    u  = s_box[0][byte(t,3)];                  \\r
+    u -= s_box[1][byte(t,2)];                  \\r
+    u += s_box[2][byte(t,1)];                  \\r
+    u ^= s_box[3][byte(t,0)];                  \\r
     y ^= u\r
 \r
     y ^= u\r
 \r
-#define f3(y,x,kr,km)           \\r
-    t  = rotl(km - x, kr);      \\r
-    u  = s_box[0][byte(t,3)];   \\r
-    u += s_box[1][byte(t,2)];   \\r
-    u ^= s_box[2][byte(t,1)];   \\r
-    u -= s_box[3][byte(t,0)];   \\r
+#define f3(y,x,kr,km)                          \\r
+    t  = rotl(km - x, kr);                     \\r
+    u  = s_box[0][byte(t,3)];                  \\r
+    u += s_box[1][byte(t,2)];                  \\r
+    u ^= s_box[2][byte(t,1)];                  \\r
+    u -= s_box[3][byte(t,0)];                  \\r
     y ^= u\r
 \r
     y ^= u\r
 \r
-#define f_rnd(x,n)                              \\r
-    f1(x[2],x[3],l_key[n],    l_key[n + 4]);    \\r
-    f2(x[1],x[2],l_key[n + 1],l_key[n + 5]);    \\r
-    f3(x[0],x[1],l_key[n + 2],l_key[n + 6]);    \\r
+#define f_rnd(x,n)                             \\r
+    f1(x[2],x[3],l_key[n],    l_key[n + 4]);   \\r
+    f2(x[1],x[2],l_key[n + 1],l_key[n + 5]);   \\r
+    f3(x[0],x[1],l_key[n + 2],l_key[n + 6]);   \\r
     f1(x[3],x[0],l_key[n + 3],l_key[n + 7])\r
 \r
     f1(x[3],x[0],l_key[n + 3],l_key[n + 7])\r
 \r
-#define i_rnd(x, n)                             \\r
-    f1(x[3],x[0],l_key[n + 3],l_key[n + 7]);    \\r
-    f3(x[0],x[1],l_key[n + 2],l_key[n + 6]);    \\r
-    f2(x[1],x[2],l_key[n + 1],l_key[n + 5]);    \\r
+#define i_rnd(x, n)                            \\r
+    f1(x[3],x[0],l_key[n + 3],l_key[n + 7]);   \\r
+    f3(x[0],x[1],l_key[n + 2],l_key[n + 6]);   \\r
+    f2(x[1],x[2],l_key[n + 1],l_key[n + 5]);   \\r
     f1(x[2],x[3],l_key[n],    l_key[n + 4])\r
 \r
     f1(x[2],x[3],l_key[n],    l_key[n + 4])\r
 \r
-#define k_rnd(k,tr,tm)          \\r
-    f1(k[6],k[7],tr[0],tm[0]);  \\r
-    f2(k[5],k[6],tr[1],tm[1]);  \\r
-    f3(k[4],k[5],tr[2],tm[2]);  \\r
-    f1(k[3],k[4],tr[3],tm[3]);  \\r
-    f2(k[2],k[3],tr[4],tm[4]);  \\r
-    f3(k[1],k[2],tr[5],tm[5]);  \\r
-    f1(k[0],k[1],tr[6],tm[6]);  \\r
+#define k_rnd(k,tr,tm)                         \\r
+    f1(k[6],k[7],tr[0],tm[0]);                 \\r
+    f2(k[5],k[6],tr[1],tm[1]);                 \\r
+    f3(k[4],k[5],tr[2],tm[2]);                 \\r
+    f1(k[3],k[4],tr[3],tm[3]);                 \\r
+    f2(k[2],k[3],tr[4],tm[4]);                 \\r
+    f3(k[1],k[2],tr[5],tm[5]);                 \\r
+    f1(k[0],k[1],tr[6],tm[6]);                 \\r
     f2(k[7],k[0],tr[7],tm[7])\r
 \r
 /* initialise the key schedule from the user supplied key   */\r
     f2(k[7],k[0],tr[7],tm[7])\r
 \r
 /* initialise the key schedule from the user supplied key   */\r
@@ -333,7 +424,7 @@ u4byte *cast_set_key(CastContext *ctx,
     }\r
 \r
     return l_key;\r
     }\r
 \r
     return l_key;\r
-};\r
+}\r
 \r
 /* encrypt a block of text  */\r
 \r
 \r
 /* encrypt a block of text  */\r
 \r
@@ -355,7 +446,7 @@ void cast_encrypt(CastContext *ctx,
 \r
     out_blk[0] = io_swap(blk[0]); out_blk[1] = io_swap(blk[1]);\r
     out_blk[2] = io_swap(blk[2]); out_blk[3] = io_swap(blk[3]);\r
 \r
     out_blk[0] = io_swap(blk[0]); out_blk[1] = io_swap(blk[1]);\r
     out_blk[2] = io_swap(blk[2]); out_blk[3] = io_swap(blk[3]);\r
-};\r
+}\r
 \r
 /* decrypt a block of text  */\r
 \r
 \r
 /* decrypt a block of text  */\r
 \r
@@ -377,5 +468,4 @@ void cast_decrypt(CastContext *ctx,
 \r
     out_blk[0] = io_swap(blk[0]); out_blk[1] = io_swap(blk[1]);\r
     out_blk[2] = io_swap(blk[2]); out_blk[3] = io_swap(blk[3]);\r
 \r
     out_blk[0] = io_swap(blk[0]); out_blk[1] = io_swap(blk[1]);\r
     out_blk[2] = io_swap(blk[2]); out_blk[3] = io_swap(blk[3]);\r
-};\r
-\r
+}\r
index d7533d5f8b225b91a34faf0c1364960c84161b42..9f36139520f642f096d3a92e63e86325a065cee8 100644 (file)
   GNU General Public License for more details.
 
 */
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.2  2001/04/03 19:54:10  priikone
- *     updates. New data types.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:54  priikone
- *     Importet from internal CVS/Added Log headers.
- *
- *
- */
 
 #ifndef CAST_H
 #define CAST_H
 
 #ifndef CAST_H
 #define CAST_H
 #include "cast_internal.h"
 
 /* 
 #include "cast_internal.h"
 
 /* 
- * SILC Crypto API for Cast
+ * SILC Crypto API for Cast-256
  */
 
  */
 
-/* Sets the key for the cipher. */
-
-inline int silc_cast_init(void *context, 
-                         const unsigned char *key, 
-                         uint32 keylen)
-{
-  cast_set_key((CastContext *)context, (uint32 *)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. */
-
-inline int silc_cast_set_string_as_key(void *context, 
-                                      const unsigned char *string,
-                                      uint32 stringlen)
-{
-  /*  SilcHash hash;
-  unsigned char key[16];
-
-  silc_hash_alloc("md5", &hash);
-  hash->make_hash(hash, string, stringlen, key);
-
-  cast_set_key((CastContext *)context, (const u4byte *)key, sizeof(key));
-
-  silc_hash_free(hash);
-  memset(&key, 'F', sizeof(key));
-  */
-  return TRUE;
-}
-
-/* Returns the size of the cipher context. */
-
-inline uint32 silc_cast_context_len()
-{
-  return sizeof(CastContext);
-}
-
-/* Encrypts with the cipher in CBC mode. */
-
-inline int silc_cast_encrypt_cbc(void *context,
-                                const unsigned char *src,
-                                unsigned char *dst,
-                                uint32 len,
-                                unsigned char *iv)
-{
-  uint32 *in, *out, *tiv;
-  uint32 tmp[4];
-  int i;
-
-  in = (uint32 *)src;
-  out = (uint32 *)dst;
-  tiv = (uint32 *)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];
-  cast_encrypt((CastContext *)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];
-    cast_encrypt((CastContext *)context, tmp, out);
-    in += 4;
-    out += 4;
-  }
-
-  return 1;
-}
-
-/* Decrypts with the cipher in CBC mode. */
-
-inline int silc_cast_decrypt_cbc(void *context,
-                                const unsigned char *src,
-                                unsigned char *dst,
-                                uint32 len,
-                                unsigned char *iv)
-{
-  uint32 *in, *out, *tiv;
-  int i;
-
-  in = (uint32 *)src;
-  out = (uint32 *)dst;
-  tiv = (uint32 *)iv;
-
-  cast_decrypt((CastContext *)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) {
-    cast_decrypt((CastContext *)context, in, out);
-    out[0] ^= in[0 - 4];
-    out[1] ^= in[1 - 4];
-    out[2] ^= in[2 - 4];
-    out[3] ^= in[3 - 4];
-    in += 4;
-    out += 4;
-  }
-
-  return 1;
-}
+SILC_CIPHER_API_SET_KEY(cast);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(cast);
+SILC_CIPHER_API_CONTEXT_LEN(cast);
+SILC_CIPHER_API_ENCRYPT_CBC(cast);
+SILC_CIPHER_API_DECRYPT_CBC(cast);
 
 #endif
 
 #endif
index e13aa5f70b40ca6ce34f936b2a89599143ea9f45..196995de86ad7de601319573f1c1d8b8a014f4d9 100644 (file)
 
 #include "none.h"
 #include "mars.h"
 
 #include "none.h"
 #include "mars.h"
+#include "rc5.h"
 #include "rc6.h"
 #include "twofish.h"
 #include "aes.h"
 #include "rc6.h"
 #include "twofish.h"
 #include "aes.h"
+#include "blowfish.h"
 
 #endif
 
 #endif
index c0db8e950cbc57218ce3a888f5852fefa6d1908c..f74dfd377d9780bdd8ce0362affbecc0b4974fce 100644 (file)
 #include "silcincludes.h"
 #include "rc5.h"
 
 #include "silcincludes.h"
 #include "rc5.h"
 
+/* 
+ * SILC Crypto API for RC5
+ */
+
+/* Sets the key for the cipher. */
+
+SILC_CIPHER_API_SET_KEY(aes)
+{
+  uint32 k[8];
+
+  SILC_GET_WORD_KEY(key, k, keylen);
+  rc5_set_key((RC5Context *)context, k, 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(aes)
+{
+  /*  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(aes)
+{
+  return sizeof(RC5Context);
+}
+
+/* Encrypts with the cipher in CBC mode. Source and destination buffers
+   maybe one and same. */
+
+SILC_CIPHER_API_ENCRYPT_CBC(aes)
+{
+  uint32 tiv[4];
+  int i;
+
+  SILC_CBC_GET_IV(tiv, iv);
+
+  SILC_CBC_ENC_PRE(tiv, src);
+  rc5_encrypt((RC5Context *)context, tiv, tiv);
+  SILC_CBC_ENC_POST(tiv, dst, src);
+
+  for (i = 16; i < len; i += 16) {
+    SILC_CBC_ENC_PRE(tiv, src);
+    rc5_encrypt((RC5Context *)context, tiv, tiv);
+    SILC_CBC_ENC_POST(tiv, dst, src);
+  }
+
+  SILC_CBC_PUT_IV(tiv, iv);
+
+  return TRUE;
+}
+
+/* Decrypts with the cipher in CBC mode. Source and destination buffers
+   maybe one and same. */
+
+SILC_CIPHER_API_DECRYPT_CBC(aes)
+{
+  uint32 tmp[4], tmp2[4], tiv[4];
+  int i;
+
+  SILC_CBC_GET_IV(tiv, iv);
+
+  SILC_CBC_DEC_PRE(tmp, src);
+  rc5_decrypt((RC5Context *)context, tmp, tmp2);
+  SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+
+  for (i = 16; i < len; i += 16) {
+    SILC_CBC_DEC_PRE(tmp, src);
+    rc5_decrypt((RC5Context *)context, tmp, tmp2); 
+    SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+  }
+  
+  SILC_CBC_PUT_IV(tiv, iv);
+  
+  return TRUE;
+}
+
 /* RC5 encryption */
 #define RC5E(i, A, B)                          \
                A = A ^ B;                      \
 /* RC5 encryption */
 #define RC5E(i, A, B)                          \
                A = A ^ B;                      \
 
 /* Sets RC5 key */
 
 
 /* Sets RC5 key */
 
-int rc5_set_key(RC5Context *ctx, char *key, int key_len)
+int rc5_set_key(RC5Context *ctx, const uint32 in_key[], int key_len)
 {
 {
-       u32 *in_key = (u32 *)key;
        u32 i, j, k, A, B, L[c];
        u32 *out_key = ctx->out_key;
 
        if (key_len < b || key_len > (2 * b))
                return -1;
 
        u32 i, j, k, A, B, L[c];
        u32 *out_key = ctx->out_key;
 
        if (key_len < b || key_len > (2 * b))
                return -1;
 
-       //      key_len *= 8;
-
        /* init L */
        for (i = 0; i < key_len / w; i++)
                L[i] = in_key[i];
        /* init L */
        for (i = 0; i < key_len / w; i++)
                L[i] = in_key[i];
index d4dcebebd016091c33bbc1be5065e19c1d4baaea..b8f024166f43faf8b5ddb37ac48145b5e6be3692 100644 (file)
   GNU General Public License for more details.
 
 */
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.2  2001/04/03 19:54:10  priikone
- *     updates. New data types.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:54  priikone
- *     Importet from internal CVS/Added Log headers.
- *
- *
- */
 
 #ifndef RC5_H
 #define RC5_H
 
 #ifndef RC5_H
 #define RC5_H
  * SILC Crypto API for RC5
  */
 
  * SILC Crypto API for RC5
  */
 
-/* Sets the key for the cipher. */
-
-SILC_CIPHER_API_SET_KEY(rc5)
-{
-  rc5_set_key((RC5Context *)context, (unsigned char *)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(rc5)
-{
-  /*  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(rc5)
-{
-  return sizeof(RC5Context);
-}
-
-/* Encrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_ENCRYPT_CBC(rc5)
-{
-  uint32 *in, *out, *tiv;
-  uint32 tmp[2];
-  int i;
-
-  in = (uint32 *)src;
-  out = (uint32 *)dst;
-  tiv = (uint32 *)iv;
-
-  tmp[0] = in[0] ^ tiv[0];
-  tmp[1] = in[1] ^ tiv[1];
-  rc5_encrypt((RC5Context *)context, tmp, out);
-  in += 2;
-  out += 2;
-
-  for (i = 8; i < len; i += 8) {
-    tmp[0] = in[0] ^ out[0 - 2];
-    tmp[1] = in[1] ^ out[1 - 2];
-    rc5_encrypt((RC5Context *)context, tmp, out);
-    in += 2;
-    out += 2;
-  }
-
-  return TRUE;
-}
-
-/* Decrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_DECRYPT_CBC(rc5)
-{
-  uint32 *in, *out, *tiv;
-  uint32 tmp[2], tmp2[2];
-  int i;
-
-  in = (uint32 *)src;
-  out = (uint32 *)dst;
-  tiv = (uint32 *)iv;
-
-  tmp[0] = in[0];
-  tmp[1] = in[1];
-  tmp[3] = in[3];
-  rc5_decrypt((RC5Context *)context, in, out);
-  out[0] ^= tiv[0];
-  out[1] ^= tiv[1];
-  in += 2;
-  out += 2;
-
-  for (i = 8; i < len; i += 8) {
-    tmp2[0] = tmp[0];
-    tmp2[1] = tmp[1];
-    tmp[0] = in[0];
-    tmp[1] = in[1];
-    rc5_decrypt((RC5Context *)context, in, out);
-    out[0] ^= tmp2[0];
-    out[1] ^= tmp2[1];
-    in += 2;
-    out += 2;
-  }
-
-  return TRUE;
-}
+SILC_CIPHER_API_SET_KEY(rc5);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(rc5);
+SILC_CIPHER_API_CONTEXT_LEN(rc5);
+SILC_CIPHER_API_ENCRYPT_CBC(rc5);
+SILC_CIPHER_API_DECRYPT_CBC(rc5);
 
 #endif
 
 #endif
index 940056700a060d5636fbba32a1b2612ef2912202..c493fdc519d8160664b1269238d11887db7e9e69 100644 (file)
@@ -36,7 +36,7 @@ typedef struct {
 } RC5Context;
 
 /* Prototypes */
 } RC5Context;
 
 /* Prototypes */
-int rc5_set_key(RC5Context *ctx, char *key, int key_len);
+int rc5_set_key(RC5Context *ctx, const uint32 in_key[], int key_len);
 int rc5_encrypt(RC5Context *ctx, u32 *in, u32 *out);
 int rc5_decrypt(RC5Context *ctx, u32 *in, u32 *out);
 
 int rc5_encrypt(RC5Context *ctx, u32 *in, u32 *out);
 int rc5_decrypt(RC5Context *ctx, u32 *in, u32 *out);