Finally(?) fix DES stuff.

This commit is contained in:
Ben Laurie 1999-02-13 21:49:34 +00:00
parent c09c3c4b2f
commit 08853ba82d
13 changed files with 128 additions and 128 deletions

View file

@ -77,6 +77,7 @@ my %table=(
# A few of my development configs
"purify", "purify gcc:-g -DPURIFY -Wall:-lsocket -lnsl::::",
"debug", "gcc:-DBN_DEBUG -DREF_CHECK -DCRYPTO_MDEBUG -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror:-lefence::::",
"debug-ben", "gcc:-DBN_DEBUG -DREF_CHECK -DCRYPTO_MDEBUG -Wformat -Wshadow -Werror:::::",
"debug-rse","gcc:-DTERMIOS -DL_ENDIAN -O -g -ggdb3 -m486 -Wall::BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_out_asm",
"dist", "cc:-O -DNOPROTO::::",

View file

@ -1190,7 +1190,7 @@ err:
}
static int certify(xret,infile,pkey,x509,dgst,policy,db,serial,startdate,days,
batch,ext_sect,conf,verbose)
batch,ext_sect,lconf,verbose)
X509 **xret;
char *infile;
EVP_PKEY *pkey;
@ -1203,7 +1203,7 @@ char *startdate;
int days;
int batch;
char *ext_sect;
LHASH *conf;
LHASH *lconf;
int verbose;
{
X509_REQ *req=NULL;
@ -1252,7 +1252,7 @@ int verbose;
BIO_printf(bio_err,"Signature ok\n");
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,
days,batch,verbose,req,ext_sect,conf);
days,batch,verbose,req,ext_sect,lconf);
err:
if (req != NULL) X509_REQ_free(req);
@ -1261,7 +1261,7 @@ err:
}
static int certify_cert(xret,infile,pkey,x509,dgst,policy,db,serial,startdate,
days, batch,ext_sect,conf,verbose)
days,batch,ext_sect,lconf,verbose)
X509 **xret;
char *infile;
EVP_PKEY *pkey;
@ -1274,7 +1274,7 @@ char *startdate;
int days;
int batch;
char *ext_sect;
LHASH *conf;
LHASH *lconf;
int verbose;
{
X509 *req=NULL;
@ -1326,7 +1326,7 @@ int verbose;
goto err;
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,days,
batch,verbose,rreq,ext_sect,conf);
batch,verbose,rreq,ext_sect,lconf);
err:
if (rreq != NULL) X509_REQ_free(rreq);
@ -1336,7 +1336,7 @@ err:
}
static int do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,days,
batch,verbose,req, ext_sect,conf)
batch,verbose,req,ext_sect,lconf)
X509 **xret;
EVP_PKEY *pkey;
X509 *x509;
@ -1350,7 +1350,7 @@ int batch;
int verbose;
X509_REQ *req;
char *ext_sect;
LHASH *conf;
LHASH *lconf;
{
X509_NAME *name=NULL,*CAname=NULL,*subject=NULL;
ASN1_UTCTIME *tm,*tmptm;
@ -1687,7 +1687,7 @@ again2:
ctx.crl = NULL;
ctx.flags = 0;
if(!X509V3_EXT_add_conf(conf, &ctx, ext_sect, ret)) goto err;
if(!X509V3_EXT_add_conf(lconf, &ctx, ext_sect, ret)) goto err;
}
@ -1811,7 +1811,7 @@ int output_der;
}
static int certify_spkac(xret,infile,pkey,x509,dgst,policy,db,serial,
startdate,days,ext_sect,conf,verbose)
startdate,days,ext_sect,lconf,verbose)
X509 **xret;
char *infile;
EVP_PKEY *pkey;
@ -1823,7 +1823,7 @@ BIGNUM *serial;
char *startdate;
int days;
char *ext_sect;
LHASH *conf;
LHASH *lconf;
int verbose;
{
STACK *sk=NULL;
@ -1969,7 +1969,7 @@ int verbose;
X509_REQ_set_pubkey(req,pktmp);
EVP_PKEY_free(pktmp);
ok=do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,
days,1,verbose,req,ext_sect,conf);
days,1,verbose,req,ext_sect,lconf);
err:
if (req != NULL) X509_REQ_free(req);
if (parms != NULL) CONF_free(parms);

View file

@ -471,6 +471,8 @@ ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigne
int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
/* for the is_set parameter to i2d_ASN1_SET */
#define IS_SEQUENCE 0

View file

