Add, forgotten in last commit.
[gnulib.git] / lib / gc-gnulib.c
index 3e75529..6eff3e3 100644 (file)
@@ -37,6 +37,7 @@
 #include <fcntl.h>
 #include <errno.h>
 
+/* Hashes. */
 #ifdef GC_USE_MD4
 # include "md4.h"
 #endif
 #ifdef GC_USE_HMAC_MD5
 # include "hmac.h"
 #endif
+
+/* Ciphers. */
+#ifdef GC_USE_ARCFOUR
+# include "arcfour.h"
+#endif
+#ifdef GC_USE_ARCTWO
+# include "arctwo.h"
+#endif
+#ifdef GC_USE_DES
+# include "des.h"
+#endif
 #ifdef GC_USE_RIJNDAEL
 # include "rijndael-api-fst.h"
 #endif
@@ -152,6 +164,15 @@ gc_set_allocators (gc_malloc_t func_malloc,
 typedef struct _gc_cipher_ctx {
   Gc_cipher alg;
   Gc_cipher_mode mode;
+#ifdef GC_USE_ARCTWO
+  arctwo_context arctwoContext;
+#endif
+#ifdef GC_USE_ARCFOUR
+  arcfour_context arcfourContext;
+#endif
+#ifdef GC_USE_DES
+  des_ctx desContext;
+#endif
 #ifdef GC_USE_RIJNDAEL
   rijndaelKeyInstance aesEncKey;
   rijndaelKeyInstance aesDecKey;
@@ -173,6 +194,46 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
 
   switch (alg)
     {
+#ifdef GC_USE_ARCTWO
+    case GC_ARCTWO40:
+      switch (mode)
+       {
+       case GC_ECB:
+         break;
+
+       default:
+         rc = GC_INVALID_CIPHER;
+       }
+      break;
+#endif
+
+#ifdef GC_USE_ARCFOUR
+    case GC_ARCFOUR128:
+    case GC_ARCFOUR40:
+      switch (mode)
+       {
+       case GC_STREAM:
+         break;
+
+       default:
+         rc = GC_INVALID_CIPHER;
+       }
+      break;
+#endif
+
+#ifdef GC_USE_DES
+    case GC_DES:
+      switch (mode)
+       {
+       case GC_ECB:
+         break;
+
+       default:
+         rc = GC_INVALID_CIPHER;
+       }
+      break;
+#endif
+
 #ifdef GC_USE_RIJNDAEL
     case GC_AES128:
     case GC_AES192:
@@ -208,6 +269,27 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
 
   switch (ctx->alg)
     {
+#ifdef GC_USE_ARCTWO
+    case GC_ARCTWO40:
+      arctwo_setkey (&ctx->arctwoContext, keylen, key);
+      break;
+#endif
+
+#ifdef GC_USE_ARCFOUR
+    case GC_ARCFOUR128:
+    case GC_ARCFOUR40:
+      arcfour_setkey (&ctx->arcfourContext, key, keylen);
+      break;
+#endif
+
+#ifdef GC_USE_DES
+    case GC_DES:
+      if (keylen != 8)
+       return GC_INVALID_CIPHER;
+      des_setkey (&ctx->desContext, key);
+      break;
+#endif
+
 #ifdef GC_USE_RIJNDAEL
     case GC_AES128:
     case GC_AES192:
@@ -297,6 +379,26 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
 
   switch (ctx->alg)
     {
+#ifdef GC_USE_ARCTWO
+    case GC_ARCTWO40:
+      arctwo_encrypt (&ctx->arctwoContext, data, data, len);
+      break;
+#endif
+
+#ifdef GC_USE_ARCFOUR
+    case GC_ARCFOUR128:
+    case GC_ARCFOUR40:
+      arcfour_stream (&ctx->arcfourContext, data, data, len);
+      break;
+#endif
+
+#ifdef GC_USE_DES
+    case GC_DES:
+      for (; len >= 8; len -= 8, data += 8)
+       des_ecb_encrypt (&ctx->desContext, data, data);
+      break;
+#endif
+
 #ifdef GC_USE_RIJNDAEL
     case GC_AES128:
     case GC_AES192:
@@ -326,6 +428,26 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
 
   switch (ctx->alg)
     {
+#ifdef GC_USE_ARCTWO
+    case GC_ARCTWO40:
+      arctwo_decrypt (&ctx->arctwoContext, data, data, len);
+      break;
+#endif
+
+#ifdef GC_USE_ARCFOUR
+    case GC_ARCFOUR128:
+    case GC_ARCFOUR40:
+      arcfour_stream (&ctx->arcfourContext, data, data, len);
+      break;
+#endif
+
+#ifdef GC_USE_DES
+    case GC_DES:
+      for (; len >= 8; len -= 8, data += 8)
+       des_ecb_decrypt (&ctx->desContext, data, data);
+      break;
+#endif
+
 #ifdef GC_USE_RIJNDAEL
     case GC_AES128:
     case GC_AES192: