From ab97910b5d094d1c77395316c5625453344fa365 Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 13:27:50 -0600 Subject: [PATCH 1/8] declare int outside of loop --- x21s.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/x21s.c b/x21s.c index 3896b5a..74f94b6 100644 --- a/x21s.c +++ b/x21s.c @@ -47,18 +47,20 @@ static void getAlgoString(const uint8_t* prevblock, char *output) { strcpy(output, "0123456789ABCDEF"); - for(int i = 0; i < 16; i++){ - uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed - uint8_t algoDigit = (i & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; - - int offset = algoDigit; - // insert the nth character at the front - char oldVal = output[offset]; - for(int j=offset; j-->0;) { - output[j+1] = output[j]; - } - output[0] = oldVal; - } + int i; + + for(i = 0; i < 16; i++){ + uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed + uint8_t algoDigit = (i & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; + + int offset = algoDigit; + // insert the nth character at the front + char oldVal = output[offset]; + for(int j=offset; j-->0;) { + output[j+1] = output[j]; + } + output[0] = oldVal; + } } void x21s_hash(const char* input, char* output, uint32_t len) { @@ -91,7 +93,9 @@ void x21s_hash(const char* input, char* output, uint32_t len) { getAlgoString(&input[4], hashOrder); - for (int i = 0; i < 16; i++) + int i; + + for (i = 0; i < 16; i++) { const char elem = hashOrder[i]; const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; From 31c699dab51b539d999471ebba9fd659848b13e7 Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 13:30:14 -0600 Subject: [PATCH 2/8] declare int outside of loop --- x21s.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x21s.c b/x21s.c index 74f94b6..15fe103 100644 --- a/x21s.c +++ b/x21s.c @@ -49,14 +49,15 @@ static void getAlgoString(const uint8_t* prevblock, char *output) int i; - for(i = 0; i < 16; i++){ + for (i = 0; i < 16; i++){ uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed uint8_t algoDigit = (i & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; int offset = algoDigit; // insert the nth character at the front char oldVal = output[offset]; - for(int j=offset; j-->0;) { + int j; + for (j = offset; j-->0;) { output[j+1] = output[j]; } output[0] = oldVal; From a66b8ae21cacfeb90ab4fac4b67b39394d3e2919 Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 19:52:46 -0600 Subject: [PATCH 3/8] dynamic -> static function def --- sph/haval.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/sph/haval.c b/sph/haval.c index f9a8918..4ff9f48 100644 --- a/sph/haval.c +++ b/sph/haval.c @@ -11,7 +11,7 @@ * ==========================(LICENSE BEGIN)============================ * * Copyright (c) 2007-2010 Projet RNRT SAPHIR - * + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -19,10 +19,10 @@ * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -634,7 +634,7 @@ haval_init(sph_haval_context *sc, unsigned olen, unsigned passes) sc->count_high = 0; sc->count_low = 0; #endif - + } /* @@ -919,7 +919,27 @@ API(224, 4) API(224, 5) API(256, 3) API(256, 4) -API(256, 5) +// API(256, 5) + +void sph_haval256_5_init(void *cc) +{ + haval_init(cc, 256 >> 5, 5); +} + +void sph_haval256_5 (void *cc, const void *data, size_t len) +{ + haval5(cc, data, len); +} + +void sph_haval256_5_close(void *cc, void *dst) +{ + haval5_close(cc, 0, 0, dst); +} + +void sph_haval256_5addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) +{ + haval5_close(cc, ub, n, dst); +} #define RVAL do { \ s0 = val[0]; \ @@ -980,4 +1000,4 @@ sph_haval_5_comp(const sph_u32 msg[32], sph_u32 val[8]) #ifdef __cplusplus } -#endif +#endif From 69711c2dbfba347b9e89a2c1f45535666d7d0cf3 Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 20:39:02 -0600 Subject: [PATCH 4/8] revert previous --- sph/haval.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/sph/haval.c b/sph/haval.c index 4ff9f48..6630489 100644 --- a/sph/haval.c +++ b/sph/haval.c @@ -919,27 +919,7 @@ API(224, 4) API(224, 5) API(256, 3) API(256, 4) -// API(256, 5) - -void sph_haval256_5_init(void *cc) -{ - haval_init(cc, 256 >> 5, 5); -} - -void sph_haval256_5 (void *cc, const void *data, size_t len) -{ - haval5(cc, data, len); -} - -void sph_haval256_5_close(void *cc, void *dst) -{ - haval5_close(cc, 0, 0, dst); -} - -void sph_haval256_5addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst) -{ - haval5_close(cc, ub, n, dst); -} +API(256, 5) #define RVAL do { \ s0 = val[0]; \ From 7c4b5ffd19e14094ffc591d46b23f0d6a5e257d1 Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 20:39:11 -0600 Subject: [PATCH 5/8] add sph/haval to bindings --- binding.gyp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/binding.gyp b/binding.gyp index d3295da..76df7d4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -47,16 +47,17 @@ "sha3/sph_whirlpool.c", "sha3/sph_shabal.c", "sha3/hamsi.c", - "sha3/sha2.c", - "sha3/sph_sha2big.c", + "sha3/sha2.c", + "sha3/sph_sha2big.c", "whirlpoolx.c", "x11.c", "x11ghost.c", "x13.c", "x14.c", "x15.c", - "x16r.c", - "x21s.c", + "x16r.c", + "sph/haval.c", + "x21s.c", "zr5.c", "crypto/oaes_lib.c", "crypto/c_keccak.c", From 1cb75413466e4e99ba0159205e4e83906aa0032d Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 21:09:21 -0600 Subject: [PATCH 6/8] add files to binding.gyp --- binding.gyp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/binding.gyp b/binding.gyp index 76df7d4..c9ea20c 100644 --- a/binding.gyp +++ b/binding.gyp @@ -57,6 +57,25 @@ "x15.c", "x16r.c", "sph/haval.c", + "sph/tiger.c", + "sph/ghost_streebog.c", + "sph/sph_sha2.c", + "sph/blake.c", + "sph/bmw.c", + "sph/groestl.c", + "sph/skein.c", + "sph/jh.c", + "sph/keccak.c", + "sph/luffa.c", + "sph/cubehash.c", + "sph/shavite.c", + "sph/simd.c", + "sph/echo.c", + "sph/hamsi.c", + "sph/fugue.c", + "sph/shabal.c", + "sph/whirlpool.c", + "sph/sph_sha2big.c", "x21s.c", "zr5.c", "crypto/oaes_lib.c", From b4db521d810594646adfded13568570fe0d4069c Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 21:12:41 -0600 Subject: [PATCH 7/8] typo --- binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index c9ea20c..12acb1b 100644 --- a/binding.gyp +++ b/binding.gyp @@ -58,7 +58,7 @@ "x16r.c", "sph/haval.c", "sph/tiger.c", - "sph/ghost_streebog.c", + "sph/gost_streebog.c", "sph/sph_sha2.c", "sph/blake.c", "sph/bmw.c", From 7837e24ff6d87c9869d973a184464785586e27ed Mon Sep 17 00:00:00 2001 From: Jayson Jacobs Date: Thu, 17 Oct 2019 21:16:43 -0600 Subject: [PATCH 8/8] remove duplicate defs --- binding.gyp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/binding.gyp b/binding.gyp index 12acb1b..00cfc40 100644 --- a/binding.gyp +++ b/binding.gyp @@ -59,23 +59,6 @@ "sph/haval.c", "sph/tiger.c", "sph/gost_streebog.c", - "sph/sph_sha2.c", - "sph/blake.c", - "sph/bmw.c", - "sph/groestl.c", - "sph/skein.c", - "sph/jh.c", - "sph/keccak.c", - "sph/luffa.c", - "sph/cubehash.c", - "sph/shavite.c", - "sph/simd.c", - "sph/echo.c", - "sph/hamsi.c", - "sph/fugue.c", - "sph/shabal.c", - "sph/whirlpool.c", - "sph/sph_sha2big.c", "x21s.c", "zr5.c", "crypto/oaes_lib.c",