@ -63,7 +63,7 @@ const unsigned char *in;
des_cblock out;
long length;
des_key_schedule schedule;
des_cblock iv;
const des_cblock iv;
{
register DES_LONG tout0,tout1,tin0,tin1;
register long l=length;

View file

@ -80,6 +80,8 @@ extern "C" {
#endif
typedef unsigned char des_cblock[8];
typedef unsigned char *des_cblocks; /* Unfortunately there's no way to say that
we want a multiple of 8 */
typedef struct des_ks_struct
{
union {
@ -151,45 +153,58 @@ extern int des_set_weak_key_flag; /* set the weak key flag */
#endif
#ifndef NOPROTO
char *des_options(void);
void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
des_key_schedule ks1,des_key_schedule ks2,
des_key_schedule ks3, int enc);
DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
long length,des_key_schedule schedule,des_cblock *ivec);
void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
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);
void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
des_key_schedule schedule,des_cblock *ivec,
des_cblock *inw,des_cblock *outw,int enc);
void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
long length,des_key_schedule schedule,des_cblock *ivec,int enc);
void des_ecb_encrypt(des_cblock *input,des_cblock *output,
des_key_schedule ks,int enc);
void des_ecb3_encrypt(const unsigned char *input,unsigned char *output,
des_key_schedule ks1,des_key_schedule ks2,
des_key_schedule ks3, int enc);
DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock output,
long length,des_key_schedule schedule,
const des_cblock ivec);
void des_cbc_encrypt(const unsigned char *input,unsigned char *output,
long length,des_key_schedule schedule,des_cblock ivec,
int enc);
void des_ncbc_encrypt(const unsigned char *input,unsigned char *output,
long length,des_key_schedule schedule,des_cblock ivec,
int enc);
void des_xcbc_encrypt(const unsigned char *input,unsigned char *output,
long length,des_key_schedule schedule,des_cblock ivec,
const des_cblock inw,const des_cblock outw,int enc);
void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
long length,des_key_schedule schedule,des_cblock ivec,
int enc);
void des_ecb_encrypt(const des_cblock input,des_cblock output,
des_key_schedule ks,int enc);
void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
des_key_schedule ks2, des_key_schedule ks3);
void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
des_key_schedule ks2, des_key_schedule ks3);
void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
long length, des_key_schedule ks1, des_key_schedule ks2,
des_key_schedule ks3, des_cblock *ivec, int enc);
void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
long length, des_key_schedule ks1, des_key_schedule ks2,
des_key_schedule ks3, des_cblock *ivec, int *num, int enc);
void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
long length, des_key_schedule ks1, des_key_schedule ks2,
des_key_schedule ks3, des_cblock *ivec, int *num);
void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
long length,
des_key_schedule ks1,des_key_schedule ks2,
des_key_schedule ks3,des_cblock ivec,int enc);
void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
long length,
des_key_schedule ks1,des_key_schedule ks2,
des_key_schedule ks3,
des_cblock ivec1,des_cblock ivec2,
int enc);
void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
long length,des_key_schedule ks1,
des_key_schedule ks2,des_key_schedule ks3,
des_cblock ivec,int *num,int enc);
void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
long length,des_key_schedule ks1,
des_key_schedule ks2,des_key_schedule ks3,
des_cblock ivec,int *num);
void des_xwhite_in2out(des_cblock (*des_key), des_cblock (*in_white),
des_cblock (*out_white));
void des_xwhite_in2out(const des_cblock des_key,const des_cblock in_white,
des_cblock out_white);
int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
des_cblock *iv);
int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
des_cblock *iv);
des_cblock iv);
int des_enc_write(int fd,const char *buf,int len,des_key_schedule sched,
des_cblock iv);
char *des_fcrypt(const char *buf,const char *salt, char *ret);
#if defined(PERL5) || defined(__FreeBSD__)
char *des_crypt(const char *buf,const char *salt);
@ -202,32 +217,34 @@ char *crypt(const char *buf,const char *salt);
char *crypt();
#endif
#endif
void des_ofb_encrypt(unsigned char *in,unsigned char *out,
int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
des_key_schedule schedule,des_cblock *ivec,int enc);
DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
long length,int out_count,des_cblock *seed);
void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
long length,des_key_schedule schedule,des_cblock ivec);
void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
long length,des_key_schedule schedule,des_cblock ivec,
int enc);
DES_LONG des_quad_cksum(const unsigned char *input,des_cblocks output,
long length,int out_count,des_cblock seed);
void des_random_seed(des_cblock key);
void des_random_key(des_cblock ret);
int des_read_password(des_cblock *key,char *prompt,int verify);
int des_read_2passwords(des_cblock *key1,des_cblock *key2,
char *prompt,int verify);
int des_read_pw_string(char *buf,int length,char *prompt,int verify);
void des_set_odd_parity(des_cblock *key);
int des_is_weak_key(des_cblock *key);
int des_set_key(des_cblock *key,des_key_schedule schedule);
int des_key_sched(des_cblock *key,des_key_schedule schedule);
void des_string_to_key(char *str,des_cblock *key);
void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
des_key_schedule schedule, des_cblock *ivec, int *num);
int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify);
int des_read_password(des_cblock key,const char *prompt,int verify);
int des_read_2passwords(des_cblock key1,des_cblock key2,
const char *prompt,int verify);
int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
void des_set_odd_parity(des_cblock key);
int des_is_weak_key(const des_cblock key);
int des_set_key(const des_cblock key,des_key_schedule schedule);
int des_key_sched(const des_cblock key,des_key_schedule schedule);
void des_string_to_key(const char *str,des_cblock key);
void des_string_to_2keys(const char *str,des_cblock key1,des_cblock key2);
void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
des_key_schedule schedule,des_cblock ivec,int *num,
int enc);
void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
des_key_schedule schedule,des_cblock ivec,int *num);
int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
/* Extra functions from Mark Murray <mark@grondar.za> */
void des_cblock_print_file(des_cblock *cb, FILE *fp);
void des_cblock_print_file(const des_cblock cb, FILE *fp);
/* The following functions are not in the normal unix build or the
* SSLeay build. When using the SSLeay build, use RAND_seed()
* and RAND_bytes() instead. */

