add return values to setkey, encrypt, des_setkey, des_cipher to
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 19 May 1991 05:56:41 +0000 (21:56 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 19 May 1991 05:56:41 +0000 (21:56 -0800)
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

usr/src/include/unistd.h
usr/src/lib/libc/gen/crypt.3
usr/src/lib/libc/gen/crypt.c

index bb0a581..34efd0f 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)unistd.h    5.11 (Berkeley) %G%
+ *     @(#)unistd.h    5.12 (Berkeley) %G%
  */
 
 #ifndef _UNISTD_H_
  */
 
 #ifndef _UNISTD_H_
@@ -89,9 +89,9 @@ char  *brk __P((const char *));
 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));
@@ -133,7 +133,7 @@ int  seteuid __P((uid_t));
 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() */
index 3374752..5d28e55 100644 (file)
@@ -3,7 +3,7 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"     @(#)crypt.3    6.5 (Berkeley) %G%
+.\"     @(#)crypt.3    6.6 (Berkeley) %G%
 .\"
 .Dd 
 .Dt CRYPT 3
 .\"
 .Dd 
 .Dt CRYPT 3
 .Sh SYNOPSIS
 .Ft char
 .Fn *crypt "const char *key" "const char *setting"
 .Sh SYNOPSIS
 .Ft char
 .Fn *crypt "const char *key" "const char *setting"
-.Ft void
+.Ft int
 .Fn setkey "char *key"
 .Fn setkey "char *key"
-.Ft void
+.Ft int
 .Fn encrypt "char *block" "int flag"
 .Fn encrypt "char *block" "int flag"
-.Ft void
+.Ft int
 .Fn des_setkey "const char *key"
 .Fn des_setkey "const char *key"
-.Ft void
+.Ft int
 .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
@@ -118,6 +118,26 @@ into groups of 8 and ignoring the last bit in each group.
 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 ,
@@ -166,6 +186,7 @@ is ridiculous.
 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.
index 52d44fa..5bb2ce3 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #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>
@@ -457,7 +457,8 @@ crypt(key, setting)
                        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) {
@@ -491,7 +492,9 @@ crypt(key, 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.
@@ -506,8 +509,11 @@ crypt(key, setting)
                        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;
        }
@@ -545,7 +551,6 @@ static C_block      KS[KS_SIZE];
 /*
  * Set up the key schedule from the key.
  */
 /*
  * Set up the key schedule from the key.
  */
-void
 des_setkey(key)
        register const char *key;
 {
 des_setkey(key)
        register const char *key;
 {
@@ -569,6 +574,7 @@ des_setkey(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);
        }
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -579,7 +585,6 @@ des_setkey(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.
  */
-void
 des_cipher(in, out, salt, num_iter)
        const char *in;
        char *out;
 des_cipher(in, out, salt, num_iter)
        const char *in;
        char *out;
@@ -694,6 +699,7 @@ des_cipher(in, out, salt, num_iter)
 #else
        STORE(L,L0,L1,*(C_block *)out);
 #endif
 #else
        STORE(L,L0,L1,*(C_block *)out);
 #endif
+       return(0);
 }
 
 
 }
 
 
@@ -869,7 +875,6 @@ init_perm(perm, p, chars_in, chars_out)
 /*
  * "setkey" routine (for backwards compatibility)
  */
 /*
  * "setkey" routine (for backwards compatibility)
  */
-void
 setkey(key)
        register const char *key;
 {
 setkey(key)
        register const char *key;
 {
@@ -884,13 +889,12 @@ setkey(key)
                }
                keyblock.b[i] = k;
        }
                }
                keyblock.b[i] = k;
        }
-       des_setkey((char *)keyblock.b);
+       return(des_setkey((char *)keyblock.b));
 }
 
 /*
  * "encrypt" routine (for backwards compatibility)
  */
 }
 
 /*
  * "encrypt" routine (for backwards compatibility)
  */
-void
 encrypt(block, flag)
        register char *block;
        int flag;
 encrypt(block, flag)
        register char *block;
        int flag;
@@ -906,7 +910,8 @@ encrypt(block, flag)
                }
                cblock.b[i] = k;
        }
                }
                cblock.b[i] = k;
        }
-       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--) {
@@ -914,6 +919,7 @@ encrypt(block, flag)
                        k >>= 1;
                }
        }
                        k >>= 1;
                }
        }
+       return(0);
 }
 
 #ifdef DEBUG
 }
 
 #ifdef DEBUG