2 ** Copyright 1998 - 2006 Double Precision, Inc.
3 ** See COPYING for distribution information.
19 #if TIME_WITH_SYS_TIME
33 #include "libhmac/hmac.h"
51 #if NEED_CRYPT_PROTOTYPE
52 extern char *crypt(const char *, const char *);
56 extern char userdb_hex64
[];
59 extern void userdb_get_random(char *buf
, unsigned n
);
64 char *userdb_mkmd5pw(const char *);
69 ** Where possible, we turn off echo when entering the password.
70 ** We set up a signal handler to catch signals and restore the echo
75 static struct termios tios
;
78 static RETSIGTYPE
sighandler(int signum
)
80 if (write(1, "\n", 1) < 0)
81 ; /* ignore gcc warning */
82 tcsetattr(0, TCSANOW
, &tios
);
84 #if RETSIGTYPE != void
90 static void read_pw(char *buf
)
95 while ((c
=getchar()) != EOF
&& c
!= '\n')
98 if (c
== EOF
&& n
== 0) exit(1);
102 int main(int argc
, char **argv
)
112 struct hmac_hashinfo
*hmac
=0;
117 if (strcmp(argv
[n
], "-md5") == 0)
124 if (strncmp(argv
[n
], "-hmac-", 6) == 0)
128 for (i
=0; hmac_list
[i
] &&
129 strcmp(hmac_list
[i
]->hh_name
, argv
[n
]+6); i
++)
139 fprintf(stderr
, "%s: invalid argument.\n", argv
[0]);
143 /* Read the password */
147 if (tcgetattr(0, &tios
) == 0)
149 struct termios tios2
;
153 signal(SIGINT
, sighandler
);
154 signal(SIGHUP
, sighandler
);
156 tios2
.c_lflag
&= ~ECHO
;
157 tcsetattr(0, TCSANOW
, &tios2
);
161 if (write(2, "Password: ", 10) < 0)
162 ; /* ignore gcc warning */
164 if (write(2, "\nReenter password: ", 19) < 0)
165 ; /* ignore gcc warning */
167 if (strcmp(buf
, buf2
) == 0) break;
168 if (write(2, "\nPasswords don't match.\n\n", 25) < 0)
169 ; /* ignore gcc warning */
180 if (write(2, "\n", 1) < 0)
181 ; /* ignore gcc warning */
183 tcsetattr(0, TCSANOW
, &tios
);
184 signal(SIGINT
, SIG_DFL
);
185 signal(SIGHUP
, SIG_DFL
);
189 /* Set the password */
194 unsigned char *p
=malloc(hmac
->hh_L
*2);
203 hmac_hashkey(hmac
, buf
, strlen(buf
), p
, p
+hmac
->hh_L
);
204 for (i
=0; i
<hmac
->hh_L
*2; i
++)
205 printf("%02x", (int)p
[i
]);
221 printf("%s\n", userdb_mkmd5pw(buf
));
226 userdb_get_random(salt
, 2);
227 salt
[0]=userdb_hex64
[salt
[0] & 63];
228 salt
[1]=userdb_hex64
[salt
[0] & 63];
247 salt
[0]=userdb_hex64
[(unsigned)salt
[0]];
248 salt
[1]=userdb_hex64
[(unsigned)salt
[1]];
253 cryptsalt
=bcrypt_gensalt(8);
254 printf("%s\n", crypt(buf
, cryptsalt
));
257 printf("%s\n", crypt(buf
, salt
));