View file

@ -301,24 +301,21 @@ des_key_schedule ks3;
#ifndef DES_DEFAULT_OPTIONS
void des_ncbc_encrypt(input, output, length, schedule, ivec, enc)
des_cblock (*input);
des_cblock (*output);
void des_ncbc_encrypt(in, out, length, schedule, ivec, enc)
const unsigned char *in;
unsigned char *out;
long length;
des_key_schedule schedule;
des_cblock (*ivec);
des_cblock ivec;
int enc;
{
register DES_LONG tin0,tin1;
register DES_LONG tout0,tout1,xor0,xor1;
register unsigned char *in,*out;
register long l=length;
DES_LONG tin[2];
unsigned char *iv;
in=(unsigned char *)input;
out=(unsigned char *)output;
iv=(unsigned char *)ivec;
iv=ivec;
if (enc)
{
@ -343,7 +340,7 @@ int enc;
tout0=tin[0]; l2c(tout0,out);
tout1=tin[1]; l2c(tout1,out);
}
iv=(unsigned char *)ivec;
iv=ivec;
l2c(tout0,iv);
l2c(tout1,iv);
}
@ -375,7 +372,7 @@ int enc;
xor1=tin1;
}
iv=(unsigned char *)ivec;
iv=ivec;
l2c(xor0,iv);
l2c(xor1,iv);
}
@ -384,13 +381,13 @@ int enc;
}
void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc)
des_cblock (*input);
des_cblock (*output);
const unsigned char *input;
unsigned char *output;
long length;
des_key_schedule ks1;
des_key_schedule ks2;
des_key_schedule ks3;
des_cblock (*ivec);
des_cblock ivec;
int enc;
{
register DES_LONG tin0,tin1;

View file

@ -103,8 +103,8 @@ char *des_options()
void des_ecb_encrypt(in, out, ks, enc)
const unsigned char *in;
unsigned char *out;
const des_cblock in;
des_cblock out;
des_key_schedule ks;
int enc;
{

View file

@ -179,7 +179,7 @@ static jmp_buf save;
int des_read_pw_string(buf, length, prompt, verify)
char *buf;
int length;
char *prompt;
const char *prompt;
int verify;
{
char buff[BUFSIZ];

View file

@ -99,7 +99,7 @@ int enc;
memcpy(&(ctx->oiv[0]),iv,8);
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL)
des_set_key((des_cblock *)key,ctx->c.des_ks);
des_set_key(key,ctx->c.des_ks);
}
static void des_cbc_cipher(ctx,out,in,inl)
@ -108,9 +108,5 @@ unsigned char *out;
unsigned char *in;
unsigned int inl;
{
des_ncbc_encrypt(
(des_cblock *)in,(des_cblock *)out,
(long)inl, ctx->c.des_ks,
(des_cblock *)&(ctx->iv[0]),
ctx->encrypt);
des_ncbc_encrypt(in,out,inl,ctx->c.des_ks,&(ctx->iv[0]),ctx->encrypt);
}

View file

@ -123,8 +123,8 @@ int enc;
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL)
{
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2);
des_set_key(key,ctx->c.des_ede.ks1);
des_set_key(&(key[8]),ctx->c.des_ede.ks2);
memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1));
@ -144,9 +144,9 @@ int enc;
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL)
{
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2);
des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3);
des_set_key(key,ctx->c.des_ede.ks1);
des_set_key(&(key[8]),ctx->c.des_ede.ks2);
des_set_key(&(key[16]),ctx->c.des_ede.ks3);
}
}
@ -156,11 +156,9 @@ unsigned char *out;
unsigned char *in;
unsigned int inl;
{
des_ede3_cfb64_encrypt(
in,out,(long)inl,
ctx->c.des_ede.ks1,
ctx->c.des_ede.ks2,
ctx->c.des_ede.ks3,
(des_cblock *)&(ctx->iv[0]),
&ctx->num,ctx->encrypt);
des_ede3_cfb64_encrypt(in,out,(long)inl,
ctx->c.des_ede.ks1,
ctx->c.des_ede.ks2,
ctx->c.des_ede.ks3,
&(ctx->iv[0]),&ctx->num,ctx->encrypt);
}

