add ESP rijndael logic. yet to be usable (until algorithm # is assigned)
This commit is contained in:
parent
b7a15a9d51
commit
e9536f86fa
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files,v 1.395 2000/09/27 23:02:02 thorpej Exp $
|
||||
# $NetBSD: files,v 1.396 2000/10/02 17:21:24 itojun Exp $
|
||||
|
||||
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
|
||||
|
||||
@ -588,6 +588,8 @@ file crypto/des/des_setkey.c ipsec & ipsec_esp
|
||||
file crypto/blowfish/bf_enc.c ipsec & ipsec_esp
|
||||
file crypto/blowfish/bf_skey.c ipsec & ipsec_esp
|
||||
file crypto/cast128/cast128.c ipsec & ipsec_esp
|
||||
file crypto/rijndael/rijndael-alg-fst.c ipsec & ipsec_esp
|
||||
file crypto/rijndael/rijndael-api-fst.c ipsec & ipsec_esp
|
||||
file ddb/db_access.c ddb | kgdb
|
||||
file ddb/db_aout.c ddb
|
||||
file ddb/db_break.c ddb
|
||||
@ -895,13 +897,13 @@ file netinet/ip_output.c inet
|
||||
file netinet/ip_proxy.c ipfilter
|
||||
file netinet/ip_state.c ipfilter
|
||||
file netinet/raw_ip.c inet
|
||||
file netinet/tcp_debug.c inet
|
||||
file netinet/tcp_input.c inet
|
||||
file netinet/tcp_output.c inet
|
||||
file netinet/tcp_subr.c inet
|
||||
file netinet/tcp_timer.c inet
|
||||
file netinet/tcp_usrreq.c inet
|
||||
file netinet/udp_usrreq.c inet
|
||||
file netinet/tcp_debug.c inet | inet6
|
||||
file netinet/tcp_input.c inet | inet6
|
||||
file netinet/tcp_output.c inet | inet6
|
||||
file netinet/tcp_subr.c inet | inet6
|
||||
file netinet/tcp_timer.c inet | inet6
|
||||
file netinet/tcp_usrreq.c inet | inet6
|
||||
file netinet/udp_usrreq.c inet | inet6
|
||||
file netinet6/ah_core.c ipsec
|
||||
file netinet6/ah_input.c ipsec
|
||||
file netinet6/ah_output.c ipsec
|
||||
@ -909,6 +911,7 @@ file netinet6/dest6.c inet6
|
||||
file netinet6/esp_core.c ipsec & ipsec_esp
|
||||
file netinet6/esp_output.c ipsec & ipsec_esp
|
||||
file netinet6/esp_input.c ipsec & ipsec_esp
|
||||
file netinet6/esp_rijndael.c ipsec & ipsec_esp
|
||||
file netinet6/frag6.c inet6
|
||||
file netinet6/icmp6.c inet6
|
||||
file netinet6/in6.c inet6
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: esp_core.c,v 1.9 2000/09/26 08:37:38 itojun Exp $ */
|
||||
/* $NetBSD: esp_core.c,v 1.10 2000/10/02 17:21:26 itojun Exp $ */
|
||||
/* $KAME: esp_core.c,v 1.44 2000/09/20 18:15:22 itojun Exp $ */
|
||||
|
||||
/*
|
||||
@ -58,6 +58,7 @@
|
||||
#include <netinet6/ipsec.h>
|
||||
#include <netinet6/ah.h>
|
||||
#include <netinet6/esp.h>
|
||||
#include <netinet6/esp_rijndael.h>
|
||||
#include <net/pfkeyv2.h>
|
||||
#include <netkey/keydb.h>
|
||||
#include <crypto/des/des.h>
|
||||
@ -136,6 +137,11 @@ static const struct esp_algorithm esp_algorithms[] = {
|
||||
esp_common_ivlen, esp_cbc_decrypt,
|
||||
esp_cbc_encrypt, esp_cast128_schedule,
|
||||
esp_cast128_blockdecrypt, esp_cast128_blockencrypt, },
|
||||
{ 16, 16, esp_cbc_mature, 128, 256, esp_rijndael_schedlen,
|
||||
"rijndael-cbc",
|
||||
esp_common_ivlen, esp_cbc_decrypt,
|
||||
esp_cbc_encrypt, esp_rijndael_schedule,
|
||||
esp_rijndael_blockdecrypt, esp_rijndael_blockencrypt },
|
||||
};
|
||||
|
||||
const struct esp_algorithm *
|
||||
@ -154,6 +160,10 @@ esp_algorithm_lookup(idx)
|
||||
return &esp_algorithms[3];
|
||||
case SADB_X_EALG_CAST128CBC:
|
||||
return &esp_algorithms[4];
|
||||
#ifdef SADB_X_EALG_RIJNDAELCBC
|
||||
case SADB_X_EALG_RIJNDAELCBC:
|
||||
return &esp_algorithms[5];
|
||||
#endif
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@ -412,6 +422,16 @@ esp_cbc_mature(sav)
|
||||
break;
|
||||
case SADB_X_EALG_BLOWFISHCBC:
|
||||
case SADB_X_EALG_CAST128CBC:
|
||||
#ifdef SADB_X_EALG_RIJNDAELCBC
|
||||
case SADB_X_EALG_RIJNDAELCBC:
|
||||
#endif
|
||||
/* allows specific key sizes only */
|
||||
if (!(keylen == 128 || keylen == 192 || keylen == 256)) {
|
||||
ipseclog((LOG_ERR,
|
||||
"esp_cbc_mature %s: invalid key length %d.\n",
|
||||
algo->name, keylen));
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
137
sys/netinet6/esp_rijndael.c
Normal file
137
sys/netinet6/esp_rijndael.c
Normal file
@ -0,0 +1,137 @@
|
||||
/* $NetBSD: esp_rijndael.c,v 1.1 2000/10/02 17:21:26 itojun Exp $ */
|
||||
/* $KAME: esp_rijndael.c,v 1.1 2000/09/20 18:15:22 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
|
||||
#include "opt_inet.h"
|
||||
#include "opt_inet6.h"
|
||||
#endif
|
||||
#ifdef __NetBSD__
|
||||
#include "opt_inet.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <netinet6/ipsec.h>
|
||||
#include <netinet6/esp.h>
|
||||
#include <netinet6/esp_rijndael.h>
|
||||
|
||||
#include <crypto/rijndael/rijndael.h>
|
||||
|
||||
#include <net/net_osdep.h>
|
||||
|
||||
/* as rijndael uses assymetric scheduled keys, we need to do it twice. */
|
||||
int
|
||||
esp_rijndael_schedlen(algo)
|
||||
const struct esp_algorithm *algo;
|
||||
{
|
||||
|
||||
return sizeof(keyInstance) * 2;
|
||||
}
|
||||
|
||||
int
|
||||
esp_rijndael_schedule(algo, sav)
|
||||
const struct esp_algorithm *algo;
|
||||
struct secasvar *sav;
|
||||
{
|
||||
keyInstance *k;
|
||||
char keymat[256 / 4 + 1];
|
||||
u_char *p, *ep;
|
||||
char *q, *eq;
|
||||
|
||||
/* rijndael_makeKey wants hex string for the key */
|
||||
if (_KEYLEN(sav->key_enc) * 2 > sizeof(keymat) - 1)
|
||||
return -1;
|
||||
p = _KEYBUF(sav->key_enc);
|
||||
ep = p + _KEYLEN(sav->key_enc);
|
||||
q = keymat;
|
||||
eq = &keymat[sizeof(keymat) - 1];
|
||||
while (p < ep && q < eq) {
|
||||
sprintf(q, "%02x", *p);
|
||||
q += 2;
|
||||
p++;
|
||||
}
|
||||
*eq = '\0';
|
||||
|
||||
k = (keyInstance *)sav->sched;
|
||||
if (rijndael_makeKey(&k[0], DIR_DECRYPT, _KEYLEN(sav->key_enc) * 8,
|
||||
keymat) < 0)
|
||||
return -1;
|
||||
if (rijndael_makeKey(&k[1], DIR_ENCRYPT, _KEYLEN(sav->key_enc) * 8,
|
||||
keymat) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
esp_rijndael_blockdecrypt(algo, sav, s, d)
|
||||
const struct esp_algorithm *algo;
|
||||
struct secasvar *sav;
|
||||
u_int8_t *s;
|
||||
u_int8_t *d;
|
||||
{
|
||||
cipherInstance c;
|
||||
keyInstance *p;
|
||||
|
||||
/* does not take advantage of CBC mode support */
|
||||
bzero(&c, sizeof(c));
|
||||
if (rijndael_cipherInit(&c, MODE_CBC, NULL) < 0)
|
||||
return -1;
|
||||
p = (keyInstance *)sav->sched;
|
||||
if (rijndael_blockDecrypt(&c, &p[0], s, algo->padbound * 8, d) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
esp_rijndael_blockencrypt(algo, sav, s, d)
|
||||
const struct esp_algorithm *algo;
|
||||
struct secasvar *sav;
|
||||
u_int8_t *s;
|
||||
u_int8_t *d;
|
||||
{
|
||||
cipherInstance c;
|
||||
keyInstance *p;
|
||||
|
||||
/* does not take advantage of CBC mode support */
|
||||
bzero(&c, sizeof(c));
|
||||
if (rijndael_cipherInit(&c, MODE_CBC, NULL) < 0)
|
||||
return -1;
|
||||
p = (keyInstance *)sav->sched;
|
||||
if (rijndael_blockEncrypt(&c, &p[1], s, algo->padbound * 8, d) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
39
sys/netinet6/esp_rijndael.h
Normal file
39
sys/netinet6/esp_rijndael.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* $NetBSD: esp_rijndael.h,v 1.1 2000/10/02 17:21:26 itojun Exp $ */
|
||||
/* $KAME: esp_rijndael.h,v 1.1 2000/09/20 18:15:22 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
int esp_rijndael_schedlen __P((const struct esp_algorithm *));
|
||||
int esp_rijndael_schedule __P((const struct esp_algorithm *,
|
||||
struct secasvar *));
|
||||
int esp_rijndael_blockdecrypt __P((const struct esp_algorithm *,
|
||||
struct secasvar *, u_int8_t *, u_int8_t *));
|
||||
int esp_rijndael_blockencrypt __P((const struct esp_algorithm *,
|
||||
struct secasvar *, u_int8_t *, u_int8_t *));
|
Loading…
x
Reference in New Issue
Block a user