From c3f2c015c4dd6ce730af378adb8a56959af8d1ff Mon Sep 17 00:00:00 2001 From: unkernet Date: Sun, 27 Aug 2017 19:39:34 +0300 Subject: [PATCH] Add ability to build on OS X --- .gitignore | 4 ++++ Makefile | 7 ++----- crypto1_bs_crack.c | 7 ++++--- libnfc_crypto1_crack.c | 8 ++++++-- solve_bs.c | 36 ++++++++++++++++++++++++++++-------- solve_piwi.c | 7 +++---- solve_piwi_bs.c | 4 ---- 7 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57b6ba9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +craptev1-v1.1.tar.xz +craptev1-v1.1/* +crapto1-v3.3.tar.xz +crapto1-v3.3/* diff --git a/Makefile b/Makefile index 2e74701..87f634b 100755 --- a/Makefile +++ b/Makefile @@ -15,11 +15,8 @@ CRAPTEV1 = craptev1-v1.1/craptev1.c -I craptev1-v1.1/ CRAPTO1 = crapto1-v3.3/crapto1.c crapto1-v3.3/crypto1.c -I crapto1-v3.3/ CRYPTO1_BS = crypto1_bs.c crypto1_bs_crack.c -solve.so: - $(CC) $(CFLAGS) craptev1-v1.1/solve.c -fPIC -shared -o solve.so - -solve_bs: solve.so - $(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} ./solve.so -o $@ -lpthread +solve_bs: + $(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread solve_piwi_bs: $(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread diff --git a/crypto1_bs_crack.c b/crypto1_bs_crack.c index 9cf5ee2..53e6f75 100644 --- a/crypto1_bs_crack.c +++ b/crypto1_bs_crack.c @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include "crypto1_bs_crack.h" inline uint64_t crack_states_bitsliced(uint32_t **task){ @@ -134,9 +134,10 @@ inline uint64_t crack_states_bitsliced(uint32_t **task){ } #ifdef EXACT_COUNT - bucket_states_tested += bucket_size[block_idx]; + // Fix a "1000000% bug". Looks like here is a problem with OS X gcc + bucket_states_tested += bucket_size[block_idx] > MAX_BITSLICES ? MAX_BITSLICES : bucket_size[block_idx]; #ifdef ONLINE_COUNT - __atomic_fetch_add(&total_states_tested, bucket_size[block_idx], __ATOMIC_RELAXED); + __atomic_fetch_add(&total_states_tested, bucket_size[block_idx] > MAX_BITSLICES ? MAX_BITSLICES : bucket_size[block_idx], __ATOMIC_RELAXED); #endif #else #ifdef ONLINE_COUNT diff --git a/libnfc_crypto1_crack.c b/libnfc_crypto1_crack.c index e1857a9..5f1e283 100755 --- a/libnfc_crypto1_crack.c +++ b/libnfc_crypto1_crack.c @@ -288,7 +288,7 @@ POSSIBILITY OF SUCH DAMAGES. #include #include #include -#include +#include #include #include @@ -676,7 +676,11 @@ int main (int argc, const char * argv[]) { return 1; } - thread_count = get_nprocs_conf(); +#ifndef __WIN32 + thread_count = sysconf(_SC_NPROCESSORS_CONF); +#else + thread_count = 1; +#endif // append some zeroes to the end of the space to make sure threads don't go off into the wild size_t j = 0; for(j = 0; space[j]; j+=5){ diff --git a/solve_bs.c b/solve_bs.c index e244c7f..ccfcd00 100644 --- a/solve_bs.c +++ b/solve_bs.c @@ -1,12 +1,8 @@ #include -#include #include #include #include #include -#ifndef __WIN32 -#include -#endif #include "craptev1.h" #include "crypto1_bs.h" #include "crypto1_bs_crack.h" @@ -17,12 +13,34 @@ #define llu PRIu64 #define lu PRIu32 -// linked from .so / .c files by bla -extern uint64_t *readnonces(char* fname); - uint32_t **space; size_t thread_count = 1; +uint64_t *readnonces(char* fname) { + int i, j, r; + FILE *f = fopen(fname, "r"); + uint64_t *nonces = malloc(sizeof (uint64_t) << 24); + uint32_t byte; + char parities; + + for(i = 0; !feof(f); ++i) { + for(j = nonces[i] = 0; j < 4; ++j) { + r = fscanf(f, "%02x%c ", &byte, &parities); + if(r != 2) { + fprintf(stderr, "Input parse error pos:%ld\n", ftell(f)); + fflush(stderr); + abort(); + } + parities = (parities == '!') ^ parity(byte); + nonces[i] |= byte << 8 * j; + nonces[i] |= ((uint64_t)parities) << (32 + j * 8); + } + } + nonces[i] = -1; + fclose(f); + return nonces; +} + void* crack_states_thread(void* x){ const size_t thread_id = (size_t)x; int j; @@ -51,7 +69,9 @@ int main(int argc, char* argv[]){ total_states = craptev1_sizeof_space(space); #ifndef __WIN32 - thread_count = get_nprocs_conf(); + thread_count = sysconf(_SC_NPROCESSORS_CONF); +#else + thread_count = 1; #endif // append some zeroes to the end of the space to make sure threads don't go off into the wild size_t j = 0; diff --git a/solve_piwi.c b/solve_piwi.c index 3945a93..acc1bc5 100644 --- a/solve_piwi.c +++ b/solve_piwi.c @@ -3,9 +3,6 @@ #include #include #include -#ifndef __WIN32 -#include -#endif #include "craptev1.h" #include #define __STDC_FORMAT_MACROS @@ -74,7 +71,9 @@ int main(int argc, char* argv[]){ total_states = craptev1_sizeof_space(space); #ifndef __WIN32 - thread_count = get_nprocs_conf(); + thread_count = sysconf(_SC_NPROCESSORS_CONF); +#else + thread_count = 1; #endif // append some zeroes to the end of the space to make sure threads don't go off into the wild size_t j = 0; diff --git a/solve_piwi_bs.c b/solve_piwi_bs.c index 6c762a8..f20ef27 100644 --- a/solve_piwi_bs.c +++ b/solve_piwi_bs.c @@ -1,12 +1,8 @@ #include -#include #include #include #include #include -#ifndef __WIN32 -#include -#endif #include "craptev1.h" #include "crypto1_bs.h" #include "crypto1_bs_crack.h"