Index: freeswan/klips/net/ipsec/alg/ipsec_alg_3des.c
diff -u /dev/null freeswan/klips/net/ipsec/alg/ipsec_alg_3des.c:1.1.2.3
--- /dev/null	Fri Jul 12 16:03:48 2002
+++ freeswan/klips/net/ipsec/alg/ipsec_alg_3des.c	Tue May 21 13:25:53 2002
@@ -0,0 +1,162 @@
+/*
+ * ipsec_alg 3DES cipher fake stubs: install 3DES ESP under other ESP id
+ * 	just for testing
+ *
+ * Author: JuanJo Ciarlante <jjo-ipsec@mendoza.gov.ar>
+ *
+ * $Id: ipsec_alg_3des.c,v 1.1.2.3 2002/05/21 16:25:53 jjo Exp $
+ * 
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ */
+#include <linux/config.h>
+#include <linux/version.h>
+
+/*	
+ *	special case: ipsec core modular with this static algo inside:
+ *	must avoid MODULE magic for this file
+ */
+#if CONFIG_IPSEC_MODULE && CONFIG_IPSEC_ALG_3DES
+#undef MODULE
+#endif
+
+#include <linux/module.h>
+#include <linux/init.h>
+
+#include <linux/kernel.h> /* printk() */
+#include <linux/errno.h>  /* error codes */
+#include <linux/types.h>  /* size_t */
+#include <linux/string.h>
+
+/* Check if __exit is defined, if not null it */
+#ifndef __exit
+#define __exit
+#endif
+
+#include <linux/socket.h>
+#include <linux/in.h>
+#include "ipsec_param.h"
+#include "ipsec_sa.h"
+#include "ipsec_alg.h"
+#include "../libdes/des.h"
+
+MODULE_AUTHOR("JuanJo Ciarlante <jjo-ipsec@mendoza.gov.ar>");
+static int debug=0;
+MODULE_PARM(debug, "i");
+static int test=0;
+MODULE_PARM(test, "i");
+static int esp_id=0;
+MODULE_PARM(esp_id, "i");
+
+#define ESP_3DES		3
+
+#define ESP_3DES_CBC_BLKLEN	8	/* 64 bit blocks */
+#define ESP_DES_KEY_SZ		8
+#define ESP_3DES_KEY_SZ		8*3 	/* 3DES */
+
+struct des3_eks{
+	des_key_schedule ctx[3];
+};
+static int _3des_set_key(__u8 *key_e, const __u8 * key, int keysize) {
+	des_key_schedule *ctx=((struct des3_eks*)key_e)->ctx;
+	int i, error;
+	if (debug > 0)
+		printk(KERN_DEBUG "klips_debug:" __FUNCTION__ ": "
+				"key_e=%p key=%p keysize=%d\n",
+				key_e, key, keysize);
+	for(i = 0; i < 3; i++) {
+		des_set_odd_parity((des_cblock *)(key+ESP_DES_KEY_SZ * i));
+		error = des_set_key((des_cblock *)(key+ESP_DES_KEY_SZ * i),
+				    ctx[i]);
+		if (debug > 0)
+			printk(KERN_DEBUG "klips_debug:des_set_key:"
+				"ctx[%d]=%p, error=%d \n",
+				i, ctx[i], error);
+		if (error == -1)
+			printk("klips_debug:" __FUNCTION__ ": "
+					"parity error in des key %d/3\n",
+					i + 1);
+		else if (error == -2)
+			printk("klips_debug:" __FUNCTION__ ": "
+					"illegal weak des key %d/3\n", i + 1);
+		if (error)
+			return error;
+	}
+	return 0;
+}
+void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
+		long length, des_key_schedule ks1, des_key_schedule ks2,
+		des_key_schedule ks3, des_cblock *ivec, int enc);
+
+static int _3des_cbc_encrypt(__u8 * key_e, __u8 * in, __u8 * out, int ilen, const __u8 * iv, int encrypt) {
+	char iv_buf[ESP_3DES_CBC_BLKLEN];
+	des_key_schedule *ctx=((struct des3_eks*)key_e)->ctx;
+	*((__u32*)&(iv_buf)) = ((__u32*)(iv))[0];
+	*((__u32*)&(iv_buf)+1) = ((__u32*)(iv))[1];
+	if (debug > 1) {
+		printk(KERN_DEBUG "klips_debug:_3des_cbc_encrypt:"
+				"key_e=%p in=%p out=%p ilen=%d iv=%p encrypt=%d\n",
+				ctx, in, out, ilen, iv, encrypt);
+	}
+	des_ede3_cbc_encrypt((des_cblock*) in, (des_cblock*) out, ilen, ctx[0], ctx[1], ctx[2], (des_cblock *)iv_buf, encrypt);
+	return ilen;
+}
+static int validate_key(struct ipsec_sa *sa_p) {
+	return (sa_p->ips_key_bits_e == (ESP_3DES_KEY_SZ * 8))? 0 : -EINVAL;
+}
+static struct ipsec_alg_enc ipsec_alg_3DES = {
+	ixt_version:	IPSEC_ALG_VERSION,
+	ixt_module:	THIS_MODULE,
+	ixt_refcnt:	ATOMIC_INIT(0),
+	ixt_name: 	"3des",
+	ixt_alg_type:	IPSEC_ALG_TYPE_ENCRYPT,
+	ixt_alg_id: 	ESP_3DES,
+	ixt_blocksize:	ESP_3DES_CBC_BLKLEN,
+	ixt_keyminbits:	ESP_3DES_KEY_SZ*7, /*  7bits key+1bit parity  */
+	ixt_keymaxbits:	ESP_3DES_KEY_SZ*7, /*  7bits key+1bit parity  */
+	ixt_e_keylen:	ESP_3DES_KEY_SZ,
+	ixt_e_ctx_size:	sizeof(struct des3_eks),
+	ixt_e_validate_key: validate_key,
+	ixt_e_set_key:	_3des_set_key,
+	ixt_e_cbc_encrypt:_3des_cbc_encrypt,
+};
+	
+IPSEC_ALG_MODULE_INIT(ipsec_3des_init)
+{
+	int ret, test_ret;
+	if (esp_id)
+		ipsec_alg_3DES.ixt_alg_id=esp_id;
+	ret=register_ipsec_alg_enc(&ipsec_alg_3DES);
+	printk(__FUNCTION__ "(alg_type=%d alg_id=%d name=%s): ret=%d\n", 
+			ipsec_alg_3DES.ixt_alg_type, 
+			ipsec_alg_3DES.ixt_alg_id, 
+			ipsec_alg_3DES.ixt_name, 
+			ret);
+	if (ret==0 && test) {
+		test_ret=ipsec_alg_test(
+				ipsec_alg_3DES.ixt_alg_type,
+				ipsec_alg_3DES.ixt_alg_id, 
+				test);
+		printk(__FUNCTION__ "(alg_type=%d alg_id=%d): test_ret=%d\n", 
+				ipsec_alg_3DES.ixt_alg_type, 
+				ipsec_alg_3DES.ixt_alg_id, 
+				test_ret);
+	}
+	return ret;
+}
+IPSEC_ALG_MODULE_EXIT(ipsec_3des_fini)
+{
+	unregister_ipsec_alg_enc(&ipsec_alg_3DES);
+	return;
+}
+#ifdef MODULE_LICENSE
+MODULE_LICENSE("GPL");
+#endif
Index: freeswan/klips/net/ipsec/alg/Makefile.alg_3des
diff -u /dev/null freeswan/klips/net/ipsec/alg/Makefile.alg_3des:1.1.2.1
--- /dev/null	Fri Jul 12 16:03:48 2002
+++ freeswan/klips/net/ipsec/alg/Makefile.alg_3des	Mon Apr 15 12:13:42 2002
@@ -0,0 +1,16 @@
+MOD_3DES += ipsec_3des.o
+
+ALG_MODULES += $(MOD_3DES)
+ALG_SUBDIRS += libdes
+
+obj-$(CONFIG_IPSEC_ALG_3DES) += $(MOD_3DES)
+static_init-func-$(CONFIG_IPSEC_ALG_3DES)+= ipsec_3des_init
+alg_obj-$(CONFIG_IPSEC_ALG_3DES) += ipsec_alg_3des.o
+
+DES_3DES_OBJS=ipsec_alg_3des.o ../libdes/libdes.a
+
+$(MOD_3DES): $(DES_3DES_OBJS)
+	$(LD) -r $(DES_3DES_OBJS) -o $@
+
+../libdes/libdes.a:
+	$(MAKE) -C .. libdes/libdes.a
Index: freeswan/klips/net/ipsec/alg/Config.alg_3des.in
diff -u /dev/null freeswan/klips/net/ipsec/alg/Config.alg_3des.in:1.1.2.1
--- /dev/null	Fri Jul 12 16:03:48 2002
+++ freeswan/klips/net/ipsec/alg/Config.alg_3des.in	Mon Apr 15 12:13:42 2002
@@ -0,0 +1,3 @@
+if [ "$CONFIG_IPSEC_ALG" = "y" ]; then
+  tristate '        3DES encryption algorithm (modular alg)' CONFIG_IPSEC_ALG_3DES
+fi
--- freeswan/klips/net/ipsec/alg/Config.in	Sun Dec 16 10:24:55 2001
+++ freeswan/klips/net/ipsec/alg/Config.in	Sun Dec 16 10:24:52 2001
@@ -1000,0 +1001 @@
+source net/ipsec/alg/Config.alg_3des.in

