freebsd-nq/eBones/des/3cbc_enc.c
Geoff Rehmet 60643d379b Initial import of eBones.
(Including all changes for FreeBSD - importing the original eBones distribution
would be too complex at this stage, since I don't have access to Piero's 
CVS.)
(If you want to include eBones in your system, don't forget to include
MAKE_EBONES in /etc/make.conf.)
(This stuff is now also suppable from braae.ru.ac.za.)

Bones originally from MIT SIPB.
Original port to FreeBSD 1.x  by Piero Serini.
Moved to FreeBSD 2.0 by Doug Rabson and Geoff Rehmet.
Nice bug fixes from Doug Rabson.
1994-09-30 14:50:09 +00:00

59 lines
1.4 KiB
C

/* 3cbc_enc.c */
/* Copyright (C) 1993 Eric Young - see README for more details */
/*-
* $Id: 3cbc_enc.c,v 1.2 1994/07/19 19:21:37 g89r4222 Exp $
*/
#include "des_locl.h"
int des_3cbc_encrypt(input,output,length,ks1,ks2,iv1,iv2,encrypt)
des_cblock *input;
des_cblock *output;
long length;
des_key_schedule ks1,ks2;
des_cblock *iv1,*iv2;
int encrypt;
{
int off=length/8-1;
des_cblock niv1,niv2;
printf("3cbc\n");
xp(iv1);
xp(iv1);
xp(iv2);
xp(input);
if (encrypt == DES_ENCRYPT)
{
des_cbc_encrypt(input,output,length,ks1,iv1,encrypt);
if (length >= sizeof(des_cblock))
bcopy(output[off],niv1,sizeof(des_cblock));
des_cbc_encrypt(output,output,length,ks2,iv1,!encrypt);
des_cbc_encrypt(output,output,length,ks1,iv2, encrypt);
if (length >= sizeof(des_cblock))
bcopy(output[off],niv2,sizeof(des_cblock));
bcopy(niv1,*iv1,sizeof(des_cblock));
}
else
{
if (length >= sizeof(des_cblock))
bcopy(input[off],niv1,sizeof(des_cblock));
des_cbc_encrypt(input,output,length,ks1,iv1,encrypt);
des_cbc_encrypt(output,output,length,ks2,iv2,!encrypt);
if (length >= sizeof(des_cblock))
bcopy(output[off],niv2,sizeof(des_cblock));
des_cbc_encrypt(output,output,length,ks1,iv2, encrypt);
}
bcopy(niv1,iv1,sizeof(des_cblock));
bcopy(niv2,iv2,sizeof(des_cblock));
xp(iv1);
xp(iv1);
xp(iv2);
xp(output);
return(0);
}
xp(a)
unsigned char *a;
{ int i; for(i=0; i<8; i++) printf("%02X",a[i]);printf("\n");}