Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include <assert.h>
00034 #include <sys/param.h>
00035
00036 #include <eurephia_nullsafe.h>
00037 #include <get_console_input.h>
00038
00039 #define ROUNDS_MIN 1000
00040 #define ROUNDS_MAX 999999999
00050 inline unsigned int get_salt_p2(const char *pwd) {
00051 int n = 0;
00052 long int saltinfo_p2 = 0, t = 0;
00053
00054 for( n = 0; n < strlen_nullsafe(pwd); n++ ) {
00055 t += pwd[n];
00056 }
00057
00058 for( n = 0; n < 4; n++ ) {
00059 saltinfo_p2 <<= 8;
00060 saltinfo_p2 += (strlen_nullsafe(pwd) ^ (t % 0xff));
00061 }
00062 return saltinfo_p2;
00063 }
00064
00065
00074 unsigned int unpack_saltinfo(const char *insalt, const char *pwd) {
00075 unsigned int in_salt_prefix = 0;
00076
00077 assert(insalt != NULL && pwd != NULL);
00078
00079 if( sscanf(insalt, "%08x", &in_salt_prefix) > -1 ) {
00080 long int regen_p2 = in_salt_prefix ^ get_salt_p2(pwd);
00081 return regen_p2 ^ 0xAAAAAAAA;
00082 } else {
00083 return -1;
00084 }
00085 }
00086
00087
00096 int main(int argc, char **argv) {
00097 char key[258];
00098 unsigned int saltinfo = 0;
00099 size_t rounds = 0, salt_len = 0;
00100
00101 if( argc != 2 ) {
00102 fprintf(stderr, "Usage: %s <password salt>\n", argv[0]);
00103 return 1;
00104 }
00105
00106 memset(&key, 0, 258);
00107 printf("\nYou will need to give the correct password for this salt.\n");
00108 printf("If you give the wrong password, the decoded information will be wrong.\n\n");
00109 get_console_input(key, 256, "Password:", 1);
00110 saltinfo = unpack_saltinfo(argv[1], key);
00111 memset(&key, 0, 258);
00112
00113 salt_len = saltinfo & 0x000000ff;
00114 rounds = MAX(ROUNDS_MIN, MIN(((saltinfo & 0xffffff00) >> 8), ROUNDS_MAX));
00115
00116 printf("\nSalt length: %ld\nHash rounds: %ld\n\n",
00117 (unsigned long int) salt_len,
00118 (unsigned long int) rounds);
00119
00120 return 0;
00121 }