Modify libcrypt so that the only exported symbol is _crypt().

Submitted by:	 Geoff Rehmet
This commit is contained in:
Geoff Rehmet 1994-08-08 17:29:04 +00:00
parent c4f09032cb
commit 712ca8b499
6 changed files with 58 additions and 266 deletions

View File

@ -2,14 +2,16 @@
# $Id: Makefile,v 1.1.1.1 1994/04/04 14:57:18 g89r4222 Exp $
#
SUBDIR= test
LIB= crypt
SRCS= crypt.c
#MAN3= crypt.0
#MAN3= crypt.3
#MLINKS= crypt.3 encrypt.3 crypt.3 setkey.3
#MLINKS+=crypt.3 des_cipher.3 crypt.3 des_setkey.3
.include <bsd.lib.mk>
.include <bsd.subdir.mk>
test:
cd test ; make test ; make clean

View File

@ -3,4 +3,19 @@ $Id: README.FreeBSD,v 1.2 1994/04/04 15:10:57 g89r4222 Exp $
This is FreeSec package for NetBSD, unchanged for
FreeBSD, except for the Makefile.
The other stuff in libcrypt will be added in stages!
FreeSec was written by David Burren <davidb@werj.com.au>
A few bugs in the original FreeSec release have been fixed.
In order to make libcrypt binaries exportable from the USA,
only the symbol _crypt() (later to be changed to ___crypt())
is exported from libcrypt.
This source code was developed outside the USA, and can be
obtained outside the USA.
Geoff Rehmet
Rhodes University
Grahamstown
South Africa
8 August 1994

View File

