Cleanup pass on mkpasswd.c
diff --git a/lib/lib.h b/lib/lib.h
index dfbe5e1..9deacf2 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -165,6 +165,9 @@
 // net.c
 int xsocket(int domain, int type, int protocol);
 
+// password.c
+int get_salt(char *salt, char * algo);
+
 // getmountlist.c
 struct mtab_list {
   struct mtab_list *next, *prev;
diff --git a/lib/password.c b/lib/password.c
index 930e9c3..76f0043 100644
--- a/lib/password.c
+++ b/lib/password.c
@@ -6,48 +6,48 @@
 #include "toys.h"
 #include <time.h>
 
+// generate appropriate random salt string for given encryption algorithm.
 int get_salt(char *salt, char *algo)
 {      
-  int i, len = 0, offset = 0;
-  char buf[12];
+  struct {
+    char *type, id, len;
+  } al[] = {{"des", 0, 2}, {"md5", 1, 8}, {"sha256", 5, 16}, {"sha512", 6, 16}};
+  int i;
 
-  if (!strcmp(algo,"des")) len = 2;
-  else {
-    *salt++ = '$';
-    if (!strcmp(algo,"md5")) {
-      *salt++ = '1';
-      len = 8;
-    } else if (!strcmp(algo,"sha256")) {
-      *salt++ = '5';
-      len = 16;
-    } else if (!strcmp(algo,"sha512")) {
-      *salt++ = '6';
-      len = 16;
-    } else return -1;
+  for (i = 0; i < ARRAY_LEN(al); i++) {
+    if (!strcmp(algo, al[i].type)) {
+      int len = al[i].len;
+      char *s = salt;
 
-    *salt++ = '$';
-    offset = 3;
-  }    
+      if (al[i].id) {
+        *s++ = '$';
+        *s++ = '0'+al[i].id;
+      }
+      *s++ = '$';
 
-  // Read appropriate number of random bytes for salt
-  i = xopen("/dev/urandom", O_RDONLY);
-  xreadall(i, buf, ((len*6)+7)/8);
-  close(i);
+      // Read appropriate number of random bytes for salt
+      i = xopen("/dev/urandom", O_RDONLY);
+      xreadall(i, libbuf, ((len*6)+7)/8);
+      close(i);
 
-  // Grab 6 bit chunks and convert to characters in ./0-9a-zA-Z
-  for (i=0; i<len; i++) {
-    int bitpos = i*6, bits = bitpos/8;
+      // Grab 6 bit chunks and convert to characters in ./0-9a-zA-Z
+      for (i=0; i<len; i++) {
+        int bitpos = i*6, bits = bitpos/8;
 
-    bits = ((buf[i]+(buf[i+1]<<8)) >> (bitpos&7)) & 0x3f;
-    bits += 46;
-    if (bits > 57) bits += 7;
-    if (bits > 90) bits += 6;
+        bits = ((libbuf[i]+(libbuf[i+1]<<8)) >> (bitpos&7)) & 0x3f;
+        bits += 46;
+        if (bits > 57) bits += 7;
+        if (bits > 90) bits += 6;
 
-    salt[i] = bits;
+        s[i] = bits;
+      }
+      salt[len] = 0;
+
+      return s-salt;
+    }
   }
-  salt[i] = 0;
 
-  return offset;
+  return -1;
 }
 
 static void handle(int signo)
diff --git a/lib/pending.h b/lib/pending.h
index aa31ea9..c99a9f1 100644
--- a/lib/pending.h
+++ b/lib/pending.h
@@ -4,7 +4,6 @@
 #define MAX_SALT_LEN  20 //3 for id, 16 for key, 1 for '\0'
 #define SYS_FIRST_ID  100
 #define SYS_LAST_ID   999
-int get_salt(char *salt, char * algo);
 void is_valid_username(const char *name);
 int read_password(char * buff, int buflen, char* mesg);
 int update_password(char *filename, char* username, char* encrypted);