glibc/crypt/cert.c
Zack Weinberg b10a0accee Disallow use of DES encryption functions in new programs.
The functions encrypt, setkey, encrypt_r, setkey_r, cbc_crypt,
ecb_crypt, and des_setparity should not be used in new programs,
because they use the DES block cipher, which is unacceptably weak by
modern standards.  Demote all of them to compatibility symbols, and
remove their prototypes from installed headers.  cbc_crypt, ecb_crypt,
and des_setparity were already compat symbols when glibc was
configured with --disable-obsolete-rpc.

POSIX requires encrypt and setkey to be available when _XOPEN_CRYPT
is defined, so this change also removes the definition of X_OPEN_CRYPT
from <unistd.h>.

The entire "DES Encryption" section is dropped from the manual, as is
the mention of AUTH_DES and FIPS 140-2 in the introduction to
crypt.texi.  The documentation of 'memfrob' cross-referenced the DES
Encryption section, which is replaced by a hyperlink to libgcrypt, and
while I was in there I spruced up the actual documentation of
'memfrob' and 'strfry' a little.  It's still fairly jokey, because
those functions _are_ jokes, but they do also have real use cases, so
people trying to use them for real should have all the information
they need.

DES-based authentication for Sun RPC is also insecure and should be
deprecated or even removed, but maybe that can be left as TI-RPC's
problem.
2018-06-29 16:53:18 +02:00

133 lines
2.3 KiB
C

/*
* This crypt(3) validation program shipped with UFC-crypt
* is derived from one distributed with Phil Karns PD DES package.
*
* @(#)cert.c 1.8 11 Aug 1996
*/
#include <stdio.h>
#include <stdlib.h>
#include "crypt.h"
/* This file tests the deprecated setkey/encrypt interface. */
#include <shlib-compat.h>
#if TEST_COMPAT (libcrypt, GLIBC_2_0, GLIBC_2_28)
#define libcrypt_version_reference(symbol, version) \
_libcrypt_version_reference (symbol, VERSION_libcrypt_##version)
#define _libcrypt_version_reference(symbol, version) \
__libcrypt_version_reference (symbol, version)
#define __libcrypt_version_reference(symbol, version) \
__asm__ (".symver " #symbol ", " #symbol "@" #version)
extern void setkey (const char *);
extern void encrypt (const char *, int);
libcrypt_version_reference (setkey, GLIBC_2_0);
libcrypt_version_reference (encrypt, GLIBC_2_0);
int totfails = 0;
int main (int argc, char *argv[]);
void get8 (char *cp);
void put8 (char *cp);
void good_bye (void) __attribute__ ((noreturn));
void
good_bye (void)
{
if(totfails == 0) {
printf("Passed DES validation suite\n");
exit(0);
} else {
printf("%d failures during DES validation suite!!!\n", totfails);
exit(1);
}
}
int
main (int argc, char *argv[])
{
char key[64],plain[64],cipher[64],answer[64];
int i;
int test;
int fail;
for(test=0;!feof(stdin);test++){
get8(key);
printf(" K: "); put8(key);
setkey(key);
get8(plain);
printf(" P: "); put8(plain);
get8(answer);
printf(" C: "); put8(answer);
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(" Encrypt FAIL");
fail++; totfails++;
}
encrypt(cipher, 1);
for(i=0;i<64;i++)
if(cipher[i] != plain[i])
break;
if(i != 64){
printf(" Decrypt FAIL");
fail++; totfails++;
}
if(fail == 0)
printf(" OK");
printf("\n");
}
good_bye();
}
void
get8 (char *cp)
{
int i,j,t;
for(i=0;i<8;i++){
scanf("%2x",&t);
if(feof(stdin))
good_bye();
for(j=0; j<8 ; j++) {
*cp++ = (t & (0x01 << (7-j))) != 0;
}
}
}
void
put8 (char *cp)
{
int i,j,t;
for(i=0;i<8;i++){
t = 0;
for(j = 0; j<8; j++)
t = (t<<1) | *cp++;
printf("%02x", t);
}
}
#else /* encrypt and setkey are not available. */
int
main (void)
{
return 77; /* UNSUPPORTED */
}
#endif