eurephia_saltdecode.c

Go to the documentation of this file.
00001 /* saltdecode.c  --  Decode a given password salt into a readable format
00002  *
00003  *  GPLv2 only - Copyright (C) 2009 - 2010
00004  *               David Sommerseth <dazo@users.sourceforge.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; version 2
00009  *  of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines