Add ability to build on OS X

This commit is contained in:
unkernet
2017-08-27 19:39:34 +03:00
parent 9598dc1b6c
commit c3f2c015c4
7 changed files with 47 additions and 26 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
craptev1-v1.1.tar.xz
craptev1-v1.1/*
crapto1-v3.3.tar.xz
crapto1-v3.3/*

View File

@ -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/ CRAPTO1 = crapto1-v3.3/crapto1.c crapto1-v3.3/crypto1.c -I crapto1-v3.3/
CRYPTO1_BS = crypto1_bs.c crypto1_bs_crack.c CRYPTO1_BS = crypto1_bs.c crypto1_bs_crack.c
solve.so: solve_bs:
$(CC) $(CFLAGS) craptev1-v1.1/solve.c -fPIC -shared -o solve.so $(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread
solve_bs: solve.so
$(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} ./solve.so -o $@ -lpthread
solve_piwi_bs: solve_piwi_bs:
$(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread $(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread

View File

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#include <malloc.h> #include <stdlib.h>
#include "crypto1_bs_crack.h" #include "crypto1_bs_crack.h"
inline uint64_t crack_states_bitsliced(uint32_t **task){ 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 #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 #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 #endif
#else #else
#ifdef ONLINE_COUNT #ifdef ONLINE_COUNT

View File

@ -288,7 +288,7 @@ POSSIBILITY OF SUCH DAMAGES.
#include <signal.h> #include <signal.h>
#include <pthread.h> #include <pthread.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/sysinfo.h> #include <unistd.h>
#include <nfc/nfc.h> #include <nfc/nfc.h>
#include <math.h> #include <math.h>
@ -676,7 +676,11 @@ int main (int argc, const char * argv[]) {
return 1; 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 // append some zeroes to the end of the space to make sure threads don't go off into the wild
size_t j = 0; size_t j = 0;
for(j = 0; space[j]; j+=5){ for(j = 0; space[j]; j+=5){

View File

@ -1,12 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#ifndef __WIN32
#include <sys/sysinfo.h>
#endif
#include "craptev1.h" #include "craptev1.h"
#include "crypto1_bs.h" #include "crypto1_bs.h"
#include "crypto1_bs_crack.h" #include "crypto1_bs_crack.h"
@ -17,12 +13,34 @@
#define llu PRIu64 #define llu PRIu64
#define lu PRIu32 #define lu PRIu32
// linked from .so / .c files by bla
extern uint64_t *readnonces(char* fname);
uint32_t **space; uint32_t **space;
size_t thread_count = 1; 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){ void* crack_states_thread(void* x){
const size_t thread_id = (size_t)x; const size_t thread_id = (size_t)x;
int j; int j;
@ -51,7 +69,9 @@ int main(int argc, char* argv[]){
total_states = craptev1_sizeof_space(space); total_states = craptev1_sizeof_space(space);
#ifndef __WIN32 #ifndef __WIN32
thread_count = get_nprocs_conf(); thread_count = sysconf(_SC_NPROCESSORS_CONF);
#else
thread_count = 1;
#endif #endif
// append some zeroes to the end of the space to make sure threads don't go off into the wild // append some zeroes to the end of the space to make sure threads don't go off into the wild
size_t j = 0; size_t j = 0;

View File

@ -3,9 +3,6 @@
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#ifndef __WIN32
#include <sys/sysinfo.h>
#endif
#include "craptev1.h" #include "craptev1.h"
#include <inttypes.h> #include <inttypes.h>
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
@ -74,7 +71,9 @@ int main(int argc, char* argv[]){
total_states = craptev1_sizeof_space(space); total_states = craptev1_sizeof_space(space);
#ifndef __WIN32 #ifndef __WIN32
thread_count = get_nprocs_conf(); thread_count = sysconf(_SC_NPROCESSORS_CONF);
#else
thread_count = 1;
#endif #endif
// append some zeroes to the end of the space to make sure threads don't go off into the wild // append some zeroes to the end of the space to make sure threads don't go off into the wild
size_t j = 0; size_t j = 0;

View File

@ -1,12 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#ifndef __WIN32
#include <sys/sysinfo.h>
#endif
#include "craptev1.h" #include "craptev1.h"
#include "crypto1_bs.h" #include "crypto1_bs.h"
#include "crypto1_bs_crack.h" #include "crypto1_bs_crack.h"