diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-06-18 07:24:09 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-06-18 07:24:09 +0000 |
commit | 27670852d7f539c2c48b7401eaac9979ef268e66 (patch) | |
tree | 313caa17a8d6d6dd9f9e2689ba8a792a280a96ae | |
parent | 4eb4c3013da3dbbfb59cfd7718f9161ba458451b (diff) |
split out transforms; some debugging done but there may still be bugs in
the new key init/zero functions
-rw-r--r-- | sys/conf/files | 3 | ||||
-rw-r--r-- | sys/netinet/ip_esp_new.c | 251 | ||||
-rw-r--r-- | sys/netinet/ip_esp_old.c | 102 | ||||
-rw-r--r-- | sys/netinet/ip_ipsp.h | 4 | ||||
-rw-r--r-- | sys/netinet/ip_xform.c | 323 |
5 files changed, 376 insertions, 307 deletions
diff --git a/sys/conf/files b/sys/conf/files index 23cbc85d874..7b029c2ce05 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.116 1999/04/30 01:58:59 art Exp $ +# $OpenBSD: files,v 1.117 1999/06/18 07:23:57 deraadt Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -451,6 +451,7 @@ file netinet/ip_ipsp.c inet & ipsec file netinet/ip_ip4.c inet & (ipsec | mrouting) file netinet/ip_ah.c inet & ipsec file netinet/ip_esp.c inet & ipsec +file netinet/ip_xform.c inet & ipsec file netinet/ip_esp_old.c inet & ipsec file netinet/ip_esp_new.c inet & ipsec file netinet/ip_ah_old.c inet & ipsec diff --git a/sys/netinet/ip_esp_new.c b/sys/netinet/ip_esp_new.c index 8bad035922e..cc0a46e31e0 100644 --- a/sys/netinet/ip_esp_new.c +++ b/sys/netinet/ip_esp_new.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_esp_new.c,v 1.43 1999/05/16 21:48:35 niklas Exp $ */ +/* $OpenBSD: ip_esp_new.c,v 1.44 1999/06/18 07:24:03 deraadt Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), @@ -77,139 +77,29 @@ #define DPRINTF(x) #endif -extern void des_ecb3_encrypt(caddr_t, caddr_t, caddr_t, caddr_t, caddr_t, int); -extern void des_ecb_encrypt(caddr_t, caddr_t, caddr_t, int); -extern void des_set_key(caddr_t, caddr_t); - -static void des1_encrypt(struct tdb *, u_int8_t *); -static void des3_encrypt(struct tdb *, u_int8_t *); -static void blf_encrypt(struct tdb *, u_int8_t *); -static void cast5_encrypt(struct tdb *, u_int8_t *); -static void skipjack_encrypt(struct tdb *, u_int8_t *); -static void des1_decrypt(struct tdb *, u_int8_t *); -static void des3_decrypt(struct tdb *, u_int8_t *); -static void blf_decrypt(struct tdb *, u_int8_t *); -static void cast5_decrypt(struct tdb *, u_int8_t *); -static void skipjack_decrypt(struct tdb *, u_int8_t *); - -struct auth_hash esp_new_hash[] = { - { SADB_AALG_MD5HMAC96, "HMAC-MD5-96", - MD5HMAC96_KEYSIZE, AH_MD5_ALEN, - sizeof(MD5_CTX), - (void (*) (void *)) MD5Init, - (void (*) (void *, u_int8_t *, u_int16_t)) MD5Update, - (void (*) (u_int8_t *, void *)) MD5Final - }, - { SADB_AALG_SHA1HMAC96, "HMAC-SHA1-96", - SHA1HMAC96_KEYSIZE, AH_SHA1_ALEN, - sizeof(SHA1_CTX), - (void (*) (void *)) SHA1Init, - (void (*) (void *, u_int8_t *, u_int16_t)) SHA1Update, - (void (*) (u_int8_t *, void *)) SHA1Final - }, - { SADB_AALG_X_RIPEMD160HMAC96, "HMAC-RIPEMD-160-96", - RIPEMD160HMAC96_KEYSIZE, AH_RMD160_ALEN, - sizeof(RMD160_CTX), - (void (*)(void *)) RMD160Init, - (void (*)(void *, u_int8_t *, u_int16_t)) RMD160Update, - (void (*)(u_int8_t *, void *)) RMD160Final - } -}; +extern struct auth_hash auth_hash_hmac_md5_96; +extern struct auth_hash auth_hash_hmac_sha1_96; +extern struct auth_hash auth_hash_hmac_ripemd_160_96; -struct enc_xform esp_new_xform[] = { - { SADB_EALG_DESCBC, "Data Encryption Standard (DES)", - ESP_DES_BLKS, ESP_DES_IVS, - 8, 8, 8, - des1_encrypt, - des1_decrypt - }, - { SADB_EALG_3DESCBC, "Triple DES (3DES)", - ESP_3DES_BLKS, ESP_3DES_IVS, - 24, 24, 8, - des3_encrypt, - des3_decrypt - }, - { SADB_EALG_X_BLF, "Blowfish", - ESP_BLF_BLKS, ESP_BLF_IVS, - 5, BLF_MAXKEYLEN, 8, - blf_encrypt, - blf_decrypt - }, - { SADB_EALG_X_CAST, "CAST", - ESP_CAST_BLKS, ESP_CAST_IVS, - 5, 16, 8, - cast5_encrypt, - cast5_decrypt - }, - { SADB_EALG_X_SKIPJACK, "Skipjack", - ESP_SKIPJACK_BLKS, ESP_SKIPJACK_IVS, - 10, 10, 8, - skipjack_encrypt, - skipjack_decrypt - } +struct auth_hash *esp_new_hash[] = { + &auth_hash_hmac_md5_96, + &auth_hash_hmac_sha1_96, + &auth_hash_hmac_ripemd_160_96 }; -static void -des1_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb_encrypt(blk, blk, tdb->tdb_key, 1); -} - -static void -des1_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb_encrypt(blk, blk, tdb->tdb_key, 0); -} - -static void -des3_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb3_encrypt(blk, blk, tdb->tdb_key, tdb->tdb_key + 128, - tdb->tdb_key + 256, 1); -} - -static void -des3_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb3_encrypt(blk, blk, tdb->tdb_key + 256, tdb->tdb_key + 128, - tdb->tdb_key, 0); -} - -static void -blf_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - blf_ecb_encrypt((blf_ctx *) tdb->tdb_key, blk, 8); -} - -static void -blf_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - blf_ecb_decrypt((blf_ctx *) tdb->tdb_key, blk, 8); -} - -static void -cast5_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - cast_encrypt((cast_key *) tdb->tdb_key, blk, blk); -} - -static void -cast5_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - cast_decrypt((cast_key *) tdb->tdb_key, blk, blk); -} - -static void -skipjack_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - skipjack_forwards(blk, blk, (u_int8_t **) tdb->tdb_key); -} - -static void -skipjack_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - skipjack_backwards(blk, blk, (u_int8_t **) tdb->tdb_key); -} +extern struct enc_xform enc_xform_des; +extern struct enc_xform enc_xform_3des; +extern struct enc_xform enc_xform_blf; +extern struct enc_xform enc_xform_cast5; +extern struct enc_xform enc_xform_skipjack; + +struct enc_xform *esp_new_xform[] = { + &enc_xform_des, + &enc_xform_3des, + &enc_xform_blf, + &enc_xform_cast5, + &enc_xform_skipjack, +}; /* * esp_new_attach() is called from the transformation initialization code. @@ -233,9 +123,9 @@ esp_new_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) int i; /* Check whether the encryption algorithm is supported */ - for (i = sizeof(esp_new_xform) / sizeof(struct enc_xform) - 1; + for (i = sizeof(esp_new_xform) / sizeof(esp_new_xform[0]) - 1; i >= 0; i--) - if (ii->ii_encalg == esp_new_xform[i].type) + if (ii->ii_encalg == esp_new_xform[i]->type) break; if (i < 0) @@ -244,7 +134,7 @@ esp_new_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) return EINVAL; } - txform = &esp_new_xform[i]; + txform = esp_new_xform[i]; if (ii->ii_enckeylen < txform->minkey) { @@ -260,9 +150,9 @@ esp_new_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) if (ii->ii_authalg) { - for (i = sizeof(esp_new_hash) / sizeof(struct auth_hash) - 1; + for (i = sizeof(esp_new_hash) / sizeof(esp_new_hash[0]) - 1; i >= 0; i--) - if (ii->ii_authalg == esp_new_hash[i].type) + if (ii->ii_authalg == esp_new_hash[i]->type) break; if (i < 0) @@ -271,7 +161,7 @@ esp_new_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) return EINVAL; } - thash = &esp_new_hash[i]; + thash = esp_new_hash[i]; if (ii->ii_authkeylen != thash->keysize) { @@ -298,45 +188,8 @@ esp_new_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) /* Initialize the IV */ get_random_bytes(tdbp->tdb_iv, tdbp->tdb_ivlen); - switch (ii->ii_encalg) - { - case SADB_EALG_DESCBC: - MALLOC(tdbp->tdb_key, u_int8_t *, 128, M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, 128); - des_set_key(ii->ii_enckey, tdbp->tdb_key); - break; - - case SADB_EALG_3DESCBC: - MALLOC(tdbp->tdb_key, u_int8_t *, 384, M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, 384); - des_set_key(ii->ii_enckey, tdbp->tdb_key); - des_set_key(ii->ii_enckey + 8, tdbp->tdb_key + 128); - des_set_key(ii->ii_enckey + 16, tdbp->tdb_key + 256); - break; - - case SADB_EALG_X_BLF: - MALLOC(tdbp->tdb_key, u_int8_t *, sizeof(blf_ctx), - M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, sizeof(blf_ctx)); - blf_key((blf_ctx *) tdbp->tdb_key, ii->ii_enckey, - ii->ii_enckeylen); - break; - - case SADB_EALG_X_CAST: - MALLOC(tdbp->tdb_key, u_int8_t *, sizeof(cast_key), - M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, sizeof(cast_key)); - cast_setkey((cast_key *) tdbp->tdb_key, ii->ii_enckey, - ii->ii_enckeylen); - break; - - case SADB_EALG_X_SKIPJACK: - MALLOC(tdbp->tdb_key, u_int8_t *, 10 * sizeof(u_int8_t *), - M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, 10 * sizeof(u_int8_t *)); - subkey_table_gen(ii->ii_enckey, (u_int8_t **) tdbp->tdb_key); - break; - } + if (txform->setkey) + txform->setkey(&tdbp->tdb_key, ii->ii_enckey, ii->ii_enckeylen); if (thash) { @@ -368,49 +221,9 @@ esp_new_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) int esp_new_zeroize(struct tdb *tdbp) { - int k; - - if (tdbp->tdb_encalgxform && tdbp->tdb_key && - tdbp->tdb_encalgxform->type == SADB_EALG_X_SKIPJACK) - for (k = 0; k < 10; k++) - if (((u_int8_t **)tdbp->tdb_key)[k] != NULL) - { - bzero(((u_int8_t **)tdbp->tdb_key)[k], 0x100); - FREE(((u_int8_t **)tdbp->tdb_key)[k], M_XDATA); - } - - if (tdbp->tdb_key) - { - if (tdbp->tdb_encalgxform) - switch (tdbp->tdb_encalgxform->type) - { - case SADB_EALG_DESCBC: - k = 128; - break; - - case SADB_EALG_3DESCBC: - k = 384; - break; - - case SADB_EALG_X_BLF: - k = sizeof(blf_ctx); - break; - - case SADB_EALG_X_CAST: - k = sizeof(cast_key); - break; - - case SADB_EALG_X_SKIPJACK: - /* Not really necessary, we have bzero'ed it */ - - default: - k = 0; - } - - bzero(tdbp->tdb_key, k); - FREE(tdbp->tdb_key, M_XDATA); - tdbp->tdb_key = NULL; - } + if (tdbp->tdb_key && tdbp->tdb_encalgxform && + tdbp->tdb_encalgxform->zerokey) + tdbp->tdb_encalgxform->zerokey(&tdbp->tdb_key); if (tdbp->tdb_ictx) { diff --git a/sys/netinet/ip_esp_old.c b/sys/netinet/ip_esp_old.c index b797313e87f..349135df1e8 100644 --- a/sys/netinet/ip_esp_old.c +++ b/sys/netinet/ip_esp_old.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_esp_old.c,v 1.34 1999/05/16 21:48:33 niklas Exp $ */ +/* $OpenBSD: ip_esp_old.c,v 1.35 1999/06/18 07:24:04 deraadt Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), @@ -78,55 +78,13 @@ #define DPRINTF(x) #endif -extern void des_ecb3_encrypt(caddr_t, caddr_t, caddr_t, caddr_t, caddr_t, int); -extern void des_ecb_encrypt(caddr_t, caddr_t, caddr_t, int); -extern void des_set_key(caddr_t, caddr_t); - -static void des1_encrypt(struct tdb *, u_int8_t *); -static void des3_encrypt(struct tdb *, u_int8_t *); -static void des1_decrypt(struct tdb *, u_int8_t *); -static void des3_decrypt(struct tdb *, u_int8_t *); - -struct enc_xform esp_old_xform[] = { - { SADB_EALG_DESCBC, "Data Encryption Standard (DES)", - ESP_DES_BLKS, ESP_DES_IVS, - 8, 8, 8, - des1_encrypt, - des1_decrypt - }, - { SADB_EALG_3DESCBC, "Triple DES (3DES)", - ESP_3DES_BLKS, ESP_3DES_IVS, - 24, 24, 8, - des3_encrypt, - des3_decrypt - } -}; - -static void -des1_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb_encrypt(blk, blk, tdb->tdb_key, 1); -} - -static void -des1_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb_encrypt(blk, blk, tdb->tdb_key, 0); -} - -static void -des3_encrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb3_encrypt(blk, blk, tdb->tdb_key, tdb->tdb_key + 128, - tdb->tdb_key + 256, 1); -} +extern struct enc_xform enc_xform_des; +extern struct enc_xform enc_xform_3des; -static void -des3_decrypt(struct tdb *tdb, u_int8_t *blk) -{ - des_ecb3_encrypt(blk, blk, tdb->tdb_key + 256, tdb->tdb_key + 128, - tdb->tdb_key, 0); -} +struct enc_xform *esp_old_xform[] = { + &enc_xform_des, + &enc_xform_3des +}; int esp_old_attach() @@ -145,9 +103,9 @@ esp_old_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) int i; /* Check whether the encryption algorithm is supported */ - for (i = sizeof(esp_old_xform) / sizeof(struct enc_xform) - 1; + for (i = sizeof(esp_old_xform) / sizeof(esp_old_xform[0]) - 1; i >= 0; i--) - if (ii->ii_encalg == esp_old_xform[i].type) + if (ii->ii_encalg == esp_old_xform[i]->type) break; if (i < 0) @@ -156,7 +114,7 @@ esp_old_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) return EINVAL; } - txform = &esp_old_xform[i]; + txform = esp_old_xform[i]; if (ii->ii_enckeylen < txform->minkey) { @@ -182,22 +140,8 @@ esp_old_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) get_random_bytes(tdbp->tdb_iv, tdbp->tdb_ivlen); - switch (ii->ii_encalg) - { - case SADB_EALG_DESCBC: - MALLOC(tdbp->tdb_key, u_int8_t *, 128, M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, 128); - des_set_key(ii->ii_enckey, tdbp->tdb_key); - break; - - case SADB_EALG_3DESCBC: - MALLOC(tdbp->tdb_key, u_int8_t *, 384, M_XDATA, M_WAITOK); - bzero(tdbp->tdb_key, 384); - des_set_key(ii->ii_enckey, tdbp->tdb_key); - des_set_key(ii->ii_enckey + 8, tdbp->tdb_key + 128); - des_set_key(ii->ii_enckey + 16, tdbp->tdb_key + 256); - break; - } + if (txform->setkey) + txform->setkey(&tdbp->tdb_key, ii->ii_enckey, ii->ii_enckeylen); return 0; } @@ -206,24 +150,10 @@ esp_old_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) int esp_old_zeroize(struct tdb *tdbp) { - if (tdbp->tdb_key) - { - if (tdbp->tdb_encalgxform) - switch (tdbp->tdb_encalgxform->type) - { - case SADB_EALG_DESCBC: - bzero(tdbp->tdb_key, 128); - break; - - case SADB_EALG_3DESCBC: - bzero(tdbp->tdb_key, 384); - break; - } - - FREE(tdbp->tdb_key, M_XDATA); - tdbp->tdb_key = NULL; - } - + if (tdbp->tdb_key && tdbp->tdb_encalgxform && + tdbp->tdb_encalgxform->zerokey) + tdbp->tdb_encalgxform->zerokey(&tdbp->tdb_key); + return 0; } diff --git a/sys/netinet/ip_ipsp.h b/sys/netinet/ip_ipsp.h index 34f7785fc78..f4b77e8093d 100644 --- a/sys/netinet/ip_ipsp.h +++ b/sys/netinet/ip_ipsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipsp.h,v 1.35 1999/06/06 23:53:02 angelos Exp $ */ +/* $OpenBSD: ip_ipsp.h,v 1.36 1999/06/18 07:24:07 deraadt Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), @@ -312,6 +312,8 @@ struct enc_xform { u_int32_t ivmask; /* Or all possible modes, zero iv = 1 */ void (*encrypt)(struct tdb *, u_int8_t *); void (*decrypt)(struct tdb *, u_int8_t *); + void (*setkey)(u_int8_t **, u_int8_t *, int len); + void (*zerokey)(u_int8_t **); }; struct ipsecinit diff --git a/sys/netinet/ip_xform.c b/sys/netinet/ip_xform.c new file mode 100644 index 00000000000..eca4f0327e5 --- /dev/null +++ b/sys/netinet/ip_xform.c @@ -0,0 +1,323 @@ +/* $OpenBSD: ip_xform.c,v 1.1 1999/06/18 07:24:08 deraadt Exp $ */ + +/* + * The authors of this code are John Ioannidis (ji@tla.org), + * Angelos D. Keromytis (kermit@csd.uch.gr) and + * Niels Provos (provos@physnet.uni-hamburg.de). + * + * This code was written by John Ioannidis for BSD/OS in Athens, Greece, + * in November 1995. + * + * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, + * by Angelos D. Keromytis. + * + * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis + * and Niels Provos. + * + * Additional features in 1999 by Angelos D. Keromytis. + * + * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, + * Angelos D. Keromytis and Niels Provos. + * + * Permission to use, copy, and modify this software without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +/* + * Encapsulation Security Payload Processing + * Per RFC1827 (Atkinson, 1995) + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/malloc.h> +#include <sys/mbuf.h> +#include <sys/domain.h> +#include <sys/protosw.h> +#include <sys/socket.h> +#include <sys/sysctl.h> +#include <sys/errno.h> +#include <sys/time.h> +#include <sys/kernel.h> +#include <machine/cpu.h> + +#include <net/if.h> +#include <net/route.h> +#include <net/netisr.h> +#include <net/bpf.h> +#include <net/if_enc.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/in_pcb.h> +#include <netinet/in_var.h> +#include <netinet/ip_var.h> + +#include <sys/socketvar.h> +#include <net/raw_cb.h> + +#include <netinet/ip_icmp.h> +#include <netinet/ip_ipsp.h> +#include <netinet/ip_esp.h> +#include <net/pfkeyv2.h> + +extern void des_ecb3_encrypt(caddr_t, caddr_t, caddr_t, caddr_t, caddr_t, int); +extern void des_ecb_encrypt(caddr_t, caddr_t, caddr_t, int); +extern void des_set_key(caddr_t, caddr_t); + +static void des1_encrypt(struct tdb *, u_int8_t *); +static void des3_encrypt(struct tdb *, u_int8_t *); +static void blf_encrypt(struct tdb *, u_int8_t *); +static void cast5_encrypt(struct tdb *, u_int8_t *); +static void skipjack_encrypt(struct tdb *, u_int8_t *); +static void des1_decrypt(struct tdb *, u_int8_t *); +static void des3_decrypt(struct tdb *, u_int8_t *); +static void blf_decrypt(struct tdb *, u_int8_t *); +static void cast5_decrypt(struct tdb *, u_int8_t *); +static void skipjack_decrypt(struct tdb *, u_int8_t *); + +static void +des1_encrypt(struct tdb *tdb, u_int8_t *blk) +{ + des_ecb_encrypt(blk, blk, tdb->tdb_key, 1); +} + +static void +des1_decrypt(struct tdb *tdb, u_int8_t *blk) +{ + des_ecb_encrypt(blk, blk, tdb->tdb_key, 0); +} + +static void +des1_setkey(u_int8_t **sched, u_int8_t *key, int len) +{ + MALLOC(*sched, u_int8_t *, 128, M_XDATA, M_WAITOK); + bzero(*sched, 128); + des_set_key(key, *sched); +} + +static void +des1_zerokey(u_int8_t **sched) +{ + bzero(*sched, 128); + FREE(*sched, M_XDATA); + *sched = NULL; +} + +struct enc_xform enc_xform_des = { + SADB_EALG_DESCBC, "Data Encryption Standard (DES)", + ESP_DES_BLKS, ESP_DES_IVS, + 8, 8, 8, + des1_encrypt, + des1_decrypt, + des1_setkey, + des1_zerokey, +}; + +static void +des3_encrypt(struct tdb *tdb, u_int8_t *blk) +{ + des_ecb3_encrypt(blk, blk, tdb->tdb_key, tdb->tdb_key + 128, + tdb->tdb_key + 256, 1); +} + +static void +des3_decrypt(struct tdb *tdb, u_int8_t *blk) +{ + des_ecb3_encrypt(blk, blk, tdb->tdb_key + 256, tdb->tdb_key + 128, + tdb->tdb_key, 0); +} + +static void +des3_setkey(u_int8_t **sched, u_int8_t *key, int len) +{ + MALLOC(*sched, u_int8_t *, 384, M_XDATA, M_WAITOK); + bzero(*sched, 384); + des_set_key(key, *sched); + des_set_key(key + 8, *sched + 128); + des_set_key(key + 16, *sched + 256); +} + +static void +des3_zerokey(u_int8_t **sched) +{ + bzero(*sched, 384); + FREE(*sched, M_XDATA); + *sched = NULL; +} + +struct enc_xform enc_xform_3des = { + SADB_EALG_3DESCBC, "Triple DES (3DES)", + ESP_3DES_BLKS, ESP_3DES_IVS, + 24, 24, 8, + des3_encrypt, + des3_decrypt, + des3_setkey, + des3_zerokey +}; + +static void +blf_encrypt(struct tdb *tdb, u_int8_t *blk) +{ + blf_ecb_encrypt((blf_ctx *) tdb->tdb_key, blk, 8); +} + +static void +blf_decrypt(struct tdb *tdb, u_int8_t *blk) +{ + blf_ecb_decrypt((blf_ctx *) tdb->tdb_key, blk, 8); +} + +static void +blf_setkey(u_int8_t **sched, u_int8_t *key, int len) +{ + MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_XDATA, M_WAITOK); + bzero(*sched, sizeof(blf_ctx)); + blf_key((blf_ctx *)*sched, key, len); +} + +static void +blf_zerokey(u_int8_t **sched) +{ + bzero(*sched, sizeof(blf_ctx)); + FREE(*sched, M_XDATA); + *sched = NULL; +} + +struct enc_xform enc_xform_blf = { + SADB_EALG_X_BLF, "Blowfish", + ESP_BLF_BLKS, ESP_BLF_IVS, + 5, BLF_MAXKEYLEN, 8, + blf_encrypt, + blf_decrypt, + blf_setkey, + blf_zerokey +}; + +static void +cast5_encrypt(struct tdb *tdb, u_int8_t *blk) +{ + cast_encrypt((cast_key *) tdb->tdb_key, blk, blk); +} + +static void +cast5_decrypt(struct tdb *tdb, u_int8_t *blk) +{ + cast_decrypt((cast_key *) tdb->tdb_key, blk, blk); +} + +static void +cast5_setkey(u_int8_t **sched, u_int8_t *key, int len) +{ + MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_XDATA, M_WAITOK); + bzero(*sched, sizeof(blf_ctx)); + cast_setkey((cast_key *)*sched, key, len); +} + +static void +cast5_zerokey(u_int8_t **sched) +{ + bzero(*sched, sizeof(cast_key)); + FREE(*sched, M_XDATA); + *sched = NULL; +} + +struct enc_xform enc_xform_cast5 = { + SADB_EALG_X_CAST, "CAST", + ESP_CAST_BLKS, ESP_CAST_IVS, + 5, 16, 8, + cast5_encrypt, + cast5_decrypt, + cast5_setkey, + cast5_zerokey +}; + +static void +skipjack_encrypt(struct tdb *tdb, u_int8_t *blk) +{ + skipjack_forwards(blk, blk, (u_int8_t **) tdb->tdb_key); +} + +static void +skipjack_decrypt(struct tdb *tdb, u_int8_t *blk) +{ + skipjack_backwards(blk, blk, (u_int8_t **) tdb->tdb_key); +} + +static void +skipjack_setkey(u_int8_t **sched, u_int8_t *key, int len) +{ + MALLOC(*sched, u_int8_t *, 10 * sizeof(u_int8_t *), M_XDATA, M_WAITOK); + bzero(*sched, 10 * sizeof(u_int8_t *)); + subkey_table_gen(key, (u_int8_t **) *sched); +} + +static void +skipjack_zerokey(u_int8_t **sched) +{ + int k; + + for (k = 0; k < 10; k++) + if (((u_int8_t **)(*sched))[k]) + { + bzero(((u_int8_t **)(*sched))[k], 0x100); + FREE(((u_int8_t **)(*sched))[k], M_XDATA); + } + bzero(*sched, sizeof(cast_key)); + FREE(*sched, M_XDATA); + *sched = NULL; +} + +struct enc_xform enc_xform_skipjack = { + SADB_EALG_X_SKIPJACK, "Skipjack", + ESP_SKIPJACK_BLKS, ESP_SKIPJACK_IVS, + 10, 10, 8, + skipjack_encrypt, + skipjack_decrypt, + skipjack_setkey, + skipjack_zerokey +}; + +/* + * And now for auth + */ + +struct auth_hash auth_hash_hmac_md5_96 = { + SADB_AALG_MD5HMAC96, "HMAC-MD5-96", + MD5HMAC96_KEYSIZE, AH_MD5_ALEN, + sizeof(MD5_CTX), + (void (*) (void *)) MD5Init, + (void (*) (void *, u_int8_t *, u_int16_t)) MD5Update, + (void (*) (u_int8_t *, void *)) MD5Final +}; + +struct auth_hash auth_hash_hmac_sha1_96 = { + SADB_AALG_SHA1HMAC96, "HMAC-SHA1-96", + SHA1HMAC96_KEYSIZE, AH_SHA1_ALEN, + sizeof(SHA1_CTX), + (void (*) (void *)) SHA1Init, + (void (*) (void *, u_int8_t *, u_int16_t)) SHA1Update, + (void (*) (u_int8_t *, void *)) SHA1Final +}; + +struct auth_hash auth_hash_hmac_ripemd_160_96 = { + SADB_AALG_X_RIPEMD160HMAC96, "HMAC-RIPEMD-160-96", + RIPEMD160HMAC96_KEYSIZE, AH_RMD160_ALEN, + sizeof(RMD160_CTX), + (void (*)(void *)) RMD160Init, + (void (*)(void *, u_int8_t *, u_int16_t)) RMD160Update, + (void (*)(u_int8_t *, void *)) RMD160Final +}; |