diff options
author | itojun <itojun@FreeBSD.org> | 2000-07-04 16:35:15 +0000 |
---|---|---|
committer | itojun <itojun@FreeBSD.org> | 2000-07-04 16:35:15 +0000 |
commit | 5f4e854de19331a53788d6100bbcd42845056bc1 (patch) | |
tree | 3ff8c876a5868b103fb8713055d83e29a3fa38d5 /sys/crypto/des | |
parent | bdc16885232d771a99d7dfc247cd27a44cd061f9 (diff) | |
download | FreeBSD-src-5f4e854de19331a53788d6100bbcd42845056bc1.zip FreeBSD-src-5f4e854de19331a53788d6100bbcd42845056bc1.tar.gz |
sync with kame tree as of july00. tons of bug fixes/improvements.
API changes:
- additional IPv6 ioctls
- IPsec PF_KEY API was changed, it is mandatory to upgrade setkey(8).
(also syntax change)
Diffstat (limited to 'sys/crypto/des')
-rw-r--r-- | sys/crypto/des/des.h | 73 | ||||
-rw-r--r-- | sys/crypto/des/des_3cbc.c | 18 | ||||
-rw-r--r-- | sys/crypto/des/des_cbc.c | 21 | ||||
-rw-r--r-- | sys/crypto/des/des_ecb.c | 7 | ||||
-rw-r--r-- | sys/crypto/des/des_locl.h | 69 | ||||
-rw-r--r-- | sys/crypto/des/des_setkey.c | 11 | ||||
-rw-r--r-- | sys/crypto/des/podd.h | 5 | ||||
-rw-r--r-- | sys/crypto/des/sk.h | 5 | ||||
-rw-r--r-- | sys/crypto/des/spr.h | 5 |
9 files changed, 114 insertions, 100 deletions
diff --git a/sys/crypto/des/des.h b/sys/crypto/des/des.h index 16a8129..536f0c9 100644 --- a/sys/crypto/des/des.h +++ b/sys/crypto/des/des.h @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: des.h,v 1.4 2000/06/14 10:41:17 itojun Exp $ */ + /* lib/des/des.h */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,12 +46,10 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ #ifndef HEADER_DES_H -#define HEADER_DES_H +#define HEADER_DES_H #ifdef __cplusplus extern "C" { @@ -57,7 +58,7 @@ extern "C" { /* If this is set to 'unsigned int' on a DEC Alpha, this gives about a * %20 speed up (longs are 8 bytes, int's are 4). */ #ifndef DES_LONG -#define DES_LONG unsigned long +#define DES_LONG unsigned long #endif typedef unsigned char des_cblock[8]; @@ -70,54 +71,54 @@ typedef struct des_ks_struct DES_LONG pad[2]; } ks; #undef _ -#define _ ks._ +#define _ ks._ } des_key_schedule[16]; -#define DES_KEY_SZ (sizeof(des_cblock)) -#define DES_SCHEDULE_SZ (sizeof(des_key_schedule)) +#define DES_KEY_SZ (sizeof(des_cblock)) +#define DES_SCHEDULE_SZ (sizeof(des_key_schedule)) -#define DES_ENCRYPT 1 -#define DES_DECRYPT 0 +#define DES_ENCRYPT 1 +#define DES_DECRYPT 0 -#define DES_CBC_MODE 0 -#define DES_PCBC_MODE 1 +#define DES_CBC_MODE 0 +#define DES_PCBC_MODE 1 -#define des_ecb2_encrypt(i,o,k1,k2,e) \ +#define des_ecb2_encrypt(i,o,k1,k2,e) \ des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) -#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ +#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) -#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ +#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) -#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ +#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) -#define C_Block des_cblock -#define Key_schedule des_key_schedule +#define C_Block des_cblock +#define Key_schedule des_key_schedule #ifdef KERBEROS -#define ENCRYPT DES_ENCRYPT -#define DECRYPT DES_DECRYPT +#define ENCRYPT DES_ENCRYPT +#define DECRYPT DES_DECRYPT #endif -#define KEY_SZ DES_KEY_SZ -#define string_to_key des_string_to_key -#define read_pw_string des_read_pw_string -#define random_key des_random_key -#define pcbc_encrypt des_pcbc_encrypt -#define set_key des_set_key -#define key_sched des_key_sched -#define ecb_encrypt des_ecb_encrypt -#define cbc_encrypt des_cbc_encrypt -#define ncbc_encrypt des_ncbc_encrypt -#define xcbc_encrypt des_xcbc_encrypt -#define cbc_cksum des_cbc_cksum -#define quad_cksum des_quad_cksum +#define KEY_SZ DES_KEY_SZ +#define string_to_key des_string_to_key +#define read_pw_string des_read_pw_string +#define random_key des_random_key +#define pcbc_encrypt des_pcbc_encrypt +#define set_key des_set_key +#define key_sched des_key_sched +#define ecb_encrypt des_ecb_encrypt +#define cbc_encrypt des_cbc_encrypt +#define ncbc_encrypt des_ncbc_encrypt +#define xcbc_encrypt des_xcbc_encrypt +#define cbc_cksum des_cbc_cksum +#define quad_cksum des_quad_cksum /* For compatibility with the MIT lib - eay 20/05/92 */ typedef des_key_schedule bit_64; -#define des_fixup_key_parity des_set_odd_parity -#define des_check_key_parity check_parity +#define des_fixup_key_parity des_set_odd_parity +#define des_check_key_parity check_parity extern int des_check_key; /* defaults to false */ extern int des_rw_mode; /* defaults to DES_PCBC_MODE */ @@ -139,7 +140,7 @@ DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output, void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length, des_key_schedule schedule,des_cblock *ivec,int enc); */ -void des_cbc_encrypt(struct mbuf *, size_t, size_t, +int des_cbc_encrypt(struct mbuf *, size_t, size_t, des_key_schedule schedule,des_cblock *ivec, int enc); void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length, des_key_schedule schedule,des_cblock *ivec,int enc); @@ -149,7 +150,7 @@ void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length, void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length, des_key_schedule sk1,des_key_schedule sk2, des_cblock *ivec1,des_cblock *ivec2,int enc); -extern void des_3cbc_process(struct mbuf *, size_t, size_t, +extern int des_3cbc_process(struct mbuf *, size_t, size_t, des_key_schedule *schedule, des_cblock *ivec, int mode); void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits, long length,des_key_schedule schedule,des_cblock *ivec,int enc); diff --git a/sys/crypto/des/des_3cbc.c b/sys/crypto/des/des_3cbc.c index 7ddb06c..e675871 100644 --- a/sys/crypto/des/des_3cbc.c +++ b/sys/crypto/des/des_3cbc.c @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: des_3cbc.c,v 1.4 2000/06/14 10:41:17 itojun Exp $ */ + /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. @@ -25,16 +28,15 @@ * 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. - * - * $FreeBSD$ */ /* * based on sys/crypto/des/des_cbc.c, rewrote by Tomomi Suzuki */ #include <crypto/des/des_locl.h> +#define panic(x) do { printf(x); return EINVAL; } while (0) -void des_3cbc_process(m0, skip, length, schedule, ivec, mode) +int des_3cbc_process(m0, skip, length, schedule, ivec, mode) struct mbuf *m0; size_t skip; size_t length; @@ -55,21 +57,21 @@ void des_3cbc_process(m0, skip, length, schedule, ivec, mode) /* sanity check */ if (m0->m_pkthdr.len < skip) { printf("des_3cbc_process: mbuf length < skip\n"); - return; + return EINVAL; } if (m0->m_pkthdr.len < length) { printf("des_3cbc_process: mbuf length < encrypt length\n"); - return; + return EINVAL; } if (m0->m_pkthdr.len < skip + length) { printf("des_3cbc_process: mbuf length < " "skip + encrypt length\n"); - return; + return EINVAL; } if (length % 8) { printf("des_3cbc_process: length(%lu) is not multiple of 8\n", (u_long)length); - return; + return EINVAL; } m = m0; @@ -242,5 +244,7 @@ void des_3cbc_process(m0, skip, length, schedule, ivec, mode) length -= 8; } + + return 0; } diff --git a/sys/crypto/des/des_cbc.c b/sys/crypto/des/des_cbc.c index 665352a..92de8f8 100644 --- a/sys/crypto/des/des_cbc.c +++ b/sys/crypto/des/des_cbc.c @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: des_cbc.c,v 1.4 2000/06/14 10:41:17 itojun Exp $ */ + /* * heavily modified by Yoshifumi Nishida <nishida@sfc.wide.ad.jp>. * then, completely rewrote by Jun-ichiro itojun Itoh <itojun@itojun.org>, @@ -48,15 +51,13 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ #include <crypto/des/des_locl.h> -#define panic(x) {printf(x); return;} +#define panic(x) do {printf(x); return EINVAL;} while (0) -void des_cbc_encrypt(m0, skip, length, schedule, ivec, mode) +int des_cbc_encrypt(m0, skip, length, schedule, ivec, mode) struct mbuf *m0; size_t skip; size_t length; @@ -75,19 +76,19 @@ void des_cbc_encrypt(m0, skip, length, schedule, ivec, mode) /* sanity checks */ if (m0->m_pkthdr.len < skip) { printf("mbuf length < skip\n"); - return; + return EINVAL; } if (m0->m_pkthdr.len < length) { printf("mbuf length < encrypt length\n"); - return; + return EINVAL; } if (m0->m_pkthdr.len < skip + length) { printf("mbuf length < skip + encrypt length\n"); - return; + return EINVAL; } if (length % 8) { printf("length is not multiple of 8\n"); - return; + return EINVAL; } m = m0; @@ -142,7 +143,7 @@ void des_cbc_encrypt(m0, skip, length, schedule, ivec, mode) while (in - &inbuf[0] < 8) { if (!p) panic("mbuf chain?\n"); - + *in++ = *p++; noff++; if (noff < n->m_len) @@ -325,4 +326,6 @@ void des_cbc_encrypt(m0, skip, length, schedule, ivec, mode) length -= 8; } } + + return 0; } diff --git a/sys/crypto/des/des_ecb.c b/sys/crypto/des/des_ecb.c index 9e74d6c..d828b91 100644 --- a/sys/crypto/des/des_ecb.c +++ b/sys/crypto/des/des_ecb.c @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: des_ecb.c,v 1.3 2000/03/27 04:36:33 sumikawa Exp $ */ + /* crypto/des/ecb_enc.c */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,8 +46,6 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ #include <crypto/des/des_locl.h> @@ -67,7 +68,7 @@ char *des_options() return("des(idx,long)"); #endif } - + void des_ecb_encrypt(input, output, ks, encrypt) des_cblock (*input); diff --git a/sys/crypto/des/des_locl.h b/sys/crypto/des/des_locl.h index ff49cc7..ae6e828 100644 --- a/sys/crypto/des/des_locl.h +++ b/sys/crypto/des/des_locl.h @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: des_locl.h,v 1.4 2000/03/27 04:43:46 sumikawa Exp $ */ + /* lib/des/des_locl.h */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,8 +46,6 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING * @@ -60,11 +61,11 @@ #include <sys/systm.h> #ifndef HEADER_DES_LOCL_H -#define HEADER_DES_LOCL_H +#define HEADER_DES_LOCL_H #if defined(WIN32) || defined(WIN16) #ifndef MSDOS -#define MSDOS +#define MSDOS #endif #endif @@ -89,7 +90,7 @@ #include <time.h> #include <io.h> #ifndef RAND -#define RAND +#define RAND #endif #undef NOPROTO #endif @@ -105,7 +106,7 @@ #endif #ifndef RAND -#define RAND +#define RAND #endif #ifdef linux @@ -113,13 +114,13 @@ #endif #ifdef MSDOS -#define getpid() 2 -#define RAND +#define getpid() 2 +#define RAND #undef NOPROTO #endif #if defined(NOCONST) -#define const +#define const #endif #ifdef __STDC__ @@ -127,24 +128,24 @@ #endif #ifdef RAND -#define srandom(s) srand(s) -#define random rand +#define srandom(s) srand(s) +#define random rand #endif -#define ITERATIONS 16 -#define HALF_ITERATIONS 8 +#define ITERATIONS 16 +#define HALF_ITERATIONS 8 /* used in des_read and des_write */ -#define MAXWRITE (1024*16) -#define BSIZE (MAXWRITE+4) +#define MAXWRITE (1024*16) +#define BSIZE (MAXWRITE+4) -#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ +#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ l|=((DES_LONG)(*((c)++)))<< 8L, \ l|=((DES_LONG)(*((c)++)))<<16L, \ l|=((DES_LONG)(*((c)++)))<<24L) /* NOTE - c is not incremented as per c2l */ -#define c2ln(c,l1,l2,n) { \ +#define c2ln(c,l1,l2,n) { \ c+=n; \ l1=l2=0; \ switch (n) { \ @@ -159,27 +160,27 @@ } \ } -#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ +#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ *((c)++)=(unsigned char)(((l)>>24L)&0xff)) /* replacements for htonl and ntohl since I have no idea what to do * when faced with machines with 8 byte longs. */ -#define HDRSIZE 4 +#define HDRSIZE 4 -#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \ +#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \ l|=((DES_LONG)(*((c)++)))<<16L, \ l|=((DES_LONG)(*((c)++)))<< 8L, \ l|=((DES_LONG)(*((c)++)))) -#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ +#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ *((c)++)=(unsigned char)(((l) )&0xff)) /* NOTE - c is not incremented as per l2c */ -#define l2cn(l1,l2,c,n) { \ +#define l2cn(l1,l2,c,n) { \ c+=n; \ switch (n) { \ case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ @@ -207,7 +208,7 @@ * bytes, probably an issue of accessing non-word aligned objects :-( */ #ifdef DES_PTR -#define D_ENCRYPT(L,R,S) { \ +#define D_ENCRYPT(L,R,S) { \ u=((R^s[S ])<<2); \ t= R^s[S+1]; \ t=ROTATE(t,2); \ @@ -222,7 +223,7 @@ *(DES_LONG *)((unsigned char *)des_SP+0x600+((u>>24)&0xfc))); } #else /* original version */ #ifdef undef -#define D_ENCRYPT(L,R,S) \ +#define D_ENCRYPT(L,R,S) \ U.l=R^s[S+1]; \ T.s[0]=((U.s[0]>>4)|(U.s[1]<<12))&0x3f3f; \ T.s[1]=((U.s[1]>>4)|(U.s[0]<<12))&0x3f3f; \ @@ -236,7 +237,7 @@ des_SPtrans[4][(U.c[2])]| \ des_SPtrans[6][(U.c[3])]; #else -#define D_ENCRYPT(Q,R,S) {\ +#define D_ENCRYPT(Q,R,S) {\ u=(R^s[S ]); \ t=R^s[S+1]; \ t=ROTATE(t,4); \ @@ -288,11 +289,11 @@ I first got ~42 operations without xors. When I remembered how to use xors :-) I got it to its final state. */ -#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ +#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ (b)^=(t),\ (a)^=((t)<<(n))) -#define IP(l,r) \ +#define IP(l,r) \ { \ register DES_LONG tt; \ PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \ @@ -302,7 +303,7 @@ PERM_OP(r,l,tt, 1,0x55555555L); \ } -#define FP(l,r) \ +#define FP(l,r) \ { \ register DES_LONG tt; \ PERM_OP(l,r,tt, 1,0x55555555L); \ @@ -315,10 +316,10 @@ /* -#define mbuf2char(i_mbuf, i_index, in) \ +#define mbuf2char(i_mbuf, i_index, in) \ { \ - register int i; \ - struct mbuf *m; \ + register int i; \ + struct mbuf *m; \ char *buf; \ m = i_mbuf; \ for (i = 0; i < 8; i ++){ \ @@ -330,10 +331,10 @@ } -#define char2mbuf(o_mbuf, o_index, out) \ +#define char2mbuf(o_mbuf, o_index, out) \ { \ - register int i; \ - struct mbuf *m; \ + register int i; \ + struct mbuf *m; \ char *buf; \ m = o_mbuf; \ for (i = 0; i < 8; i ++){ \ diff --git a/sys/crypto/des/des_setkey.c b/sys/crypto/des/des_setkey.c index 9747b52..48d13fc 100644 --- a/sys/crypto/des/des_setkey.c +++ b/sys/crypto/des/des_setkey.c @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: des_setkey.c,v 1.3 2000/03/27 04:36:33 sumikawa Exp $ */ + /* crypto/des/set_key.c */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,8 +46,6 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ /* set_key.c v 1.4 eay 24/9/91 @@ -97,7 +98,7 @@ des_cblock (*key); * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference * (and actual cblock values). */ -#define NUM_WEAK_KEY 16 +#define NUM_WEAK_KEY 16 static des_cblock weak_keys[NUM_WEAK_KEY]={ /* weak keys */ {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, @@ -142,7 +143,7 @@ des_cblock (*key); * (a)=((a)^((t)<<(n)))) */ -#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ +#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ (a)=(a)^(t)^(t>>(16-(n)))) /* return 0 if key parity is odd (correct), @@ -223,7 +224,7 @@ des_key_schedule schedule; /* table contained 0213 4657 */ *(k++)=((t<<16L)|(s&0x0000ffffL))&0xffffffffL; s= ((s>>16L)|(t&0xffff0000L)); - + s=(s<<4L)|(s>>28L); *(k++)=s&0xffffffffL; } diff --git a/sys/crypto/des/podd.h b/sys/crypto/des/podd.h index a0efc55..fb54c39 100644 --- a/sys/crypto/des/podd.h +++ b/sys/crypto/des/podd.h @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: podd.h,v 1.3 2000/03/27 04:36:34 sumikawa Exp $ */ + /* crypto/des/podd.h */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,8 +46,6 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ static const unsigned char odd_parity[256]={ diff --git a/sys/crypto/des/sk.h b/sys/crypto/des/sk.h index 1a1469c..24bde96 100644 --- a/sys/crypto/des/sk.h +++ b/sys/crypto/des/sk.h @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: sk.h,v 1.3 2000/03/27 04:36:34 sumikawa Exp $ */ + /* crypto/des/sk.h */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,8 +46,6 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ static const DES_LONG des_skb[8][64]={ diff --git a/sys/crypto/des/spr.h b/sys/crypto/des/spr.h index c340f58..606e12b 100644 --- a/sys/crypto/des/spr.h +++ b/sys/crypto/des/spr.h @@ -1,3 +1,6 @@ +/* $FreeBSD$ */ +/* $KAME: spr.h,v 1.3 2000/03/27 04:36:35 sumikawa Exp $ */ + /* crypto/des/spr.h */ /* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au) * All rights reserved. @@ -43,8 +46,6 @@ * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] - * - * $FreeBSD$ */ static const DES_LONG des_SPtrans[8][64]={ |