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

View File

@ -1,5 +1,5 @@
/* $NetBSD: bf_skey.c,v 1.1.1.1 2000/06/14 19:45:34 thorpej Exp $ */ /* $NetBSD: bf_skey.c,v 1.2 2000/11/06 14:11:40 itojun Exp $ */
/* $KAME: bf_skey.c,v 1.3 2000/03/27 04:36:27 sumikawa Exp $ */ /* $KAME: bf_skey.c,v 1.5 2000/11/06 13:58:08 itojun Exp $ */
/* crypto/bf/bf_skey.c */ /* crypto/bf/bf_skey.c */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) /* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
@ -61,12 +61,17 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#ifdef _KERNEL
#include <sys/systm.h> #include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/blowfish/blowfish.h> #include <crypto/blowfish/blowfish.h>
#include <crypto/blowfish/bf_locl.h> #include <crypto/blowfish/bf_locl.h>
#include <crypto/blowfish/bf_pi.h> #include <crypto/blowfish/bf_pi.h>
void BF_set_key(key,len,data) void
BF_set_key(key, len, data)
BF_KEY *key; BF_KEY *key;
int len; int len;
unsigned char *data; unsigned char *data;
@ -75,16 +80,15 @@ unsigned char *data;
BF_LONG *p, ri, in[2]; BF_LONG *p, ri, in[2];
unsigned char *d, *end; unsigned char *d, *end;
memcpy((char *)key, (char *)&bf_init, sizeof(BF_KEY)); memcpy((char *)key, (char *)&bf_init, sizeof(BF_KEY));
p = key->P; 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]); end= &(data[len]);
for (i=0; i<(BF_ROUNDS+2); i++) for (i = 0; i < BF_ROUNDS + 2; i++) {
{
ri = *(d++); ri = *(d++);
if (d >= end) d = data; if (d >= end) d = data;
@ -105,19 +109,16 @@ unsigned char *data;
in[0] = 0L; in[0] = 0L;
in[1] = 0L; in[1] = 0L;
for (i=0; i<(BF_ROUNDS+2); i+=2) for (i = 0; i < BF_ROUNDS + 2; i += 2) {
{
BF_encrypt(in, key, BF_ENCRYPT); BF_encrypt(in, key, BF_ENCRYPT);
p[i ] = in[0]; p[i ] = in[0];
p[i+1] = in[1]; p[i+1] = in[1];
} }
p = key->S; p = key->S;
for (i=0; i<4*256; i+=2) for (i = 0; i < 4 * 256; i += 2) {
{
BF_encrypt(in, key, BF_ENCRYPT); BF_encrypt(in, key, BF_ENCRYPT);
p[i ] = in[0]; p[i ] = in[0];
p[i+1] = in[1]; 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 $ */ /* $NetBSD: blowfish.h,v 1.3 2000/11/06 14:11:40 itojun Exp $ */
/* $KAME: blowfish.h,v 1.7 2000/08/31 06:21:55 itojun Exp $ */ /* $KAME: blowfish.h,v 1.10 2000/09/18 21:21:20 itojun Exp $ */
/* crypto/bf/blowfish.h */ /* crypto/bf/blowfish.h */
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) /* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
@ -75,27 +75,13 @@ extern "C" {
#define BF_ROUNDS 16 #define BF_ROUNDS 16
#define BF_BLOCK 8 #define BF_BLOCK 8
typedef struct bf_key_st typedef struct bf_key_st {
{
BF_LONG P[BF_ROUNDS+2]; BF_LONG P[BF_ROUNDS+2];
BF_LONG S[4*256]; BF_LONG S[4*256];
} BF_KEY; } BF_KEY;
void BF_set_key __P((BF_KEY *, int, unsigned char *)); 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_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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: cast128.c,v 1.1.1.1 2000/06/14 19:45:34 thorpej Exp $ */ /* $NetBSD: cast128.c,v 1.2 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: cast128.c,v 1.3 2000/03/27 04:36:29 sumikawa 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> * heavily modified by Tomomi Suzuki <suzuki@grelot.elec.ryukoku.ac.jp>
@ -37,7 +37,11 @@
*/ */
#include <sys/param.h> #include <sys/param.h>
#ifdef _KERNEL
#include <sys/systm.h> #include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/cast128/cast128.h> #include <crypto/cast128/cast128.h>
#include <crypto/cast128/cast128_subkey.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 $ */ /* $NetBSD: cast128.h,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: cast128.h,v 1.5 2000/08/31 06:57:56 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> * 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 *)); u_int32_t *));
extern void cast128_decrypt_round12 __P((u_int8_t *, const u_int8_t *, extern void cast128_decrypt_round12 __P((u_int8_t *, const u_int8_t *,
u_int32_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 #endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: des.h,v 1.3 2000/08/31 14:53:48 itojun Exp $ */ /* $NetBSD: des.h,v 1.4 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des.h,v 1.6 2000/08/31 14:52:59 itojun Exp $ */ /* $KAME: des.h,v 1.7 2000/09/18 20:59:21 itojun Exp $ */
/* lib/des/des.h */ /* lib/des/des.h */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) /* 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 */ extern int des_check_key; /* defaults to false */
char *des_options __P((void)); 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 *, void des_ecb_encrypt __P((des_cblock *, des_cblock *,
des_key_schedule, int)); des_key_schedule, int));
void des_encrypt __P((DES_LONG *, 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 $ */ /* $NetBSD: des_ecb.c,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des_ecb.c,v 1.4 2000/08/31 07:27:27 itojun Exp $ */ /* $KAME: des_ecb.c,v 1.5 2000/11/06 13:58:08 itojun Exp $ */
/* crypto/des/ecb_enc.c */ /* crypto/des/ecb_enc.c */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -49,8 +49,11 @@
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/malloc.h> #ifdef _KERNEL
#include <sys/systm.h> #include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/des/des_locl.h> #include <crypto/des/des_locl.h>
#include <crypto/des/spr.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 $ */ /* $NetBSD: des_locl.h,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des_locl.h,v 1.5 2000/08/31 07:27:27 itojun Exp $ */ /* $KAME: des_locl.h,v 1.6 2000/11/06 13:58:09 itojun Exp $ */
/* lib/des/des_locl.h */ /* lib/des/des_locl.h */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -62,8 +62,6 @@
#undef DES_PTR #undef DES_PTR
#include <sys/systm.h>
#ifdef __STDC__ #ifdef __STDC__
#undef NOPROTO #undef NOPROTO
#endif #endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: des_setkey.c,v 1.2 2000/08/31 07:33:05 itojun Exp $ */ /* $NetBSD: des_setkey.c,v 1.3 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: des_setkey.c,v 1.4 2000/08/31 07:27:27 itojun Exp $ */ /* $KAME: des_setkey.c,v 1.5 2000/11/06 13:58:09 itojun Exp $ */
/* crypto/des/set_key.c */ /* crypto/des/set_key.c */
/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
@ -56,8 +56,11 @@
* 1.0 First working version * 1.0 First working version
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/malloc.h> #ifdef _KERNEL
#include <sys/systm.h> #include <sys/systm.h>
#else
#include <string.h>
#endif
#include <crypto/des/des_locl.h> #include <crypto/des/des_locl.h>
#include <crypto/des/podd.h> #include <crypto/des/podd.h>
#include <crypto/des/sk.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 $ */ /* $NetBSD: rijndael-api-fst.c,v 1.4 2000/11/06 14:11:41 itojun Exp $ */
/* $KAME: rijndael-api-fst.c,v 1.6 2000/10/03 03:14:52 jinmei 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 * rijndael-api-fst.c v2.3 April '2000
@ -17,8 +17,12 @@
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.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-alg-fst.h>
#include <crypto/rijndael/rijndael-api-fst.h> #include <crypto/rijndael/rijndael-api-fst.h>
#include <crypto/rijndael/rijndael_local.h> #include <crypto/rijndael/rijndael_local.h>