Unify DES library: ncbc_enc.c wasn't used, but its content was almost
duplicated in cbc_enc.c (without IV updating) and in des_enc.c As pointed out by others on the openssl-dev list, des_cbc_encrypt (without IV updating; defined in cbc_enc.c) exists only for historical reasons: des_ncbc_encrypt should be used instead (and the caller does not have to manually update the IV). If des_cbc_enrypt is not needed for backwards compatibility, the definition of des_ncbc_encrypt should be put back into des_enc.c, and both cbc_enc.c and ncbc_enc.c can be deleted. If des_cbc_encrypt *is* needed for backwards compatibility, its behaviour obviously should not change (i.e., don't add IV updating).
This commit is contained in:
parent
df63a389a5
commit
3bcfce2881
crypto/des
@ -59,9 +59,9 @@
|
|||||||
#include "des_locl.h"
|
#include "des_locl.h"
|
||||||
|
|
||||||
/* HAS BUGS? DON'T USE - this is only present for use in des.c */
|
/* HAS BUGS? DON'T USE - this is only present for use in des.c */
|
||||||
void des_3cbc_encrypt(des_cblock (*input), des_cblock (*output), long length,
|
void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
|
||||||
des_key_schedule ks1, des_key_schedule ks2, des_cblock (*iv1),
|
des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1,
|
||||||
des_cblock (*iv2), int enc)
|
des_cblock *iv2, int enc)
|
||||||
{
|
{
|
||||||
int off=((int)length-1)/8;
|
int off=((int)length-1)/8;
|
||||||
long l8=((length+7)/8)*8;
|
long l8=((length+7)/8)*8;
|
||||||
|
@ -56,84 +56,6 @@
|
|||||||
* [including the GNU Public Licence.]
|
* [including the GNU Public Licence.]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "des_locl.h"
|
#define CBC_ENC_C__DONT_UPDATE_IV
|
||||||
|
|
||||||
/* Note that this is inconsistent with other DES functions in that it doesn't
|
|
||||||
update ivec */
|
|
||||||
void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
|
||||||
des_key_schedule schedule, des_cblock *ivec, int enc)
|
|
||||||
{
|
|
||||||
register DES_LONG tin0,tin1;
|
|
||||||
register DES_LONG tout0,tout1,xor0,xor1;
|
|
||||||
register long l=length;
|
|
||||||
DES_LONG tin[2];
|
|
||||||
unsigned char *iv;
|
|
||||||
|
|
||||||
iv = &(*ivec)[0];
|
|
||||||
|
|
||||||
if (enc)
|
|
||||||
{
|
|
||||||
c2l(iv,tout0);
|
|
||||||
c2l(iv,tout1);
|
|
||||||
for (l-=8; l>=0; l-=8)
|
|
||||||
{
|
|
||||||
c2l(in,tin0);
|
|
||||||
c2l(in,tin1);
|
|
||||||
tin0^=tout0; tin[0]=tin0;
|
|
||||||
tin1^=tout1; tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
|
|
||||||
tout0=tin[0]; l2c(tout0,out);
|
|
||||||
tout1=tin[1]; l2c(tout1,out);
|
|
||||||
}
|
|
||||||
if (l != -8)
|
|
||||||
{
|
|
||||||
c2ln(in,tin0,tin1,l+8);
|
|
||||||
tin0^=tout0; tin[0]=tin0;
|
|
||||||
tin1^=tout1; tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
|
|
||||||
tout0=tin[0]; l2c(tout0,out);
|
|
||||||
tout1=tin[1]; l2c(tout1,out);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
iv = &(*ivec)[0];
|
|
||||||
l2c(tout0,iv);
|
|
||||||
l2c(tout1,iv);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c2l(iv,xor0);
|
|
||||||
c2l(iv,xor1);
|
|
||||||
for (l-=8; l>=0; l-=8)
|
|
||||||
{
|
|
||||||
c2l(in,tin0); tin[0]=tin0;
|
|
||||||
c2l(in,tin1); tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
|
|
||||||
tout0=tin[0]^xor0;
|
|
||||||
tout1=tin[1]^xor1;
|
|
||||||
l2c(tout0,out);
|
|
||||||
l2c(tout1,out);
|
|
||||||
xor0=tin0;
|
|
||||||
xor1=tin1;
|
|
||||||
}
|
|
||||||
if (l != -8)
|
|
||||||
{
|
|
||||||
c2l(in,tin0); tin[0]=tin0;
|
|
||||||
c2l(in,tin1); tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
|
|
||||||
tout0=tin[0]^xor0;
|
|
||||||
tout1=tin[1]^xor1;
|
|
||||||
l2cn(tout0,tout1,out,l+8);
|
|
||||||
/* xor0=tin0;
|
|
||||||
xor1=tin1; */
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
iv = &(*ivec)[0];
|
|
||||||
l2c(xor0,iv);
|
|
||||||
l2c(xor1,iv);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
tin0=tin1=tout0=tout1=xor0=xor1=0;
|
|
||||||
tin[0]=tin[1]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#include "ncbc_enc.c" /* des_cbc_encrypt */
|
||||||
|
@ -289,79 +289,8 @@ void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
|
|||||||
|
|
||||||
#ifndef DES_DEFAULT_OPTIONS
|
#ifndef DES_DEFAULT_OPTIONS
|
||||||
|
|
||||||
void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
#undef CBC_ENC_C__DONT_UPDATE_IV
|
||||||
des_key_schedule schedule, des_cblock *ivec, int enc)
|
#include "ncbc_enc.c" /* des_ncbc_enrypt */
|
||||||
{
|
|
||||||
register DES_LONG tin0,tin1;
|
|
||||||
register DES_LONG tout0,tout1,xor0,xor1;
|
|
||||||
register long l=length;
|
|
||||||
DES_LONG tin[2];
|
|
||||||
unsigned char *iv;
|
|
||||||
|
|
||||||
iv = &(*ivec)[0];
|
|
||||||
|
|
||||||
if (enc)
|
|
||||||
{
|
|
||||||
c2l(iv,tout0);
|
|
||||||
c2l(iv,tout1);
|
|
||||||
for (l-=8; l>=0; l-=8)
|
|
||||||
{
|
|
||||||
c2l(in,tin0);
|
|
||||||
c2l(in,tin1);
|
|
||||||
tin0^=tout0; tin[0]=tin0;
|
|
||||||
tin1^=tout1; tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
|
|
||||||
tout0=tin[0]; l2c(tout0,out);
|
|
||||||
tout1=tin[1]; l2c(tout1,out);
|
|
||||||
}
|
|
||||||
if (l != -8)
|
|
||||||
{
|
|
||||||
c2ln(in,tin0,tin1,l+8);
|
|
||||||
tin0^=tout0; tin[0]=tin0;
|
|
||||||
tin1^=tout1; tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
|
|
||||||
tout0=tin[0]; l2c(tout0,out);
|
|
||||||
tout1=tin[1]; l2c(tout1,out);
|
|
||||||
}
|
|
||||||
iv = &(*ivec)[0];
|
|
||||||
l2c(tout0,iv);
|
|
||||||
l2c(tout1,iv);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c2l(iv,xor0);
|
|
||||||
c2l(iv,xor1);
|
|
||||||
for (l-=8; l>=0; l-=8)
|
|
||||||
{
|
|
||||||
c2l(in,tin0); tin[0]=tin0;
|
|
||||||
c2l(in,tin1); tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
|
|
||||||
tout0=tin[0]^xor0;
|
|
||||||
tout1=tin[1]^xor1;
|
|
||||||
l2c(tout0,out);
|
|
||||||
l2c(tout1,out);
|
|
||||||
xor0=tin0;
|
|
||||||
xor1=tin1;
|
|
||||||
}
|
|
||||||
if (l != -8)
|
|
||||||
{
|
|
||||||
c2l(in,tin0); tin[0]=tin0;
|
|
||||||
c2l(in,tin1); tin[1]=tin1;
|
|
||||||
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
|
|
||||||
tout0=tin[0]^xor0;
|
|
||||||
tout1=tin[1]^xor1;
|
|
||||||
l2cn(tout0,tout1,out,l+8);
|
|
||||||
xor0=tin0;
|
|
||||||
xor1=tin1;
|
|
||||||
}
|
|
||||||
|
|
||||||
iv = &(*ivec)[0];
|
|
||||||
l2c(xor0,iv);
|
|
||||||
l2c(xor1,iv);
|
|
||||||
}
|
|
||||||
tin0=tin1=tout0=tout1=xor0=xor1=0;
|
|
||||||
tin[0]=tin[1]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
|
void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
|
||||||
long length, des_key_schedule ks1, des_key_schedule ks2,
|
long length, des_key_schedule ks1, des_key_schedule ks2,
|
||||||
|
@ -58,19 +58,21 @@
|
|||||||
|
|
||||||
#include "des_locl.h"
|
#include "des_locl.h"
|
||||||
|
|
||||||
void des_ncbc_encrypt(des_cblock (*input), des_cblock (*output), long length,
|
#ifdef CBC_ENC_C__DONT_UPDATE_IV
|
||||||
des_key_schedule schedule, des_cblock (*ivec), int enc)
|
void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||||
|
des_key_schedule schedule, des_cblock *ivec, int enc)
|
||||||
|
#else
|
||||||
|
void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||||
|
des_key_schedule schedule, des_cblock *ivec, int enc)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
register DES_LONG tin0,tin1;
|
register DES_LONG tin0,tin1;
|
||||||
register DES_LONG tout0,tout1,xor0,xor1;
|
register DES_LONG tout0,tout1,xor0,xor1;
|
||||||
register unsigned char *in,*out;
|
|
||||||
register long l=length;
|
register long l=length;
|
||||||
DES_LONG tin[2];
|
DES_LONG tin[2];
|
||||||
unsigned char *iv;
|
unsigned char *iv;
|
||||||
|
|
||||||
in=(unsigned char *)input;
|
iv = &(*ivec)[0];
|
||||||
out=(unsigned char *)output;
|
|
||||||
iv=(unsigned char *)ivec;
|
|
||||||
|
|
||||||
if (enc)
|
if (enc)
|
||||||
{
|
{
|
||||||
@ -95,9 +97,11 @@ void des_ncbc_encrypt(des_cblock (*input), des_cblock (*output), long length,
|
|||||||
tout0=tin[0]; l2c(tout0,out);
|
tout0=tin[0]; l2c(tout0,out);
|
||||||
tout1=tin[1]; l2c(tout1,out);
|
tout1=tin[1]; l2c(tout1,out);
|
||||||
}
|
}
|
||||||
iv=(unsigned char *)ivec;
|
#ifndef CBC_ENC_C__DONT_UPDATE_IV
|
||||||
|
iv = &(*ivec)[0];
|
||||||
l2c(tout0,iv);
|
l2c(tout0,iv);
|
||||||
l2c(tout1,iv);
|
l2c(tout1,iv);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -115,11 +119,25 @@ void des_ncbc_encrypt(des_cblock (*input), des_cblock (*output), long length,
|
|||||||
xor0=tin0;
|
xor0=tin0;
|
||||||
xor1=tin1;
|
xor1=tin1;
|
||||||
}
|
}
|
||||||
iv=(unsigned char *)ivec;
|
if (l != -8)
|
||||||
|
{
|
||||||
|
c2l(in,tin0); tin[0]=tin0;
|
||||||
|
c2l(in,tin1); tin[1]=tin1;
|
||||||
|
des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
|
||||||
|
tout0=tin[0]^xor0;
|
||||||
|
tout1=tin[1]^xor1;
|
||||||
|
l2cn(tout0,tout1,out,l+8);
|
||||||
|
#ifndef CBC_ENC_C__DONT_UPDATE_IV
|
||||||
|
xor0=tin0;
|
||||||
|
xor1=tin1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifndef CBC_ENC_C__DONT_UPDATE_IV
|
||||||
|
iv = &(*ivec)[0];
|
||||||
l2c(xor0,iv);
|
l2c(xor0,iv);
|
||||||
l2c(xor1,iv);
|
l2c(xor1,iv);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
tin0=tin1=tout0=tout1=xor0=xor1=0;
|
tin0=tin1=tout0=tout1=xor0=xor1=0;
|
||||||
tin[0]=tin[1]=0;
|
tin[0]=tin[1]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user