sync with kame.

- include string.h (instead of sys/systm.h) on userland compilation.
  make compilation under src/regress/sys/crypto happier.  from minoura
- (blowfish) KNF.
This commit is contained in:
itojun 2000-11-06 14:11:40 +00:00
parent 73367a6dad
commit 7236276c18
10 changed files with 144 additions and 158 deletions

View File

@ -1,5 +1,5 @@
/* $NetBSD: bf_enc.c,v 1.2 2000/08/31 06:46:21 itojun Exp $ */
/* $KAME: bf_enc.c,v 1.4 2000/08/31 05:41:03 itojun Exp $ */
/* $NetBSD: bf_enc.c,v 1.3 2000/11/06 14:11:40 itojun Exp $ */
/* $KAME: bf_enc.c,v 1.5 2000/09/18 21:21:19 itojun Exp $ */
/* crypto/bf/bf_enc.c */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
@ -73,72 +73,71 @@ If you set BF_ROUNDS to some value other than 16 or 20, you will have
to modify the code.
#endif
void BF_encrypt(data,key,encrypt)
BF_LONG *data;
BF_KEY *key;
int encrypt;
{
register BF_LONG l,r,*p,*s;
/* XXX "data" is host endian */
void
BF_encrypt(data, key, encrypt)
BF_LONG *data;
BF_KEY *key;
int encrypt;
{
register BF_LONG l, r, *p, *s;
p=key->P;
s= &(key->S[0]);
l=data[0];
r=data[1];
p = key->P;
s= &key->S[0];
l = data[0];
r = data[1];
if (encrypt)
{
if (encrypt) {
l^=p[0];
BF_ENC(r,l,s,p[ 1]);
BF_ENC(l,r,s,p[ 2]);
BF_ENC(r,l,s,p[ 3]);
BF_ENC(l,r,s,p[ 4]);
BF_ENC(r,l,s,p[ 5]);
BF_ENC(l,r,s,p[ 6]);
BF_ENC(r,l,s,p[ 7]);
BF_ENC(l,r,s,p[ 8]);
BF_ENC(r,l,s,p[ 9]);
BF_ENC(l,r,s,p[10]);
BF_ENC(r,l,s,p[11]);
BF_ENC(l,r,s,p[12]);
BF_ENC(r,l,s,p[13]);
BF_ENC(l,r,s,p[14]);
BF_ENC(r,l,s,p[15]);
BF_ENC(l,r,s,p[16]);
BF_ENC(r, l, s, p[ 1]);
BF_ENC(l, r, s, p[ 2]);
BF_ENC(r, l, s, p[ 3]);
BF_ENC(l, r, s, p[ 4]);
BF_ENC(r, l, s, p[ 5]);
BF_ENC(l, r, s, p[ 6]);
BF_ENC(r, l, s, p[ 7]);
BF_ENC(l, r, s, p[ 8]);
BF_ENC(r, l, s, p[ 9]);
BF_ENC(l, r, s, p[10]);
BF_ENC(r, l, s, p[11]);
BF_ENC(l, r, s, p[12]);
BF_ENC(r, l, s, p[13]);
BF_ENC(l, r, s, p[14]);
BF_ENC(r, l, s, p[15]);
BF_ENC(l, r, s, p[16]);
#if BF_ROUNDS == 20
BF_ENC(r,l,s,p[17]);
BF_ENC(l,r,s,p[18]);
BF_ENC(r,l,s,p[19]);
BF_ENC(l,r,s,p[20]);
BF_ENC(r, l, s, p[17]);
BF_ENC(l, r, s, p[18]);
BF_ENC(r, l, s, p[19]);
BF_ENC(l, r, s, p[20]);
#endif
r^=p[BF_ROUNDS+1];
}
else
{
l^=p[BF_ROUNDS+1];
r ^= p[BF_ROUNDS + 1];
} else {
l ^= p[BF_ROUNDS + 1];
#if BF_ROUNDS == 20
BF_ENC(r,l,s,p[20]);
BF_ENC(l,r,s,p[19]);
BF_ENC(r,l,s,p[18]);
BF_ENC(l,r,s,p[17]);
BF_ENC(r, l, s, p[20]);
BF_ENC(l, r, s, p[19]);
BF_ENC(r, l, s, p[18]);
BF_ENC(l, r, s, p[17]);
#endif
BF_ENC(r,l,s,p[16]);
BF_ENC(l,r,s,p[15]);
BF_ENC(r,l,s,p[14]);
BF_ENC(l,r,s,p[13]);
BF_ENC(r,l,s,p[12]);
BF_ENC(l,r,s,p[11]);
BF_ENC(r,l,s,p[10]);
BF_ENC(l,r,s,p[ 9]);
BF_ENC(r,l,s,p[ 8]);
BF_ENC(l,r,s,p[ 7]);
BF_ENC(r,l,s,p[ 6]);
BF_ENC(l,r,s,p[ 5]);
BF_ENC(r,l,s,p[ 4]);
BF_ENC(l,r,s,p[ 3]);
BF_ENC(r,l,s,p[ 2]);
BF_ENC(l,r,s,p[ 1]);
r^=p[0];
}
data[1]=l&0xffffffff;
data[0]=r&0xffffffff;
BF_ENC(r, l, s, p[16]);
BF_ENC(l, r, s, p[15]);
BF_ENC(r, l, s, p[14]);
BF_ENC(l, r, s, p[13]);
BF_ENC(r, l, s, p[12]);
BF_ENC(l, r, s, p[11]);
BF_ENC(r, l, s, p[10]);
BF_ENC(l, r, s, p[ 9]);
BF_ENC(r, l, s, p[ 8]);
BF_ENC(l, r, s, p[ 7]);
BF_ENC(r, l, s, p[ 6]);
BF_ENC(l, r, s, p[ 5]);
BF_ENC(r, l, s, p[ 4]);
BF_ENC(l, r, s, p[ 3]);
BF_ENC(r, l, s, p[ 2]);
BF_ENC(l, r, s, p[ 1]);
r ^= p[0];
}
data[1] = l & 0xffffffff;
data[0] = r & 0xffffffff;
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: bf_skey.c,v 1.1.1.1 2000/06/14 19:45:34 thorpej Exp $ */
/* $KAME: bf_skey.c,v 1.3 2000/03/27 04:36:27 sumikawa Exp $ */
/* $NetBSD: bf_skey.c,v 1.2 2000/11/06 14:11:40 itojun Exp $ */
/* $KAME: bf_skey.c,v 1.5 2000/11/06 13:58:08 itojun Exp $ */
/* crypto/bf/bf_skey.c */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
@ -61,63 +61,64 @@
#include <sys/types.h>
#include <sys/time.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/blowfish/blowfish.h>
#include <crypto/blowfish/bf_locl.h>
#include <crypto/blowfish/bf_pi.h>
void BF_set_key(key,len,data)
BF_KEY *key;
int len;
unsigned char *data;
{
void
BF_set_key(key, len, data)
BF_KEY *key;
int len;
unsigned char *data;
{
int i;
BF_LONG *p,ri,in[2];
unsigned char *d,*end;
BF_LONG *p, ri, in[2];
unsigned char *d, *end;
memcpy((char *)key, (char *)&bf_init, sizeof(BF_KEY));
p = key->P;
memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));
p=key->P;
if (len > ((BF_ROUNDS + 2) * 4))
len = (BF_ROUNDS + 2) * 4;
if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
d=data;
d = data;
end= &(data[len]);
for (i=0; i<(BF_ROUNDS+2); i++)
{
ri= *(d++);
if (d >= end) d=data;
for (i = 0; i < BF_ROUNDS + 2; i++) {
ri = *(d++);
if (d >= end) d = data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri <<= 8;
ri |= *(d++);
if (d >= end) d = data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri <<= 8;
ri |= *(d++);
if (d >= end) d = data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri <<= 8;
ri |= *(d++);
if (d >= end) d = data;
p[i]^=ri;
}
in[0]=0L;
in[1]=0L;
for (i=0; i<(BF_ROUNDS+2); i+=2)
{
BF_encrypt(in,key,BF_ENCRYPT);
p[i ]=in[0];
p[i+1]=in[1];
}
p=key->S;
for (i=0; i<4*256; i+=2)
{
BF_encrypt(in,key,BF_ENCRYPT);
p[i ]=in[0];
p[i+1]=in[1];
}
p[i] ^= ri;
}
in[0] = 0L;
in[1] = 0L;
for (i = 0; i < BF_ROUNDS + 2; i += 2) {
BF_encrypt(in, key, BF_ENCRYPT);
p[i ] = in[0];
p[i+1] = in[1];
}
p = key->S;
for (i = 0; i < 4 * 256; i += 2) {
BF_encrypt(in, key, BF_ENCRYPT);
p[i ] = in[0];
p[i+1] = in[1];
}
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: blowfish.h,v 1.2 2000/08/31 06:46:21 itojun Exp $ */
/* $KAME: blowfish.h,v 1.7 2000/08/31 06:21:55 itojun Exp $ */
/* $NetBSD: blowfish.h,v 1.3 2000/11/06 14:11:40 itojun Exp $ */
/* $KAME: blowfish.h,v 1.10 2000/09/18 21:21:20 itojun Exp $ */
/* crypto/bf/blowfish.h */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
@ -75,27 +75,13 @@ extern "C" {
#define BF_ROUNDS 16
#define BF_BLOCK 8
typedef struct bf_key_st
{
typedef struct bf_key_st {
BF_LONG P[BF_ROUNDS+2];
BF_LONG S[4*256];
} BF_KEY;
} BF_KEY;
void BF_set_key __P((BF_KEY *, int, unsigned char *));
void BF_ecb_encrypt __P((unsigned char *, unsigned char *, BF_KEY *, int));
void BF_encrypt __P((BF_LONG *, BF_KEY *, int));
void BF_cbc_encrypt __P((unsigned char *, unsigned char *, long,
BF_KEY *, unsigned char *, int));
void BF_cfb64_encrypt __P((unsigned char *, unsigned char *, long,
BF_KEY *, unsigned char *, int *, int));
void BF_ofb64_encrypt __P((unsigned char *, unsigned char *, long,
BF_KEY *, unsigned char *, int *));
char *BF_options __P((void));
/* added by itojun */
struct mbuf;
int BF_cbc_encrypt_m __P((struct mbuf *, int, int, BF_KEY *, unsigned char *, int));
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: cast128.c,v 1.1.1.1 2000/06/14 19:45:34 thorpej Exp $ */
/* $KAME: cast128.c,v 1.3 2000/03/27 04:36:29 sumikawa Exp $ */
/* $NetBSD: cast128.c,v 1.2 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: cast128.c,v 1.4 2000/11/06 13:58:08 itojun Exp $ */
/*
* heavily modified by Tomomi Suzuki <suzuki@grelot.elec.ryukoku.ac.jp>
@ -37,7 +37,11 @@
*/
#include <sys/param.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/cast128/cast128.h>
#include <crypto/cast128/cast128_subkey.h>

View File

@ -1,5 +1,5 @@
/* $NetBSD: cast128.h,v 1.2 2000/08/31 06:59:17 itojun Exp $ */
/* $KAME: cast128.h,v 1.5 2000/08/31 06:57:56 itojun Exp $ */
/* $NetBSD: cast128.h,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: cast128.h,v 1.6 2000/09/18 20:59:20 itojun Exp $ */
/*
* heavily modified by Tomomi Suzuki <suzuki@grelot.elec.ryukoku.ac.jp>
@ -55,9 +55,5 @@ extern void cast128_encrypt_round12 __P((u_int8_t *, const u_int8_t *,
u_int32_t *));
extern void cast128_decrypt_round12 __P((u_int8_t *, const u_int8_t *,
u_int32_t *));
struct mbuf;
extern int cast128_cbc_process __P((struct mbuf *, size_t, size_t,
u_int32_t *, u_int8_t *, size_t, int));
#endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: des.h,v 1.3 2000/08/31 14:53:48 itojun Exp $ */
/* $KAME: des.h,v 1.6 2000/08/31 14:52:59 itojun Exp $ */
/* $NetBSD: des.h,v 1.4 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des.h,v 1.7 2000/09/18 20:59:21 itojun Exp $ */
/* lib/des/des.h */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -83,14 +83,6 @@ typedef struct des_ks_struct
extern int des_check_key; /* defaults to false */
char *des_options __P((void));
struct mbuf;
int des_cbc_encrypt __P((struct mbuf *, size_t, size_t,
des_key_schedule, des_cblock *, int));
void des_3cbc_encrypt __P((des_cblock *, des_cblock *, long,
des_key_schedule, des_key_schedule,
des_cblock *, des_cblock *, int));
extern int des_3cbc_process __P((struct mbuf *, size_t, size_t,
des_key_schedule *, des_cblock *, int));
void des_ecb_encrypt __P((des_cblock *, des_cblock *,
des_key_schedule, int));
void des_encrypt __P((DES_LONG *, des_key_schedule, int));

View File

@ -1,5 +1,5 @@
/* $NetBSD: des_ecb.c,v 1.2 2000/08/31 07:33:05 itojun Exp $ */
/* $KAME: des_ecb.c,v 1.4 2000/08/31 07:27:27 itojun Exp $ */
/* $NetBSD: des_ecb.c,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des_ecb.c,v 1.5 2000/11/06 13:58:08 itojun Exp $ */
/* crypto/des/ecb_enc.c */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -49,8 +49,11 @@
*/
#include <sys/param.h>
#include <sys/malloc.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/des/des_locl.h>
#include <crypto/des/spr.h>

View File

@ -1,5 +1,5 @@
/* $NetBSD: des_locl.h,v 1.2 2000/08/31 07:33:05 itojun Exp $ */
/* $KAME: des_locl.h,v 1.5 2000/08/31 07:27:27 itojun Exp $ */
/* $NetBSD: des_locl.h,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des_locl.h,v 1.6 2000/11/06 13:58:09 itojun Exp $ */
/* lib/des/des_locl.h */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -62,8 +62,6 @@
#undef DES_PTR
#include <sys/systm.h>
#ifdef __STDC__
#undef NOPROTO
#endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: des_setkey.c,v 1.2 2000/08/31 07:33:05 itojun Exp $ */
/* $KAME: des_setkey.c,v 1.4 2000/08/31 07:27:27 itojun Exp $ */
/* $NetBSD: des_setkey.c,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des_setkey.c,v 1.5 2000/11/06 13:58:09 itojun Exp $ */
/* crypto/des/set_key.c */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -56,8 +56,11 @@
* 1.0 First working version
*/
#include <sys/param.h>
#include <sys/malloc.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/des/des_locl.h>
#include <crypto/des/podd.h>
#include <crypto/des/sk.h>

View File

@ -1,5 +1,5 @@
/* $NetBSD: rijndael-api-fst.c,v 1.3 2000/10/03 03:17:19 itojun Exp $ */
/* $KAME: rijndael-api-fst.c,v 1.6 2000/10/03 03:14:52 jinmei Exp $ */
/* $NetBSD: rijndael-api-fst.c,v 1.4 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: rijndael-api-fst.c,v 1.7 2000/11/06 13:58:09 itojun Exp $ */
/*
* rijndael-api-fst.c v2.3 April '2000
@ -17,8 +17,12 @@
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#ifdef _KERNEL
#include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/rijndael/rijndael-alg-fst.h>
#include <crypto/rijndael/rijndael-api-fst.h>
#include <crypto/rijndael/rijndael_local.h>