Updated to libdes 4.01
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1923 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
/* lib/des/enc_read.c */
|
||||
/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
|
||||
/* crypto/des/enc_read.c */
|
||||
/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of an SSL implementation written
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@mincom.oz.au).
|
||||
* The implementation was written so as to conform with Netscapes SSL
|
||||
* specification. This library and applications are
|
||||
* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
|
||||
* as long as the following conditions are aheared to.
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@mincom.oz.au).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed. If this code is used in a product,
|
||||
* Eric Young should be given attribution as the author of the parts used.
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
@@ -25,7 +30,13 @@
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Eric Young (eay@mincom.oz.au)
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@mincom.oz.au)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@mincom.oz.au)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
@@ -50,7 +61,7 @@
|
||||
#include "des_locl.h"
|
||||
|
||||
/* This has some uglies in it but it works - even over sockets. */
|
||||
extern int errno;
|
||||
/*extern int errno;*/
|
||||
int des_rw_mode=DES_PCBC_MODE;
|
||||
|
||||
int des_enc_read(fd, buf, len, sched, iv)
|
||||
@@ -62,17 +73,33 @@ des_cblock (*iv);
|
||||
{
|
||||
/* data to be unencrypted */
|
||||
int net_num=0;
|
||||
unsigned char net[BSIZE];
|
||||
static unsigned char *net=NULL;
|
||||
/* extra unencrypted data
|
||||
* for when a block of 100 comes in but is des_read one byte at
|
||||
* a time. */
|
||||
static char unnet[BSIZE];
|
||||
static char *unnet=NULL;
|
||||
static int unnet_start=0;
|
||||
static int unnet_left=0;
|
||||
static char *tmpbuf=NULL;
|
||||
int i;
|
||||
long num=0,rnum;
|
||||
unsigned char *p;
|
||||
|
||||
if (tmpbuf == NULL)
|
||||
{
|
||||
tmpbuf=(char *)malloc(BSIZE);
|
||||
if (tmpbuf == NULL) return(-1);
|
||||
}
|
||||
if (net == NULL)
|
||||
{
|
||||
net=(unsigned char *)malloc(BSIZE);
|
||||
if (net == NULL) return(-1);
|
||||
}
|
||||
if (unnet == NULL)
|
||||
{
|
||||
unnet=(char *)malloc(BSIZE);
|
||||
if (unnet == NULL) return(-1);
|
||||
}
|
||||
/* left over data from last decrypt */
|
||||
if (unnet_left != 0)
|
||||
{
|
||||
@@ -102,7 +129,6 @@ des_cblock (*iv);
|
||||
if (len > MAXWRITE) len=MAXWRITE;
|
||||
|
||||
/* first - get the length */
|
||||
net_num=0;
|
||||
while (net_num < HDRSIZE)
|
||||
{
|
||||
i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num);
|
||||
@@ -113,7 +139,7 @@ des_cblock (*iv);
|
||||
|
||||
/* we now have at net_num bytes in net */
|
||||
p=net;
|
||||
num=0;
|
||||
/* num=0; */
|
||||
n2l(p,num);
|
||||
/* num should be rounded up to the next group of eight
|
||||
* we make sure that we have read a multiple of 8 bytes from the net.
|
||||
@@ -135,14 +161,14 @@ des_cblock (*iv);
|
||||
if (len < num)
|
||||
{
|
||||
if (des_rw_mode & DES_PCBC_MODE)
|
||||
pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
|
||||
des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
|
||||
num,sched,iv,DES_DECRYPT);
|
||||
else
|
||||
cbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
|
||||
des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
|
||||
num,sched,iv,DES_DECRYPT);
|
||||
memcpy(buf,unnet,(unsigned int)len);
|
||||
unnet_start=len;
|
||||
unnet_left=num-len;
|
||||
unnet_left=(int)num-len;
|
||||
|
||||
/* The following line is done because we return num
|
||||
* as the number of bytes read. */
|
||||
@@ -157,14 +183,13 @@ des_cblock (*iv);
|
||||
* FIXED - Should be ok now 18-9-90 - eay */
|
||||
if (len < rnum)
|
||||
{
|
||||
char tmpbuf[BSIZE];
|
||||
|
||||
if (des_rw_mode & DES_PCBC_MODE)
|
||||
pcbc_encrypt((des_cblock *)net,
|
||||
des_pcbc_encrypt((des_cblock *)net,
|
||||
(des_cblock *)tmpbuf,
|
||||
num,sched,iv,DES_DECRYPT);
|
||||
else
|
||||
cbc_encrypt((des_cblock *)net,
|
||||
des_cbc_encrypt((des_cblock *)net,
|
||||
(des_cblock *)tmpbuf,
|
||||
num,sched,iv,DES_DECRYPT);
|
||||
|
||||
@@ -175,15 +200,15 @@ des_cblock (*iv);
|
||||
else
|
||||
{
|
||||
if (des_rw_mode & DES_PCBC_MODE)
|
||||
pcbc_encrypt((des_cblock *)net,
|
||||
des_pcbc_encrypt((des_cblock *)net,
|
||||
(des_cblock *)buf,num,sched,iv,
|
||||
DES_DECRYPT);
|
||||
else
|
||||
cbc_encrypt((des_cblock *)net,
|
||||
des_cbc_encrypt((des_cblock *)net,
|
||||
(des_cblock *)buf,num,sched,iv,
|
||||
DES_DECRYPT);
|
||||
}
|
||||
}
|
||||
return(num);
|
||||
return((int)num);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user