Merge pull request #24 from unkernet/master
Display cracking progress in solve_bs and port to OS X
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
craptev1-v1.1.tar.xz
|
||||
craptev1-v1.1/*
|
||||
crapto1-v3.3.tar.xz
|
||||
crapto1-v3.3/*
|
9
Makefile
9
Makefile
@ -15,14 +15,11 @@ 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 -lm
|
||||
|
||||
solve_piwi_bs:
|
||||
$(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread
|
||||
$(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread -lm
|
||||
|
||||
solve_piwi:
|
||||
$(CC) $(CFLAGS) $@.c $(CRYPTO1_BS) $(CRAPTO1) ${CRAPTEV1} -o $@ -lpthread
|
||||
|
@ -22,7 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include "crypto1_bs_crack.h"
|
||||
|
||||
inline uint64_t crack_states_bitsliced(uint32_t **task){
|
||||
@ -133,10 +136,13 @@ inline uint64_t crack_states_bitsliced(uint32_t **task){
|
||||
}
|
||||
}
|
||||
|
||||
// Fix a "1000000% bug". Looks like here is a problem with OS X gcc
|
||||
size_t current_bucket_size = bucket_size[block_idx] > MAX_BITSLICES ? MAX_BITSLICES : bucket_size[block_idx];
|
||||
|
||||
#ifdef EXACT_COUNT
|
||||
bucket_states_tested += bucket_size[block_idx];
|
||||
bucket_states_tested += current_bucket_size;
|
||||
#ifdef ONLINE_COUNT
|
||||
__atomic_fetch_add(&total_states_tested, bucket_size[block_idx], __ATOMIC_RELAXED);
|
||||
__atomic_fetch_add(&total_states_tested, current_bucket_size, __ATOMIC_RELAXED);
|
||||
#endif
|
||||
#else
|
||||
#ifdef ONLINE_COUNT
|
||||
|
@ -288,7 +288,7 @@ POSSIBILITY OF SUCH DAMAGES.
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <unistd.h>
|
||||
#include <nfc/nfc.h>
|
||||
#include <math.h>
|
||||
|
||||
@ -517,6 +517,7 @@ void * update_predictions_thread(void* p){
|
||||
if(space){
|
||||
total_states = craptev1_sizeof_space(space);
|
||||
}
|
||||
sleep(1); // We don't need to check this more often than once per second
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -676,7 +677,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){
|
||||
|
69
solve_bs.c
69
solve_bs.c
@ -1,27 +1,52 @@
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#ifndef __WIN32
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
#include "craptev1.h"
|
||||
#include "crypto1_bs.h"
|
||||
#include "crypto1_bs_crack.h"
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#define llx PRIx64
|
||||
#define lli PRIi64
|
||||
#define llu PRIu64
|
||||
#define lu PRIu32
|
||||
|
||||
// linked from .so / .c files by bla
|
||||
extern uint64_t *readnonces(char* fname);
|
||||
#define VT100_cleareol "\r\33[2K"
|
||||
|
||||
uint32_t **space;
|
||||
size_t thread_count = 1;
|
||||
uint8_t thread_count = 1;
|
||||
|
||||
uint64_t *readnonces(char* fname) {
|
||||
int i, j;
|
||||
FILE *f = fopen(fname, "r");
|
||||
if (f == NULL) {
|
||||
fprintf(stderr, "Cannot open file.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
uint64_t *nonces = malloc(sizeof (uint64_t) << 24);
|
||||
uint32_t nt;
|
||||
char par;
|
||||
|
||||
i = 0;
|
||||
while(!feof(f)){
|
||||
nonces[i] = 0;
|
||||
for(j = 0; j < 32; j += 8) {
|
||||
if(2 != fscanf(f, "%02x%c ", &nt, &par)) {
|
||||
fprintf(stderr, "Input format error at line:%d\n", i);
|
||||
fflush(stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
nonces[i] |= nt << j | (uint64_t)((par == '!') ^ parity(nt)) << (32 + j);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
nonces[i] = -1;
|
||||
fclose(f);
|
||||
return nonces;
|
||||
}
|
||||
|
||||
void* crack_states_thread(void* x){
|
||||
const size_t thread_id = (size_t)x;
|
||||
@ -33,25 +58,34 @@ void* crack_states_thread(void* x){
|
||||
break;
|
||||
} else if(keys_found){
|
||||
break;
|
||||
} else {
|
||||
printf("Cracking... %6.02f%%\n", (total_states_tested/(total_states/100.0)));
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void notify_status_offline(int sig){
|
||||
printf(VT100_cleareol "Cracking... %6.02f%%", (100.0*total_states_tested/(total_states)));
|
||||
alarm(1);
|
||||
fflush(stdout);
|
||||
signal(SIGALRM, notify_status_offline);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc != 3){
|
||||
printf("Usage: %s <nonces.txt> <uid>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
printf("Reading nonces...\n");
|
||||
uint64_t *nonces = readnonces(argv[1]);
|
||||
uint32_t uid = strtoul(argv[2], NULL, 16);
|
||||
printf("Deriving search space...\n");
|
||||
space = craptev1_get_space(nonces, 95, uid);
|
||||
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;
|
||||
@ -87,14 +121,23 @@ int main(int argc, char* argv[]){
|
||||
total_states_tested = 0;
|
||||
keys_found = 0;
|
||||
|
||||
printf("Starting %zu threads to test %"llu" states\n", thread_count, total_states);
|
||||
printf("Starting %u threads to test %"llu" (~2^%0.2f) states\n", thread_count, total_states, log(total_states) / log(2));
|
||||
|
||||
signal(SIGALRM, notify_status_offline);
|
||||
alarm(1);
|
||||
|
||||
for(i = 0; i < thread_count; i++){
|
||||
pthread_create(&threads[i], NULL, crack_states_thread, (void*) i);
|
||||
}
|
||||
for(i = 0; i < thread_count; i++){
|
||||
pthread_join(threads[i], 0);
|
||||
}
|
||||
printf("Tested %"llu" states\n", total_states_tested);
|
||||
|
||||
alarm(0);
|
||||
|
||||
printf("\nTested %"llu" states\n", total_states_tested);
|
||||
|
||||
if(!keys_found) fprintf(stderr, "No solution found :(\n");
|
||||
|
||||
craptev1_destroy_space(space);
|
||||
return 0;
|
||||
|
@ -3,9 +3,6 @@
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#ifndef __WIN32
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
#include "craptev1.h"
|
||||
#include <inttypes.h>
|
||||
#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;
|
||||
|
@ -1,21 +1,20 @@
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#ifndef __WIN32
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
#include "craptev1.h"
|
||||
#include "crypto1_bs.h"
|
||||
#include "crypto1_bs_crack.h"
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#define llx PRIx64
|
||||
#define lli PRIi64
|
||||
#define llu PRIu64
|
||||
#define lu PRIu32
|
||||
#define VT100_cleareol "\r\33[2K"
|
||||
|
||||
uint64_t split(uint8_t p){
|
||||
return (((p & 0x8) >>3 )| ((p & 0x4) >> 2) << 8 | ((p & 0x2) >> 1) << 16 | (p & 0x1) << 24 );
|
||||
@ -25,6 +24,10 @@ uint32_t uid;
|
||||
uint64_t *readnonces(char* fname){
|
||||
int i;
|
||||
FILE *f = fopen(fname, "rb");
|
||||
if (f == NULL) {
|
||||
fprintf(stderr, "Cannot open file.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
uint64_t *nonces = malloc(sizeof (uint64_t) << 24);
|
||||
if(fread(&uid, 1, 4, f)){
|
||||
uid = rev32(uid);
|
||||
@ -58,19 +61,26 @@ void* crack_states_thread(void* x){
|
||||
break;
|
||||
} else if(keys_found){
|
||||
break;
|
||||
} else {
|
||||
printf("Cracking... %6.02f%%\n", (100.0*total_states_tested/(total_states)));
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void notify_status_offline(int sig){
|
||||
printf(VT100_cleareol "Cracking... %6.02f%%", (100.0*total_states_tested/(total_states)));
|
||||
alarm(1);
|
||||
fflush(stdout);
|
||||
signal(SIGALRM, notify_status_offline);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
if(argc != 2){
|
||||
printf("Usage: %s <nonces.bin>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
printf("Reading nonces...\n");
|
||||
uint64_t *nonces = readnonces(argv[1]);
|
||||
printf("Deriving search space...\n");
|
||||
space = craptev1_get_space(nonces, 95, uid);
|
||||
total_states = craptev1_sizeof_space(space);
|
||||
|
||||
@ -114,13 +124,20 @@ int main(int argc, char* argv[]){
|
||||
total_states_tested = 0;
|
||||
keys_found = 0;
|
||||
|
||||
printf("Starting %u threads to test %"llu" states\n", thread_count, total_states);
|
||||
printf("Starting %u threads to test %"llu" (~2^%0.2f) states\n", thread_count, total_states, log(total_states) / log(2));
|
||||
|
||||
signal(SIGALRM, notify_status_offline);
|
||||
alarm(1);
|
||||
|
||||
for(i = 0; i < thread_count; i++){
|
||||
pthread_create(&threads[i], NULL, crack_states_thread, (void*) i);
|
||||
}
|
||||
for(i = 0; i < thread_count; i++){
|
||||
pthread_join(threads[i], 0);
|
||||
}
|
||||
|
||||
alarm(0);
|
||||
|
||||
printf("Tested %"llu" states\n", total_states_tested);
|
||||
|
||||
craptev1_destroy_space(space);
|
||||
|
Reference in New Issue
Block a user