aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-02-08 06:31:13 +0100
committerMattias Andrée <maandree@operamail.com>2013-02-08 06:31:13 +0100
commit7ad82d0366a352055316c0e2de22dc9abdd292a4 (patch)
tree5c5b967487e8d9a157b5c29feee898cf302472ff
parentm (diff)
downloadsha3sum-7ad82d0366a352055316c0e2de22dc9abdd292a4.tar.gz
sha3sum-7ad82d0366a352055316c0e2de22dc9abdd292a4.tar.bz2
sha3sum-7ad82d0366a352055316c0e2de22dc9abdd292a4.tar.xz
corrected
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--Makefile26
-rw-r--r--README4
-rw-r--r--c/sha3.c11
-rw-r--r--c/sha3sum.c4
-rw-r--r--pure-java/SHA3.java4
-rwxr-xr-xpython3/sha3sum.py10
6 files changed, 41 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 50208d9..f3068b0 100644
--- a/Makefile
+++ b/Makefile
@@ -8,20 +8,36 @@
# [GNU All Permissive License]
JAVAC=javac
+JAVADIRS=-s "pure-java" -d "bin/pure-java" -cp "pure-java"
+JAVAFLAGS=-Xlint
+JAVA_FLAGS=$(JAVADIRS) $(JAVAFLAGS)
+CFLAGS=-W{all,extra} -pedantic
+CPPFLAGS=
+LDFLAGS=
+C_FLAGS=$(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
-JAVA_CLASSES = $(shell find "pure-java" | grep '\.java$$' | sed -e 's_^_bin/_g' -e 's_java$$_class_g')
+JAVA_CLASSES = $(shell find "pure-java" | grep '\.java$$' | sed -e 's_^_bin/_g' -e 's_java$$_class_g')
+C_OBJS = $(shell find "c" | grep '\.h$$' | sed -e 's_^_bin/_g' -e 's_h$$_o_g')
+C_BINS = bin/c/sha3sum
-all: pure-java
+all: pure-java c
pure-java: $(JAVA_CLASSES)
bin/pure-java/%.class: pure-java/%.java
mkdir -p "bin/pure-java"
- $(JAVAC) -s "pure-java" -d "bin/pure-java" -cp "pure-java" "pure-java/$*.java"
-
-
+ $(JAVAC) $(JAVA_FLAGS) "pure-java/$*.java"
+
+c: $(C_OBJS) $(C_BINS)
+bin/c/%.o: c/%.h c/%.c
+ mkdir -p "bin/c"
+ $(CC) $(C_FLAGS) -c "c/$*".{c,h}
+ mv "$*.o" "c/$*.o"
+bin/c/%: c/%.c
+ mkdir -p "bin/c"
+ $(CC) $(C_FLAGS) -o "$@" "c/$*".c "c/"*.o
.PHONY: clean
diff --git a/README b/README
index 6750307..cad6b6d 100644
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
COMPLETE STATUS:
- Pure Java 1.2+ :: incorrect, optimised
+ Pure Java 1.2+ :: optimised
Python 3 :: optimised
- C ISO C90 :: incorrect(as java), not optimised
+ C ISO C90 :: not optimised
Java/C JNI :: planned (after c)
NASM :: planned (maybe, after jni)
Haskell :: planned (maybe)
diff --git a/c/sha3.c b/c/sha3.c
index 47867b8..a21a6a9 100644
--- a/c/sha3.c
+++ b/c/sha3.c
@@ -335,7 +335,7 @@ static byte* pad10star1(byte* msg, long len, long r, long* outlen)
{
byte* message;
- long nrf = len >> 3;
+ long nrf = (len <<= 3) >> 3;
long nbrf = len & 7;
long ll = len % r;
long i;
@@ -382,7 +382,14 @@ extern void initialise(long bitrate, long capacity, long output)
w = b / 25;
l = lb(w);
nr = 12 + (l << 1);
- wmod = w == 64 ? -1LL ? (1LL << w) - 1LL;
+ if (w == 64)
+ wmod = -1;
+ else
+ {
+ wmod = 1;
+ wmod <<= w;
+ wmod--;
+ }
S = (llong*)malloc(25 * sizeof(llong));
M = (byte*)malloc(mlen = (r * b) >> 2);
mptr = 0;
diff --git a/c/sha3sum.c b/c/sha3sum.c
index 993cf94..bc29a58 100644
--- a/c/sha3sum.c
+++ b/c/sha3sum.c
@@ -338,13 +338,13 @@ int main(int argc, char** argv)
if (binary)
{
long j;
+ for (j = 0; j < bn; j++)
+ putchar(*(bs + j));
if (filename == null)
{
stdin = bs;
bs = null;
}
- for (j = 0; j < bn; j++)
- putchar(*(bs + j));
fflush(stdout);
}
else
diff --git a/pure-java/SHA3.java b/pure-java/SHA3.java
index 2e0f774..76d3df4 100644
--- a/pure-java/SHA3.java
+++ b/pure-java/SHA3.java
@@ -318,7 +318,7 @@ public class SHA3
*/
private static byte[] pad10star1(byte[] msg, int len, int r)
{
- int nrf = len >> 3;
+ int nrf = (len <<= 3) >> 3;
int nbrf = len & 7;
int ll = len % r;
@@ -336,8 +336,6 @@ public class SHA3
len = ((len - (len % r) + (r - 8)) >> 3) + 1;
message = new byte[len];
message[nrf] = b;
- //for (long i = nrf + 1; i < len; i++)
- // message[i + nrf] = 0;
message[len - 1] = -128;
}
System.arraycopy(msg, 0, message, 0, nrf);
diff --git a/python3/sha3sum.py b/python3/sha3sum.py
index f7e297a..613b697 100755
--- a/python3/sha3sum.py
+++ b/python3/sha3sum.py
@@ -324,7 +324,7 @@ class SHA3:
@param r:int The bitrate
@return :str The message padded
'''
- nnn = len(msg)
+ nnn = len(msg) << 3
nrf = nnn >> 3
nbrf = nnn & 7
@@ -341,8 +341,6 @@ class SHA3:
message = [0] * (nnn - nrf)
message[0] = bbbb
nnn -= nrf
- #for i in range(1, nnn):
- # message[i] = 0
message[nnn - 1] = 0x80
return msg[:nrf] + bytes(message)
@@ -698,7 +696,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
fn = '/dev/stdin' if filename is None else filename
with open(fn, 'rb') as file:
SHA3.initialise(r, c, o)
- blksize = os.stat(os.path.realpath(fn)).st_size
+ blksize = (o + 7) >> 3
+ try:
+ blksize = os.stat(os.path.realpath(fn)).st_size
+ except:
+ pass
while True:
chunk = file.read(blksize)
if len(chunk) == 0: