summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-03-29 13:40:13 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-03-29 13:40:13 +0200
commit0c7c0c7ea6e61872dafd3a7a49a10f63b819693c (patch)
tree4f793702f3ff8205932c9a96712dff5e0d81ec8a /utils
parentbf152fe270a195bddb14010662995560e1edb481 (diff)
downloadeurephia-0c7c0c7ea6e61872dafd3a7a49a10f63b819693c.tar.gz
eurephia-0c7c0c7ea6e61872dafd3a7a49a10f63b819693c.tar.xz
eurephia-0c7c0c7ea6e61872dafd3a7a49a10f63b819693c.zip
Added a small utility for decoding password salt information
Diffstat (limited to 'utils')
-rw-r--r--utils/CMakeLists.txt6
-rw-r--r--utils/saltdecode.c85
2 files changed, 91 insertions, 0 deletions
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index bcaed05..dcc8b00 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -26,4 +26,10 @@ IF(EUREPHIADM)
INCLUDE_DIRECTORIES(../common ../database ../eurephiadm)
ADD_EXECUTABLE(eurephia_init ${e_init_SRC})
TARGET_LINK_LIBRARIES(eurephia_init dl crypto ${EXTRA_LIBS})
+
+ SET(saltdecode_SRC
+ saltdecode.c
+ ../eurephiadm/get_console_input.c
+ )
+ ADD_EXECUTABLE(saltdecode ${saltdecode_SRC})
ENDIF(EUREPHIADM)
diff --git a/utils/saltdecode.c b/utils/saltdecode.c
new file mode 100644
index 0000000..ddaf4c7
--- /dev/null
+++ b/utils/saltdecode.c
@@ -0,0 +1,85 @@
+/* saltdecode.c -- Decode a given password salt into a readable format
+ *
+ * GPLv2 only - Copyright (C) 2009
+ * David Sommerseth <dazo@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/param.h>
+
+#include <eurephia_nullsafe.h>
+#include <get_console_input.h>
+
+#define ROUNDS_MIN 1000
+#define ROUNDS_MAX 999999999
+
+inline unsigned int get_salt_p2(const char *pwd) {
+ int n = 0;
+ long int saltinfo_p2 = 0, t = 0;
+
+ for( n = 0; n < strlen_nullsafe(pwd); n++ ) {
+ t += pwd[n];
+ }
+
+ for( n = 0; n < 4; n++ ) {
+ saltinfo_p2 <<= 8;
+ saltinfo_p2 += (strlen_nullsafe(pwd) ^ (t % 0xff));
+ }
+ return saltinfo_p2;
+}
+
+unsigned int unpack_saltinfo(const char *insalt, const char *pwd) {
+ unsigned int in_salt_prefix = 0;
+
+ assert(insalt != NULL && pwd != NULL);
+
+ if( sscanf(insalt, "%08x", &in_salt_prefix) > -1 ) {
+ long int regen_p2 = in_salt_prefix ^ get_salt_p2(pwd);
+ return regen_p2 ^ 0xAAAAAAAA;
+ } else {
+ return -1;
+ }
+}
+
+
+int main(int argc, char **argv) {
+ char key[258];
+ unsigned int saltinfo = 0;
+ size_t rounds = 0, salt_len = 0;
+
+ if( argc != 2 ) {
+ fprintf(stderr, "Usage: %s <password salt>\n", argv[0]);
+ return 1;
+ }
+
+ memset(&key, 0, 258);
+ printf("\nYou will need to give the correct password for this salt.\n");
+ printf("If you give the wrong password, the information will be decoded wrong.\n\n");
+ get_console_input(key, 256, "Password:", 1);
+ saltinfo = unpack_saltinfo(argv[1], key);
+ memset(&key, 0, 258);
+
+ salt_len = saltinfo & 0x000000ff;
+ rounds = MAX(ROUNDS_MIN, MIN(((saltinfo & 0xffffff00) >> 8), ROUNDS_MAX));
+
+ printf("\nSalt length: %ld\nHash rounds: %ld\n\n", salt_len, rounds);
+
+ return 0;
+}