cbc.c (99109) | cbc.c (101093) |
---|---|
1/* cbc.c: This file contains the encryption routines for the ed line editor */ 2/*- 3 * Copyright (c) 1993 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * Copyright (c) 1993 Andrew Moore, Talke Studio. 7 * All rights reserved. 8 * --- 22 unchanged lines hidden (view full) --- 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38#include <sys/cdefs.h> | 1/* cbc.c: This file contains the encryption routines for the ed line editor */ 2/*- 3 * Copyright (c) 1993 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * Copyright (c) 1993 Andrew Moore, Talke Studio. 7 * All rights reserved. 8 * --- 22 unchanged lines hidden (view full) --- 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/ed/cbc.c 99109 2002-06-30 05:13:54Z obrien $"); | 39__FBSDID("$FreeBSD: head/bin/ed/cbc.c 101093 2002-07-31 16:52:16Z markm $"); |
40 41#include <sys/types.h> 42#include <errno.h> 43#include <pwd.h> 44#ifdef DES 45#include <time.h> 46#endif 47 48#include "ed.h" 49 50 51/* 52 * BSD and System V systems offer special library calls that do 53 * block move_liness and fills, so if possible we take advantage of them 54 */ 55#define MEMCPY(dest,src,len) memcpy((dest),(src),(len)) 56#define MEMZERO(dest,len) memset((dest), 0, (len)) 57 58/* Hide the calls to the primitive encryption routines. */ | 40 41#include <sys/types.h> 42#include <errno.h> 43#include <pwd.h> 44#ifdef DES 45#include <time.h> 46#endif 47 48#include "ed.h" 49 50 51/* 52 * BSD and System V systems offer special library calls that do 53 * block move_liness and fills, so if possible we take advantage of them 54 */ 55#define MEMCPY(dest,src,len) memcpy((dest),(src),(len)) 56#define MEMZERO(dest,len) memset((dest), 0, (len)) 57 58/* Hide the calls to the primitive encryption routines. */ |
59#define DES_KEY(buf) \ 60 if (des_setkey(buf)) \ | 59#define DES_KEY(buf) \ 60 if (des_setkey(buf)) \ |
61 des_error("des_setkey"); | 61 des_error("des_setkey"); |
62#define DES_XFORM(buf) \ 63 if (des_cipher(buf, buf, 0L, (inverse ? -1 : 1))) \ | 62#define DES_XFORM(buf) \ 63 if (des_cipher((char *)buf, (char *)buf, 0L, inverse ? -1 : 1)) \ |
64 des_error("des_cipher"); 65 66/* 67 * read/write - no error checking 68 */ 69#define READ(buf, n, fp) fread(buf, sizeof(char), n, fp) 70#define WRITE(buf, n, fp) fwrite(buf, sizeof(char), n, fp) 71 --- 255 unchanged lines hidden (view full) --- 327 DES_KEY(UBUFFER(buf)); 328} 329 330 331/* 332 * This encrypts using the Cipher Block Chaining mode of DES 333 */ 334int | 64 des_error("des_cipher"); 65 66/* 67 * read/write - no error checking 68 */ 69#define READ(buf, n, fp) fread(buf, sizeof(char), n, fp) 70#define WRITE(buf, n, fp) fwrite(buf, sizeof(char), n, fp) 71 --- 255 unchanged lines hidden (view full) --- 327 DES_KEY(UBUFFER(buf)); 328} 329 330 331/* 332 * This encrypts using the Cipher Block Chaining mode of DES 333 */ 334int |
335cbc_encode(char *msgbuf, int n, FILE *fp) | 335cbc_encode(unsigned char *msgbuf, int n, FILE *fp) |
336{ 337 int inverse = 0; /* 0 to encrypt, 1 to decrypt */ 338 339 /* 340 * do the transformation 341 */ 342 if (n == 8) { 343 for (n = 0; n < 8; n++) --- 21 unchanged lines hidden (view full) --- 365} 366 367/* 368 * This decrypts using the Cipher Block Chaining mode of DES 369 * msgbuf I/O buffer 370 * fp input file descriptor 371 */ 372int | 336{ 337 int inverse = 0; /* 0 to encrypt, 1 to decrypt */ 338 339 /* 340 * do the transformation 341 */ 342 if (n == 8) { 343 for (n = 0; n < 8; n++) --- 21 unchanged lines hidden (view full) --- 365} 366 367/* 368 * This decrypts using the Cipher Block Chaining mode of DES 369 * msgbuf I/O buffer 370 * fp input file descriptor 371 */ 372int |
373cbc_decode(char *msgbuf, FILE *fp) | 373cbc_decode(unsigned char *msgbuf, FILE *fp) |
374{ 375 Desbuf tbuf; /* temp buffer for initialization vector */ 376 int n; /* number of bytes actually read */ 377 int c; /* used to test for EOF */ 378 int inverse = 1; /* 0 to encrypt, 1 to decrypt */ 379 380 if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) { 381 /* --- 27 unchanged lines hidden --- | 374{ 375 Desbuf tbuf; /* temp buffer for initialization vector */ 376 int n; /* number of bytes actually read */ 377 int c; /* used to test for EOF */ 378 int inverse = 1; /* 0 to encrypt, 1 to decrypt */ 379 380 if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) { 381 /* --- 27 unchanged lines hidden --- |