Add, forgotten in last commit.
[gnulib.git] / lib / gc-gnulib.c
index 61bf124..6eff3e3 100644 (file)
 #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
@@ -158,9 +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;
@@ -182,6 +194,19 @@ 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:
@@ -196,6 +221,19 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
       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:
@@ -231,6 +269,12 @@ 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:
@@ -238,6 +282,14 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key)
       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:
@@ -327,6 +379,12 @@ 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:
@@ -334,6 +392,13 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data)
       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:
@@ -363,6 +428,12 @@ 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:
@@ -370,6 +441,13 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data)
       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: