distinguish failure (no hardware support or foreign distribution)
SCCS-vsn: lib/libc/gen/crypt.3 6.6
SCCS-vsn: lib/libc/gen/crypt.c 5.9
SCCS-vsn: include/unistd.h 5.12
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)unistd.h 5.11 (Berkeley) %G%
+ * @(#)unistd.h 5.12 (Berkeley) %G%
int chflags __P((const char *, long));
int chroot __P((const char *));
char *crypt __P((const char *, const char *));
int chflags __P((const char *, long));
int chroot __P((const char *));
char *crypt __P((const char *, const char *));
-void des_cipher __P((const char *, char *, long, int));
-void des_setkey __P((const char *key));
-void encrypt __P((char *, int));
+int des_cipher __P((const char *, char *, long, int));
+int des_setkey __P((const char *key));
+int encrypt __P((char *, int));
void endusershell __P((void));
int exect __P((const char *, char * const *, char * const *));
int fchdir __P((int));
void endusershell __P((void));
int exect __P((const char *, char * const *, char * const *));
int fchdir __P((int));
int setgroups __P((int, const int *));
void sethostid __P((long));
int sethostname __P((const char *, int));
int setgroups __P((int, const int *));
void sethostid __P((long));
int sethostname __P((const char *, int));
-void setkey __P((const char *));
+int setkey __P((const char *));
int setlogin __P((const char *));
void *setmode __P((const char *));
int setpgrp __P((pid_t pid, pid_t pgrp)); /* obsoleted by setpgid() */
int setlogin __P((const char *));
void *setmode __P((const char *));
int setpgrp __P((pid_t pid, pid_t pgrp)); /* obsoleted by setpgid() */
.\"
.\" %sccs.include.redist.man%
.\"
.\"
.\" %sccs.include.redist.man%
.\"
-.\" @(#)crypt.3 6.5 (Berkeley) %G%
+.\" @(#)crypt.3 6.6 (Berkeley) %G%
.Sh SYNOPSIS
.Ft char
.Fn *crypt "const char *key" "const char *setting"
.Sh SYNOPSIS
.Ft char
.Fn *crypt "const char *key" "const char *setting"
.Fn encrypt "char *block" "int flag"
.Fn encrypt "char *block" "int flag"
.Fn des_setkey "const char *key"
.Fn des_setkey "const char *key"
.Fn des_cipher "const char *in" "char *out" "long salt" "int count"
.Sh DESCRIPTION
The
.Fn des_cipher "const char *in" "char *out" "long salt" "int count"
.Sh DESCRIPTION
The
specifies perturbations to
.Tn DES
as described above.
specifies perturbations to
.Tn DES
as described above.
+.Pp
+The function
+.Fn crypt
+returns a pointer to the encrypted value on success and NULL on failure.
+The functions
+.Fn setkey ,
+.Fn encrypt ,
+.Fn des_setkey ,
+and
+.Fn des_cipher
+return 0 on success and 1 on failure.
+Historically, the functions
+.Fn setkey
+and
+.Fn encrypt
+did not return any value.
+They have been provided return values primarily to distinguish
+implementations where hardware support is provided but not
+available or where the DES encryption is not available due to the
+usual political silliness.
.Sh SEE ALSO
.Xr login 1 ,
.Xr passwd 1 ,
.Sh SEE ALSO
.Xr login 1 ,
.Xr passwd 1 ,
The
.Fn crypt
function leaves its result in an internal static object and returns
The
.Fn crypt
function leaves its result in an internal static object and returns
-a pointer to that object. Subsequent calls to
+a pointer to that object.
+Subsequent calls to
.Fn crypt
will modify the same object.
.Fn crypt
will modify the same object.
*/
#if defined(LIBC_SCCS) && !defined(lint)
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)crypt.c 5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)crypt.c 5.9 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <unistd.h>
#endif /* LIBC_SCCS and not lint */
#include <unistd.h>
key++;
keyblock.b[i] = t;
}
key++;
keyblock.b[i] = t;
}
- des_setkey((char *)keyblock.b); /* also initializes "a64toi" */
+ if (des_setkey((char *)keyblock.b)) /* also initializes "a64toi" */
+ return(NULL);
encp = &cryptresult[0];
switch (*setting) {
encp = &cryptresult[0];
switch (*setting) {
salt = (salt<<6) | a64toi[t];
}
encp += salt_size;
salt = (salt<<6) | a64toi[t];
}
encp += salt_size;
- des_cipher((char *)&constdatablock, (char *)&rsltblock, salt, num_iter);
+ if (des_cipher((char *)&constdatablock, (char *)&rsltblock,
+ salt, num_iter))
+ return(NULL);
/*
* encrypt the remainder of the password 8 characters at a time.
/*
* encrypt the remainder of the password 8 characters at a time.
if (t == 0)
break; /* pad out with previous key */
}
if (t == 0)
break; /* pad out with previous key */
}
- des_setkey((char *)keyblock.b);
- des_cipher((char *)&constdatablock, (char *)&xdatablock, 0L, 1);
+ if (des_setkey((char *)keyblock.b))
+ return(NULL);
+ if (des_cipher((char *)&constdatablock,
+ (char *)&xdatablock, 0L, 1))
+ return(NULL);
rsltblock.b32.i0 ^= xdatablock.b32.i0;
rsltblock.b32.i1 ^= xdatablock.b32.i1;
}
rsltblock.b32.i0 ^= xdatablock.b32.i0;
rsltblock.b32.i1 ^= xdatablock.b32.i1;
}
/*
* Set up the key schedule from the key.
*/
/*
* Set up the key schedule from the key.
*/
des_setkey(key)
register const char *key;
{
des_setkey(key)
register const char *key;
{
PERM6464(K,K0,K1,(unsigned char *)key,ptabp);
STORE(K&0xfcfcfcfcL, K0&0xfcfcfcfcL, K1, *(C_block *)key);
}
PERM6464(K,K0,K1,(unsigned char *)key,ptabp);
STORE(K&0xfcfcfcfcL, K0&0xfcfcfcfcL, K1, *(C_block *)key);
}
* NOTE: the performance of this routine is critically dependent on your
* compiler and machine architecture.
*/
* NOTE: the performance of this routine is critically dependent on your
* compiler and machine architecture.
*/
des_cipher(in, out, salt, num_iter)
const char *in;
char *out;
des_cipher(in, out, salt, num_iter)
const char *in;
char *out;
#else
STORE(L,L0,L1,*(C_block *)out);
#endif
#else
STORE(L,L0,L1,*(C_block *)out);
#endif
/*
* "setkey" routine (for backwards compatibility)
*/
/*
* "setkey" routine (for backwards compatibility)
*/
setkey(key)
register const char *key;
{
setkey(key)
register const char *key;
{
- des_setkey((char *)keyblock.b);
+ return(des_setkey((char *)keyblock.b));
}
/*
* "encrypt" routine (for backwards compatibility)
*/
}
/*
* "encrypt" routine (for backwards compatibility)
*/
encrypt(block, flag)
register char *block;
int flag;
encrypt(block, flag)
register char *block;
int flag;
- des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag? -1: 1));
+ if (des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1)))
+ return(1);
for (i = 7; i >= 0; i--) {
k = cblock.b[i];
for (j = 7; j >= 0; j--) {
for (i = 7; i >= 0; i--) {
k = cblock.b[i];
for (j = 7; j >= 0; j--) {