View file

@ -123,8 +123,8 @@ int enc;
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL)
{
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2);
des_set_key(key,ctx->c.des_ede.ks1);
des_set_key(&(key[8]),ctx->c.des_ede.ks2);
memcpy( (char *)ctx->c.des_ede.ks3,
(char *)ctx->c.des_ede.ks1,
sizeof(ctx->c.des_ede.ks1));
@ -144,9 +144,9 @@ int enc;
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL)
{
des_set_key((des_cblock *)key,ctx->c.des_ede.ks1);
des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2);
des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3);
des_set_key(key,ctx->c.des_ede.ks1);
des_set_key(&(key[8]),ctx->c.des_ede.ks2);
des_set_key(&(key[16]),ctx->c.des_ede.ks3);
}
}
@ -156,10 +156,7 @@ unsigned char *out;
unsigned char *in;
unsigned int inl;
{
des_ede3_ofb64_encrypt(
in,out,
(long)inl,
ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
(des_cblock *)&(ctx->iv[0]),
&ctx->num);
des_ede3_ofb64_encrypt(in,out,inl,ctx->c.des_ede.ks1,
ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
&(ctx->iv[0]),&ctx->num);
}

View file

@ -101,7 +101,7 @@ int enc;
memcpy(&(ctx->oiv[0]),iv,8);
memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
if (key != NULL)
des_set_key((des_cblock *)key,ctx->c.des_ks);
des_set_key(key,ctx->c.des_ks);
}
static void des_ofb_cipher(ctx,out,in,inl)
@ -110,9 +110,5 @@ unsigned char *out;
unsigned char *in;
unsigned int inl;
{
des_ofb64_encrypt(
in,out,
(long)inl, ctx->c.des_ks,
(des_cblock *)&(ctx->iv[0]),
&ctx->num);
des_ofb64_encrypt(in,out,inl,ctx->c.des_ks,&(ctx->iv[0]),&ctx->num);
}

View file

@ -135,27 +135,23 @@ unsigned int len;
register DES_LONG tin0,tin1;
register DES_LONG ttin0,ttin1;
DES_LONG d[2],dd[2];
unsigned char *h,*hh;
des_key_schedule k;
unsigned char *p;
unsigned int i;
h= c->h;
hh= c->hh;
for (i=0; i<len; i+=8)
{
c2l(in,tin0); d[0]=dd[0]=tin0;
c2l(in,tin1); d[1]=dd[1]=tin1;
h[0]=(h[0]&0x9f)|0x40;
hh[0]=(hh[0]&0x9f)|0x20;
c->h[0]=(c->h[0]&0x9f)|0x40;
c->hh[0]=(c->hh[0]&0x9f)|0x20;
des_set_odd_parity(h);
des_set_key(h,k);
des_set_odd_parity(c->h);
des_set_key(c->h,k);
des_encrypt(d,k,1);
des_set_odd_parity(hh);
des_set_key(hh,k);
des_set_odd_parity(c->hh);
des_set_key(c->hh,k);
des_encrypt(dd,k,1);
ttin0=tin0^dd[0];
@ -163,10 +159,10 @@ unsigned int len;
tin0^=d[0];
tin1^=d[1];
p=h;
p=c->h;
l2c(tin0,p);
l2c(ttin1,p);
p=(unsigned char *)hh;
p=c->hh;
l2c(ttin0,p);
l2c(tin1,p);
}