@ -4,6 +4,10 @@
* Copyright (c) 1994 David Burren
* All rights reserved.
*
* Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet
* crypt.c should now *only* export crypt(), in order to make
* binaries of libcrypt exportable from the USA
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -59,6 +63,11 @@
# include <stdio.h>
#endif
/* We can't always assume gcc */
#ifdef __GNUC__
#define INLINE inline
#endif
static u_char IP[64] = {
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
@ -184,7 +193,7 @@ static u_char ascii64[] =
/* 0000000000111111111122222222223333333333444444444455555555556666 */
/* 0123456789012345678901234567890123456789012345678901234567890123 */
static inline int
static INLINE int
ascii_to_bin(char ch)
{
if (ch > 'z')
@ -202,7 +211,6 @@ ascii_to_bin(char ch)
return(0);
}
static void
des_init()
{
@ -333,7 +341,6 @@ des_init()
des_initialised = 1;
}
static void
setup_salt(long salt)
{
@ -355,8 +362,7 @@ setup_salt(long salt)
}
}
int
static int
des_setkey(const char *key)
{
u_long k0, k1, rawkey0, rawkey1;
@ -437,7 +443,6 @@ des_setkey(const char *key)
return(0);
}
static int
do_des( u_long l_in, u_long r_in, u_long *l_out, u_long *r_out, int count)
{
@ -554,8 +559,7 @@ do_des( u_long l_in, u_long r_in, u_long *l_out, u_long *r_out, int count)
return(0);
}
int
static int
des_cipher(const char *in, char *out, long salt, int count)
{
u_long l_out, r_out, rawl, rawr;
@ -576,52 +580,7 @@ des_cipher(const char *in, char *out, long salt, int count)
return(retval);
}
int
setkey(char *key)
{
int i, j;
u_long packed_keys[2];
u_char *p;
p = (u_char *) packed_keys;
for (i = 0; i < 8; i++) {
p[i] = 0;
for (j = 0; j < 8; j++)
if (*key++ & 1)
p[i] |= bits8[j];
}
return(des_setkey(p));
}
int
encrypt(char *block, int flag)
{
u_long io[2];
u_char *p;
int i, j, retval;
if (!des_initialised)
des_init();
setup_salt(0L);
p = block;
for (i = 0; i < 2; i++) {
io[i] = 0L;
for (j = 0; j < 32; j++)
if (*p++ & 1)
io[i] |= bits32[j];
}
retval = do_des(io[0], io[1], io, io + 1, flag ? -1 : 1);
for (i = 0; i < 2; i++)
for (j = 0; j < 32; j++)
block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0;
return(retval);
}
char *
crypt(char *key, char *setting)
{

View File

@ -4,6 +4,10 @@
* Copyright (c) 1994 David Burren
* All rights reserved.
*
* Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet
* crypt.c should now *only* export crypt(), in order to make
* binaries of libcrypt exportable from the USA
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -59,6 +63,11 @@
# include <stdio.h>
#endif
/* We can't always assume gcc */
#ifdef __GNUC__
#define INLINE inline
#endif
static u_char IP[64] = {
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
@ -184,7 +193,7 @@ static u_char ascii64[] =
/* 0000000000111111111122222222223333333333444444444455555555556666 */
/* 0123456789012345678901234567890123456789012345678901234567890123 */
static inline int
static INLINE int
ascii_to_bin(char ch)
{
if (ch > 'z')
@ -202,7 +211,6 @@ ascii_to_bin(char ch)
return(0);
}
static void
des_init()
{
@ -333,7 +341,6 @@ des_init()
des_initialised = 1;
}
static void
setup_salt(long salt)
{
@ -355,8 +362,7 @@ setup_salt(long salt)
}
}
int
static int
des_setkey(const char *key)
{
u_long k0, k1, rawkey0, rawkey1;
@ -437,7 +443,6 @@ des_setkey(const char *key)
return(0);
}
static int
do_des( u_long l_in, u_long r_in, u_long *l_out, u_long *r_out, int count)
{
@ -554,8 +559,7 @@ do_des( u_long l_in, u_long r_in, u_long *l_out, u_long *r_out, int count)
return(0);
}
int
static int
des_cipher(const char *in, char *out, long salt, int count)
{
u_long l_out, r_out, rawl, rawr;
@ -576,52 +580,7 @@ des_cipher(const char *in, char *out, long salt, int count)
return(retval);
}
int
setkey(char *key)
{
int i, j;
u_long packed_keys[2];
u_char *p;
p = (u_char *) packed_keys;
for (i = 0; i < 8; i++) {
p[i] = 0;
for (j = 0; j < 8; j++)
if (*key++ & 1)
p[i] |= bits8[j];
}
return(des_setkey(p));
}
int
encrypt(char *block, int flag)
{
u_long io[2];
u_char *p;
int i, j, retval;
if (!des_initialised)
des_init();
setup_salt(0L);
p = block;
for (i = 0; i < 2; i++) {
io[i] = 0L;
for (j = 0; j < 32; j++)
if (*p++ & 1)
io[i] |= bits32[j];
}
retval = do_des(io[0], io[1], io, io + 1, flag ? -1 : 1);
for (i = 0; i < 2; i++)
for (j = 0; j < 32; j++)
block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0;
return(retval);
}
char *
crypt(char *key, char *setting)
{

View File

@ -4,27 +4,26 @@
#
# $Id: Makefile,v 1.1.1.1 1994/04/04 14:57:18 g89r4222 Exp $
#
LIBCRYPT!=cd $(.CURDIR)/..; \
printf "xxx:\n\techo \$${.OBJDIR}/libcrypt.a\n" | make -r -s -f - xxx
.if exists (../obj)
OBJDIR = obj
.else
OBJDIR =
.endif
LIBCRYPT= $(.CURDIR)/../$(OBJDIR)/libcrypt.a
#CFLAGS+= -DHAVE_CRYPT16
TARGETS=cert speedcrypt speeddes
TARGETS=cert speedcrypt
all: ${TARGETS}
test: all testcrypt testencrypt testdes testspeed
test: all testcrypt testspeed
testcrypt: cert
@./cert -c
testencrypt: cert
@./cert -e < ${.CURDIR}/cert.input
testdes: cert
@./cert -d < ${.CURDIR}/cert.input
testspeed: cryptspeed desspeed
testspeed: cryptspeed
cryptspeed: speedcrypt
@./speedcrypt 30 1
@ -32,24 +31,18 @@ cryptspeed: speedcrypt
@./speedcrypt 30 0
@./speedcrypt 30 0
desspeed: speeddes
@./speeddes 30 1
@./speeddes 30 1
@./speeddes 40 25
@./speeddes 40 25
cert: cert.c ${LIBCRYPT}
$(CC) $(CFLAGS) -o cert ${.CURDIR}/cert.c ${LIBCRYPT}
speedcrypt: speedcrypt.c ${LIBCRYPT}
$(CC) $(CFLAGS) -o speedcrypt ${.CURDIR}/speedcrypt.c ${LIBCRYPT}
speeddes: speeddes.c ${LIBCRYPT}
$(CC) $(CFLAGS) -o speeddes ${.CURDIR}/speeddes.c ${LIBCRYPT}
clean:
rm -f ${TARGETS}
install:
.include <bsd.obj.mk>
obj:
.include <bsd.prog.mk>

View File

@ -144,72 +144,6 @@ char *key, *plain, *answer;
return(0);
}
/*
* Test the setkey and encrypt functions
*/
void test_encrypt()
{
char key[64],plain[64],cipher[64],answer[64];
char buff[BUFSIZ];
unsigned long salt;
int i;
int test;
int fail;
printf("Testing setkey/encrypt\n");
for(test=0;fgets(buff, BUFSIZ, stdin);test++){
/*
* Allow comments.
*/
if (*buff == '#')
continue;
if ((fail = parse_line(buff, &salt, key, plain, answer)) < 0){
printf("test %d garbled (%d)\n", test, fail);
continue;
}
if (salt)
continue; /* encrypt has no salt support */
printf(" K: "); put8(key);
printf(" P: "); put8(plain);
printf(" C: "); put8(answer);
setkey(key);
for(i = 0; i < 64; i++)
cipher[i] = plain[i];
encrypt(cipher, 0);
for(i=0;i<64;i++)
if(cipher[i] != answer[i])
break;
fail = 0;
if(i != 64){
printf(" Enc FAIL ");
put8(cipher);
fail++; totfails++;
}
encrypt(cipher, 1);
for(i=0;i<64;i++)
if(cipher[i] != plain[i])
break;
if(i != 64){
printf(" Dec FAIL");
fail++; totfails++;
}
if(fail == 0)
printf(" OK");
printf("\n");
}
}
void bytes_to_bits(bytes, bits)
char *bytes;
unsigned char *bits;
@ -225,71 +159,6 @@ unsigned char *bits;
}
/*
* Test the des_setkey and des_cipher functions
*/
void test_des()
{
char ckey[64], cplain[64], canswer[64];
unsigned char key[8], plain[8], cipher[8], answer[8];
char buff[BUFSIZ];
unsigned long salt;
int i;
int test;
int fail;
printf("Testing des_setkey/des_cipher\n");
for(test=0;fgets(buff, BUFSIZ, stdin);test++){
/*
* Allow comments.
*/
if (*buff == '#')
continue;
if ((fail = parse_line(buff, &salt, ckey, cplain, canswer)) <0){
printf("test %d garbled (%d)\n", test, fail);
continue;
}
printf(" S: %06x", salt);
printf(" K: "); put8(ckey);
printf(" P: "); put8(cplain);
printf(" C: "); put8(canswer);
bytes_to_bits(ckey, key);
bytes_to_bits(cplain, plain);
bytes_to_bits(canswer, answer);
des_setkey(key);
des_cipher(plain, cipher, salt, 1);
for(i = 0; i < 8; i++)
if(cipher[i] != answer[i])
break;
fail = 0;
if(i != 8){
printf(" Enc FAIL ");
print_bits(cipher);
fail++; totfails++;
}
des_cipher(cipher, cipher, salt, -1);
for(i = 0; i < 8; i++)
if(cipher[i] != plain[i])
break;
if(i != 8){
printf(" Dec FAIL");
fail++; totfails++;
}
if(fail == 0)
printf(" OK");
printf("\n");
}
}
/*
* Test the old-style crypt(), the new-style crypt(), and crypt16().
@ -334,11 +203,6 @@ main(argc, argv)
int argc;
char *argv[];
{
if(argc < 1 || !strcmp(argv[1], "-e"))
test_encrypt();
else if(!strcmp(argv[1], "-d"))
test_des();
else if(!strcmp(argv[1], "-c"))
test_crypt();
test_crypt();
good_bye();
}