1993-06-18 13:00:14 +00:00
|
|
|
/* cbc.c: This file contains the encryption routines for the ed line editor */
|
|
|
|
/*-
|
1994-02-01 00:36:28 +00:00
|
|
|
* Copyright (c) 1993 The Regents of the University of California.
|
1993-06-18 13:00:14 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1994-02-01 00:36:28 +00:00
|
|
|
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
|
|
|
* All rights reserved.
|
1993-06-18 13:00:14 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-06-30 05:13:54 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1993-06-18 13:00:14 +00:00
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
#include <sys/types.h>
|
1993-06-18 13:00:14 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <pwd.h>
|
1997-08-07 21:33:47 +00:00
|
|
|
#ifdef DES
|
|
|
|
#include <time.h>
|
2003-06-02 19:06:28 +00:00
|
|
|
#include <openssl/des.h>
|
|
|
|
#define ED_DES_INCLUDES
|
1997-08-07 21:33:47 +00:00
|
|
|
#endif
|
1993-06-18 13:00:14 +00:00
|
|
|
|
|
|
|
#include "ed.h"
|
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
|
1993-06-18 13:00:14 +00:00
|
|
|
/*
|
|
|
|
* BSD and System V systems offer special library calls that do
|
1994-02-01 00:36:28 +00:00
|
|
|
* block move_liness and fills, so if possible we take advantage of them
|
1993-06-18 13:00:14 +00:00
|
|
|
*/
|
|
|
|
#define MEMCPY(dest,src,len) memcpy((dest),(src),(len))
|
|
|
|
#define MEMZERO(dest,len) memset((dest), 0, (len))
|
|
|
|
|
|
|
|
/* Hide the calls to the primitive encryption routines. */
|
2002-07-31 16:52:16 +00:00
|
|
|
#define DES_XFORM(buf) \
|
2003-06-02 19:06:28 +00:00
|
|
|
DES_ecb_encrypt(buf, buf, &schedule, \
|
|
|
|
inverse ? DES_DECRYPT : DES_ENCRYPT);
|
1993-06-18 13:00:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* read/write - no error checking
|
|
|
|
*/
|
|
|
|
#define READ(buf, n, fp) fread(buf, sizeof(char), n, fp)
|
|
|
|
#define WRITE(buf, n, fp) fwrite(buf, sizeof(char), n, fp)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* global variables and related macros
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum { /* encrypt, decrypt, authenticate */
|
|
|
|
MODE_ENCRYPT, MODE_DECRYPT, MODE_AUTHENTICATE
|
|
|
|
} mode = MODE_ENCRYPT;
|
|
|
|
|
2003-06-03 17:03:48 +00:00
|
|
|
#ifdef DES
|
2003-06-02 19:06:28 +00:00
|
|
|
DES_cblock ivec; /* initialization vector */
|
|
|
|
DES_cblock pvec; /* padding vector */
|
2003-06-03 17:03:48 +00:00
|
|
|
#endif
|
2003-06-02 19:06:28 +00:00
|
|
|
|
1993-06-18 13:00:14 +00:00
|
|
|
char bits[] = { /* used to extract bits from a char */
|
|
|
|
'\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001'
|
|
|
|
};
|
2003-06-02 19:06:28 +00:00
|
|
|
|
1993-06-18 13:00:14 +00:00
|
|
|
int pflag; /* 1 to preserve parity bits */
|
|
|
|
|
2003-06-03 17:03:48 +00:00
|
|
|
#ifdef DES
|
2003-06-02 19:06:28 +00:00
|
|
|
DES_key_schedule schedule; /* expanded DES key */
|
2003-06-03 17:03:48 +00:00
|
|
|
#endif
|
2003-06-02 19:06:28 +00:00
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
unsigned char des_buf[8]; /* shared buffer for get_des_char/put_des_char */
|
|
|
|
int des_ct = 0; /* count for get_des_char/put_des_char */
|
|
|
|
int des_n = 0; /* index for put_des_char/get_des_char */
|
1993-06-18 13:00:14 +00:00
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
/* init_des_cipher: initialize DES */
|
1993-06-18 13:00:14 +00:00
|
|
|
void
|
2002-02-02 06:36:49 +00:00
|
|
|
init_des_cipher(void)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
|
|
|
#ifdef DES
|
|
|
|
int i;
|
|
|
|
|
|
|
|
des_ct = des_n = 0;
|
|
|
|
|
1995-03-19 13:29:28 +00:00
|
|
|
/* initialize the initialization vector */
|
1993-06-18 13:00:14 +00:00
|
|
|
MEMZERO(ivec, 8);
|
|
|
|
|
1999-05-08 10:22:15 +00:00
|
|
|
/* initialize the padding vector */
|
1993-06-18 13:00:14 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
2003-06-02 19:06:28 +00:00
|
|
|
pvec[i] = (char) (arc4random() % 256);
|
1993-06-18 13:00:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
/* get_des_char: return next char in an encrypted file */
|
|
|
|
int
|
2002-02-02 06:36:49 +00:00
|
|
|
get_des_char(FILE *fp)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
|
|
|
#ifdef DES
|
|
|
|
if (des_n >= des_ct) {
|
|
|
|
des_n = 0;
|
1994-02-01 00:36:28 +00:00
|
|
|
des_ct = cbc_decode(des_buf, fp);
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
return (des_ct > 0) ? des_buf[des_n++] : EOF;
|
1995-03-19 13:29:28 +00:00
|
|
|
#else
|
|
|
|
return (getc(fp));
|
1993-06-18 13:00:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
/* put_des_char: write a char to an encrypted file; return char written */
|
|
|
|
int
|
2002-02-02 06:36:49 +00:00
|
|
|
put_des_char(int c, FILE *fp)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
|
|
|
#ifdef DES
|
|
|
|
if (des_n == sizeof des_buf) {
|
1994-02-01 00:36:28 +00:00
|
|
|
des_ct = cbc_encode(des_buf, des_n, fp);
|
1993-06-18 13:00:14 +00:00
|
|
|
des_n = 0;
|
|
|
|
}
|
|
|
|
return (des_ct >= 0) ? (des_buf[des_n++] = c) : EOF;
|
1995-03-19 13:29:28 +00:00
|
|
|
#else
|
|
|
|
return (fputc(c, fp));
|
1993-06-18 13:00:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-02-01 00:36:28 +00:00
|
|
|
/* flush_des_file: flush an encrypted file's output; return status */
|
|
|
|
int
|
2002-02-02 06:36:49 +00:00
|
|
|
flush_des_file(FILE *fp)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
|
|
|
#ifdef DES
|
|
|
|
if (des_n == sizeof des_buf) {
|
1994-02-01 00:36:28 +00:00
|
|
|
des_ct = cbc_encode(des_buf, des_n, fp);
|
1993-06-18 13:00:14 +00:00
|
|
|
des_n = 0;
|
|
|
|
}
|
1994-02-01 00:36:28 +00:00
|
|
|
return (des_ct >= 0 && cbc_encode(des_buf, des_n, fp) >= 0) ? 0 : EOF;
|
1995-03-19 13:29:28 +00:00
|
|
|
#else
|
|
|
|
return (fflush(fp));
|
1993-06-18 13:00:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DES
|
|
|
|
/*
|
|
|
|
* get keyword from tty or stdin
|
|
|
|
*/
|
1994-02-01 00:36:28 +00:00
|
|
|
int
|
2002-02-02 06:36:49 +00:00
|
|
|
get_keyword(void)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
2001-08-06 22:01:31 +00:00
|
|
|
char *p; /* used to obtain the key */
|
2003-06-02 19:06:28 +00:00
|
|
|
DES_cblock msgbuf; /* I/O buffer */
|
1993-06-18 13:00:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get the key
|
|
|
|
*/
|
|
|
|
if (*(p = getpass("Enter key: "))) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy it, nul-padded, into the key area
|
|
|
|
*/
|
2003-06-02 19:06:28 +00:00
|
|
|
expand_des_key(msgbuf, p);
|
1993-06-18 13:00:14 +00:00
|
|
|
MEMZERO(p, _PASSWORD_LEN);
|
2003-06-02 19:06:28 +00:00
|
|
|
set_des_key(&msgbuf);
|
1993-06-18 13:00:14 +00:00
|
|
|
MEMZERO(msgbuf, sizeof msgbuf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print a warning message and, possibly, terminate
|
|
|
|
*/
|
|
|
|
void
|
2002-02-02 06:36:49 +00:00
|
|
|
des_error(const char *s)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
2001-08-06 22:01:31 +00:00
|
|
|
errmsg = s ? s : strerror(errno);
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* map a hex character to an integer
|
|
|
|
*/
|
1994-02-01 00:36:28 +00:00
|
|
|
int
|
2002-02-02 06:36:49 +00:00
|
|
|
hex_to_binary(int c, int radix)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
|
|
|
switch(c) {
|
|
|
|
case '0': return(0x0);
|
|
|
|
case '1': return(0x1);
|
|
|
|
case '2': return(radix > 2 ? 0x2 : -1);
|
|
|
|
case '3': return(radix > 3 ? 0x3 : -1);
|
|
|
|
case '4': return(radix > 4 ? 0x4 : -1);
|
|
|
|
case '5': return(radix > 5 ? 0x5 : -1);
|
|
|
|
case '6': return(radix > 6 ? 0x6 : -1);
|
|
|
|
case '7': return(radix > 7 ? 0x7 : -1);
|
|
|
|
case '8': return(radix > 8 ? 0x8 : -1);
|
|
|
|
case '9': return(radix > 9 ? 0x9 : -1);
|
|
|
|
case 'A': case 'a': return(radix > 10 ? 0xa : -1);
|
|
|
|
case 'B': case 'b': return(radix > 11 ? 0xb : -1);
|
|
|
|
case 'C': case 'c': return(radix > 12 ? 0xc : -1);
|
|
|
|
case 'D': case 'd': return(radix > 13 ? 0xd : -1);
|
|
|
|
case 'E': case 'e': return(radix > 14 ? 0xe : -1);
|
|
|
|
case 'F': case 'f': return(radix > 15 ? 0xf : -1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* invalid character
|
|
|
|
*/
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert the key to a bit pattern
|
2002-02-02 06:36:49 +00:00
|
|
|
* obuf bit pattern
|
|
|
|
* kbuf the key itself
|
1993-06-18 13:00:14 +00:00
|
|
|
*/
|
|
|
|
void
|
2002-02-02 06:36:49 +00:00
|
|
|
expand_des_key(char *obuf, char *kbuf)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
2001-08-06 22:01:31 +00:00
|
|
|
int i, j; /* counter in a for loop */
|
1993-06-18 13:00:14 +00:00
|
|
|
int nbuf[64]; /* used for hex/key translation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* leading '0x' or '0X' == hex key
|
|
|
|
*/
|
2001-08-06 22:01:31 +00:00
|
|
|
if (kbuf[0] == '0' && (kbuf[1] == 'x' || kbuf[1] == 'X')) {
|
|
|
|
kbuf = &kbuf[2];
|
1993-06-18 13:00:14 +00:00
|
|
|
/*
|
|
|
|
* now translate it, bombing on any illegal hex digit
|
|
|
|
*/
|
2001-08-06 22:01:31 +00:00
|
|
|
for (i = 0; kbuf[i] && i < 16; i++)
|
|
|
|
if ((nbuf[i] = hex_to_binary((int) kbuf[i], 16)) == -1)
|
1994-02-01 00:36:28 +00:00
|
|
|
des_error("bad hex digit in key");
|
1993-06-18 13:00:14 +00:00
|
|
|
while (i < 16)
|
|
|
|
nbuf[i++] = 0;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
obuf[i] =
|
|
|
|
((nbuf[2*i]&0xf)<<4) | (nbuf[2*i+1]&0xf);
|
|
|
|
/* preserve parity bits */
|
|
|
|
pflag = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* leading '0b' or '0B' == binary key
|
|
|
|
*/
|
2001-08-06 22:01:31 +00:00
|
|
|
if (kbuf[0] == '0' && (kbuf[1] == 'b' || kbuf[1] == 'B')) {
|
|
|
|
kbuf = &kbuf[2];
|
1993-06-18 13:00:14 +00:00
|
|
|
/*
|
|
|
|
* now translate it, bombing on any illegal binary digit
|
|
|
|
*/
|
2001-08-06 22:01:31 +00:00
|
|
|
for (i = 0; kbuf[i] && i < 16; i++)
|
|
|
|
if ((nbuf[i] = hex_to_binary((int) kbuf[i], 2)) == -1)
|
1994-02-01 00:36:28 +00:00
|
|
|
des_error("bad binary digit in key");
|
1993-06-18 13:00:14 +00:00
|
|
|
while (i < 64)
|
|
|
|
nbuf[i++] = 0;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
for (j = 0; j < 8; j++)
|
|
|
|
obuf[i] = (obuf[i]<<1)|nbuf[8*i+j];
|
|
|
|
/* preserve parity bits */
|
|
|
|
pflag = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* no special leader -- ASCII
|
|
|
|
*/
|
2001-08-06 22:01:31 +00:00
|
|
|
(void)strncpy(obuf, kbuf, 8);
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* DES FUNCTIONS *
|
|
|
|
*****************/
|
|
|
|
/*
|
|
|
|
* This sets the DES key and (if you're using the deszip version)
|
|
|
|
* the direction of the transformation. This uses the Sun
|
|
|
|
* to map the 64-bit key onto the 56 bits that the key schedule
|
|
|
|
* generation routines use: the old way, which just uses the user-
|
|
|
|
* supplied 64 bits as is, and the new way, which resets the parity
|
|
|
|
* bit to be the same as the low-order bit in each character. The
|
|
|
|
* new way generates a greater variety of key schedules, since many
|
|
|
|
* systems set the parity (high) bit of each character to 0, and the
|
|
|
|
* DES ignores the low order bit of each character.
|
|
|
|
*/
|
|
|
|
void
|
2003-06-02 19:06:28 +00:00
|
|
|
set_des_key(DES_cblock *buf) /* key block */
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
2001-08-06 22:01:31 +00:00
|
|
|
int i, j; /* counter in a for loop */
|
|
|
|
int par; /* parity counter */
|
1993-06-18 13:00:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if the parity is not preserved, flip it
|
|
|
|
*/
|
|
|
|
if (!pflag) {
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
par = 0;
|
|
|
|
for (j = 1; j < 8; j++)
|
2003-06-02 19:06:28 +00:00
|
|
|
if ((bits[j] & (*buf)[i]) != 0)
|
1993-06-18 13:00:14 +00:00
|
|
|
par++;
|
2003-06-02 19:06:28 +00:00
|
|
|
if ((par & 0x01) == 0x01)
|
|
|
|
(*buf)[i] &= 0x7f;
|
1993-06-18 13:00:14 +00:00
|
|
|
else
|
2003-06-02 19:06:28 +00:00
|
|
|
(*buf)[i] = ((*buf)[i] & 0x7f) | 0x80;
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-02 19:06:28 +00:00
|
|
|
DES_set_odd_parity(buf);
|
|
|
|
DES_set_key(buf, &schedule);
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This encrypts using the Cipher Block Chaining mode of DES
|
|
|
|
*/
|
1994-02-01 00:36:28 +00:00
|
|
|
int
|
2002-07-31 16:52:16 +00:00
|
|
|
cbc_encode(unsigned char *msgbuf, int n, FILE *fp)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
|
|
|
int inverse = 0; /* 0 to encrypt, 1 to decrypt */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do the transformation
|
|
|
|
*/
|
|
|
|
if (n == 8) {
|
|
|
|
for (n = 0; n < 8; n++)
|
2003-06-02 19:06:28 +00:00
|
|
|
msgbuf[n] ^= ivec[n];
|
|
|
|
DES_XFORM((DES_cblock *)msgbuf);
|
|
|
|
MEMCPY(ivec, msgbuf, 8);
|
|
|
|
return WRITE(msgbuf, 8, fp);
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* at EOF or last block -- in either case, the last byte contains
|
|
|
|
* the character representation of the number of bytes in it
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
MEMZERO(msgbuf + n, 8 - n);
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Pad the last block randomly
|
|
|
|
*/
|
2003-06-02 19:06:28 +00:00
|
|
|
(void)MEMCPY(msgbuf + n, pvec, 8 - n);
|
|
|
|
msgbuf[7] = n;
|
1993-06-18 13:00:14 +00:00
|
|
|
for (n = 0; n < 8; n++)
|
2003-06-02 19:06:28 +00:00
|
|
|
msgbuf[n] ^= ivec[n];
|
|
|
|
DES_XFORM((DES_cblock *)msgbuf);
|
|
|
|
return WRITE(msgbuf, 8, fp);
|
1993-06-18 13:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This decrypts using the Cipher Block Chaining mode of DES
|
2002-02-02 06:36:49 +00:00
|
|
|
* msgbuf I/O buffer
|
|
|
|
* fp input file descriptor
|
1993-06-18 13:00:14 +00:00
|
|
|
*/
|
1994-02-01 00:36:28 +00:00
|
|
|
int
|
2002-07-31 16:52:16 +00:00
|
|
|
cbc_decode(unsigned char *msgbuf, FILE *fp)
|
1993-06-18 13:00:14 +00:00
|
|
|
{
|
2003-06-02 19:06:28 +00:00
|
|
|
DES_cblock tbuf; /* temp buffer for initialization vector */
|
2001-08-06 22:01:31 +00:00
|
|
|
int n; /* number of bytes actually read */
|
|
|
|
int c; /* used to test for EOF */
|
1993-06-18 13:00:14 +00:00
|
|
|
int inverse = 1; /* 0 to encrypt, 1 to decrypt */
|
|
|
|
|
2003-06-02 19:06:28 +00:00
|
|
|
if ((n = READ(msgbuf, 8, fp)) == 8) {
|
1993-06-18 13:00:14 +00:00
|
|
|
/*
|
|
|
|
* do the transformation
|
|
|
|
*/
|
2003-06-02 19:06:28 +00:00
|
|
|
MEMCPY(tbuf, msgbuf, 8);
|
|
|
|
DES_XFORM((DES_cblock *)msgbuf);
|
1993-06-18 13:00:14 +00:00
|
|
|
for (c = 0; c < 8; c++)
|
2003-06-02 19:06:28 +00:00
|
|
|
msgbuf[c] ^= ivec[c];
|
|
|
|
MEMCPY(ivec, tbuf, 8);
|
1993-06-18 13:00:14 +00:00
|
|
|
/*
|
|
|
|
* if the last one, handle it specially
|
|
|
|
*/
|
|
|
|
if ((c = fgetc(fp)) == EOF) {
|
2003-06-02 19:06:28 +00:00
|
|
|
n = msgbuf[7];
|
1993-06-18 13:00:14 +00:00
|
|
|
if (n < 0 || n > 7) {
|
1994-02-01 00:36:28 +00:00
|
|
|
des_error("decryption failed (block corrupted)");
|
1993-06-18 13:00:14 +00:00
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
(void)ungetc(c, fp);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
if (n > 0)
|
1994-02-01 00:36:28 +00:00
|
|
|
des_error("decryption failed (incomplete block)");
|
1993-06-18 13:00:14 +00:00
|
|
|
else if (n < 0)
|
1994-02-01 00:36:28 +00:00
|
|
|
des_error("cannot read file");
|
1993-06-18 13:00:14 +00:00
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
#endif /* DES */
|