Modified:
/src/commandline.c
/src/gui.c
/src/shacrypt.c
/src/shacrypt.h
/tests/Makefile.am
/tests/Makefile.in
=======================================
--- /src/commandline.c Sat Mar 13 07:26:35 2010
+++ /src/commandline.c Sat Mar 13 14:09:52 2010
@@ -126,10 +126,12 @@
int n;
FILE *f,
*o;
- static char fbuf[256] = {0},
- obuf[256] = {0};
+ unsigned char fbuf[256] = {0},
+ ibuf[256] = {0},
+ obuf[256] = {0},
+ algos = '\0',
+ scramblekey[256] = {0};
SHACrypt_Context s;
- unsigned char algos = '\0';
if ( strlen( argv[1] ) > 1 ) {
for ( n = 1; n < strlen( argv[1] ); n++ ) {
@@ -191,28 +193,42 @@
SHACrypt_Init( &s, argv[2], strlen( argv[2] ), algos, fbuf, n );
fwrite( identifier, 1, 3, o ); // Identifier
- fwrite( "\2\0", 1, 2, o ); // Format version
+ fwrite( "\3\0", 1, 2, o ); // Format version
fputc( (unsigned char)(n - 1), o ); // Random seed length
- fwrite( fbuf, 1, n, o ); // Random seed
+ fwrite( fbuf, 1, n, o ); // Random seed
fputc( algos, o ); // Hash alogithms used
+ n = SHACrypt_GetRand( algos, scramblekey );
+ SHACrypt_SetScramble( &s, scramblekey, n );
+
+ /* We need to also encrypt the scramble key */
+ fbuf[0] = (unsigned char)(n - 1);
+ SHACrypt_Process( &s, fbuf, obuf, 1 );
+ fwrite( obuf, 1, 1, o ); // Scramble key length
+ SHACrypt_Process( &s, scramblekey, obuf, n );
+ fwrite( obuf, 1, n, o ); // Scramble key
+
/* Do the actual encryption */
while ( ( n = fread( fbuf, 1, 256, f ) ) > 0 ) {
- SHACrypt_Process( &s, fbuf, obuf, n );
+ SHACrypt_Scramble( &s, fbuf, ibuf, n );
+ SHACrypt_Process( &s, ibuf, obuf, n );
fwrite( obuf, 1, n, o );
}
}
void decryptmode( int argc, char **argv ) {
- int n;
+ int n, version;
FILE *f,
*o;
- static char fbuf[256] = {0},
- obuf[256] = {0};
+ unsigned char fbuf[256] = {0},
+ ibuf[256] = {0},
+ obuf[256] = {0},
+ scramblekey[256] = {0},
+ algos,
+ randlen,
+ scramblelen;
SHACrypt_Context s;
- unsigned char algos,
- randlen;
if ( argc > 3 ) {
f = fopen( argv[3], "rb");
@@ -237,20 +253,41 @@
randlen = '\x13';
fread( fbuf, 1, 20, f );
algos = '\x01';
+ version = 2;
} else if ( fbuf[3] == '\2' && fbuf[4] == '\0' ) {
randlen = fgetc( f );
fread( fbuf, 1, (int)randlen + 1, f );
algos = fgetc( f );
+ version = 2;
+ } else if ( fbuf[3] == '\3' && fbuf[4] == '\0' ) {
+ randlen = fgetc( f );
+ fread( fbuf, 1, (int)randlen + 1, f );
+ algos = fgetc( f );
+ version = 3;
} else {
fprintf( stderr, "Input file was not in a format that could be
read by SHACrypt. (Maybe it's a newer version?)" );
exit( 1 );
}
SHACrypt_Init( &s, argv[2], strlen( argv[2] ), algos, fbuf,
(int)randlen + 1 );
+
+ /* Get the scramble key */
+ if ( version >= 3 ) {
+ n = fread( fbuf, 1, 1, f );
+ SHACrypt_Process( &s, fbuf, obuf, 1 );
+ scramblelen = obuf[0];
+
+ n = fread( fbuf, 1, (int)scramblelen + 1, f );
+ SHACrypt_Process( &s, fbuf, scramblekey, n );
+
+ SHACrypt_SetScramble( &s, scramblekey, n );
+ }
/* Do the actual decryption */
while ( ( n = fread( fbuf, 1, 256, f ) ) > 0 ) {
- SHACrypt_Process( &s, fbuf, obuf, n );
+ if ( version >= 3 )
+ SHACrypt_Unscramble( &s, fbuf, ibuf, n );
+ SHACrypt_Process( &s, ibuf, obuf, n );
fwrite( obuf, 1, n, o );
}
@@ -298,7 +335,8 @@
obuf[256] = {0};
SHACrypt_Context s;
unsigned char algos,
- randlen;
+ randlen,
+ *version;
if ( argc > 3 ) {
f = fopen( argv[3], "rb");
@@ -323,17 +361,24 @@
randlen = '\x13';
fread( fbuf, 1, 20, f );
algos = '\x01';
+ version = "\2\0";
} else if ( fbuf[3] == '\2' && fbuf[4] == '\0' ) {
randlen = fgetc( f );
fread( fbuf, 1, (int)randlen + 1, f );
algos = fgetc( f );
+ version = "\2\0";
+ } else if ( fbuf[3] == '\3' && fbuf[4] == '\0' ) {
+ randlen = fgetc( f );
+ fread( fbuf, 1, (int)randlen + 1, f );
+ algos = fgetc( f );
+ version = "\3\0";
} else {
fprintf( stderr, "Input file was not in a format that could be
read by SHACrypt. (Maybe it's a newer version?)" );
exit( 1 );
}
fwrite( identifier, 1, 3, o ); // Identifier
- fwrite( "\2\0", 1, 2, o ); // Format version
+ fwrite( version, 1, 2, o ); // Format version
fputc( randlen, o ); // Random seed length
fwrite( fbuf, 1, (int)randlen + 1, o ); // Random seed
fputc( algos, o ); // Hash algorithms used
=======================================
--- /src/gui.c Sat Mar 13 08:49:22 2010
+++ /src/gui.c Sat Mar 13 14:09:52 2010
@@ -305,9 +305,6 @@
o = fopen( tmp, "wb" );
- g_free( tmp );
- g_free( filename );
-
for ( i = 0; i < n; i++ )
fbuf[i] = g_random_int_range( 0, 255 );
@@ -528,7 +525,6 @@
tmp = g_strdup_printf( "%s%s", filename_prefix, filename_suffix );
-
i = 0;
while ( fopen( tmp, "rb" ) != NULL ) {
g_free( tmp );
=======================================
--- /src/shacrypt.c Sat Mar 13 07:53:27 2010
+++ /src/shacrypt.c Sat Mar 13 14:09:52 2010
@@ -404,8 +404,8 @@
* @version 1.2.2
*/
void SHACrypt_Scramble( SHACrypt_Context* ctx, char* in, char* out,
unsigned int len ) {
- int i;
- char c;
+ unsigned int i;
+ unsigned char c;
// First pass: Just copy
for ( i = 0; i < len; i++ ) {
@@ -523,16 +523,18 @@
* @version 1.2.2
*/
void SHACrypt_Unscramble( SHACrypt_Context* ctx, char* in, char* out,
unsigned int len ) {
- int i;
- char c;
+ unsigned int i;
+ unsigned char c,
+ *buf;
// First pass: Just copy
for ( i = 0; i < len; i++ ) {
out[i] = in[i];
}
- // Second pass: The actual swapping
- for ( i = len; i > -1; i-- ) {
+ // Second pass: Make the buffer
+ buf = malloc( len * sizeof( unsigned char ) );
+ for ( i = 0; i < len; i++ ) {
c = 0;
if ( ctx->algos & '\x01' ) {
@@ -631,8 +633,16 @@
ctx->scramble_whirlpool_ptr++;
}
+ buf[i] = c;
+ }
+
+ // Third pass: The actual swapping
+ for ( i = len; i > -1; i-- ) {
+ c = buf[i];
out[c % len] ^= out[i];
out[i] ^= out[c % len];
out[c % len] ^= out[i];
}
-}
+
+ free( buf );
+}
=======================================
--- /src/shacrypt.h Sat Mar 13 07:26:35 2010
+++ /src/shacrypt.h Sat Mar 13 14:09:52 2010
@@ -24,8 +24,9 @@
#ifndef _SHACRYPT_H_
#define _SHACRYPT_H_
// Legacy methods
-int SHACrypt_XOR( char *in1, char *in2, char *out, int len );
-int SHACrypt_GenKey( char *oldkey, char *newkey, char *password );
+/** @deprecated */ int SHACrypt_XOR( char *in1, char *in2, char *out, int
len );
+/** @deprecated */ int SHACrypt_GenKey( char *oldkey, char *newkey, char
*password );
+
int SHACrypt_GenRand( char *data, int len );
// Methods added in the MultiHash branch
=======================================
--- /tests/Makefile.am Sat Feb 27 09:31:24 2010
+++ /tests/Makefile.am Sat Mar 13 14:09:52 2010
@@ -7,5 +7,7 @@
test_helper_LDADD = ../src/libshacrypt.a
TESTS_ENVIRONMENT = SHACRYPT=$(top_builddir)/src/shacrypt$(EXEEXT) $(SHELL)
-dist_TESTS = t1.sh t2.sh t3.sh t4.sh t5.sh
+TESTS = t1.sh t2.sh t3.sh t4.sh t5.sh
XFAIL_TESTS = t1.sh t5.sh
+
+EXTRA_DIST = $(TESTS)
=======================================
--- /tests/Makefile.in Sat Feb 27 20:17:00 2010
+++ /tests/Makefile.in Sat Mar 13 14:09:52 2010
@@ -59,6 +59,8 @@
DIST_SOURCES = $(test_helper_SOURCES)
ETAGS = etags
CTAGS = ctags
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
@@ -169,8 +171,9 @@
test_helper_SOURCES = test-helper.c ../src/shacrypt.h
test_helper_LDADD = ../src/libshacrypt.a
TESTS_ENVIRONMENT = SHACRYPT=$(top_builddir)/src/shacrypt$(EXEEXT) $(SHELL)
-dist_TESTS = t1.sh t2.sh t3.sh t4.sh t5.sh
+TESTS = t1.sh t2.sh t3.sh t4.sh t5.sh
XFAIL_TESTS = t1.sh t5.sh
+EXTRA_DIST = $(TESTS)
all: all-am
.SUFFIXES:
@@ -288,6 +291,98 @@
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list=' $(TESTS) '; \
+ $(am__tty_colors); \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=XPASS; \
+ ;; \
+ *) \
+ col=$$grn; res=PASS; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xfail=`expr $$xfail + 1`; \
+ col=$$lgn; res=XFAIL; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=FAIL; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ col=$$blu; res=SKIP; \
+ fi; \
+ echo "$${col}$$res$${std}: $$tst"; \
+ done; \
+ if test "$$all" -eq 1; then \
+ tests="test"; \
+ All=""; \
+ else \
+ tests="tests"; \
+ All="All "; \
+ fi; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="$$All$$all $$tests passed"; \
+ else \
+ if test "$$xfail" -eq 1; then failures=failure; else
failures=failures; fi; \
+ banner="$$All$$all $$tests behaved as expected ($$xfail expected
$$failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all $$tests failed"; \
+ else \
+ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+ banner="$$failed of $$all $$tests did not behave as expected
($$xpass unexpected $$passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ if test "$$skip" -eq 1; then \
+ skipped="($$skip test was not run)"; \
+ else \
+ skipped="($$skip tests were not run)"; \
+ fi; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ if test "$$failed" -eq 0; then \
+ echo "$$grn$$dashes"; \
+ else \
+ echo "$$red$$dashes"; \
+ fi; \
+ echo "$$banner"; \
+ test -z "$$skipped" || echo "$$skipped"; \
+ test -z "$$report" || echo "$$report"; \
+ echo "$$dashes$$std"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
@@ -320,6 +415,7 @@
done
check-am: all-am
$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
check: check-am
all-am: Makefile
installdirs:
@@ -419,7 +515,7 @@
.MAKE: check-am install-am install-strip
-.PHONY: CTAGS GTAGS all all-am check check-am clean \
+.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
clean-checkPROGRAMS clean-generic ctags distclean \
distclean-compile distclean-generic distclean-tags distdir dvi \
dvi-am html html-am info info-am install install-am \