Provide msclock() as Milliseconds timer for performance measures (#231)

- don't use clock(). It has different functionalities in Windows and Linux
- move sleep functions to util.h
This commit is contained in:
pwpiwi 2017-03-12 15:06:27 +01:00 committed by GitHub
parent 0ca9bc0e99
commit acf0582d53
29 changed files with 162 additions and 150 deletions

View file

@ -54,7 +54,6 @@ endif
CORESRCS = uart.c \ CORESRCS = uart.c \
util.c \ util.c \
sleep.c
CMDSRCS = crapto1/crapto1.c\ CMDSRCS = crapto1/crapto1.c\

View file

@ -8,7 +8,6 @@
// CRC Calculations from the software reveng commands // CRC Calculations from the software reveng commands
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <stdlib.h>
#ifdef _WIN32 #ifdef _WIN32
# include <io.h> # include <io.h>
# include <fcntl.h> # include <fcntl.h>
@ -19,8 +18,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
//#include <stdlib.h> #include <stdlib.h>
//#include <ctype.h> #include <ctype.h>
#include "cmdmain.h" #include "cmdmain.h"
#include "cmdcrc.h" #include "cmdcrc.h"
#include "reveng/reveng.h" #include "reveng/reveng.h"

View file

@ -8,10 +8,12 @@
// High frequency commands // High frequency commands
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "proxmark3.h" #include "proxmark3.h"
#include "util.h" #include "util.h"
#include "data.h"
#include "ui.h" #include "ui.h"
#include "iso14443crc.h" #include "iso14443crc.h"
#include "cmdmain.h" #include "cmdmain.h"

View file

@ -431,7 +431,7 @@ int CmdHF14ACUIDs(const char *Cmd)
n = n > 0 ? n : 1; n = n > 0 ? n : 1;
PrintAndLog("Collecting %d UIDs", n); PrintAndLog("Collecting %d UIDs", n);
PrintAndLog("Start: %u", time(NULL)); PrintAndLog("Start: %" PRIu64, msclock()/1000);
// repeat n times // repeat n times
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
// execute anticollision procedure // execute anticollision procedure
@ -454,7 +454,7 @@ int CmdHF14ACUIDs(const char *Cmd)
PrintAndLog("%s", uid_string); PrintAndLog("%s", uid_string);
} }
} }
PrintAndLog("End: %u", time(NULL)); PrintAndLog("End: %" PRIu64, msclock()/1000);
return 1; return 1;
} }

View file

@ -12,13 +12,14 @@
#ifndef CMDHF14A_H__ #ifndef CMDHF14A_H__
#define CMDHF14A_H__ #define CMDHF14A_H__
int CmdHF14A(const char *Cmd); #include <stdint.h>
int CmdHF14A(const char *Cmd);
int CmdHF14AList(const char *Cmd); int CmdHF14AList(const char *Cmd);
int CmdHF14AMifare(const char *Cmd); int CmdHF14AMifare(const char *Cmd);
int CmdHF14AReader(const char *Cmd); int CmdHF14AReader(const char *Cmd);
int CmdHF14ASim(const char *Cmd); int CmdHF14ASim(const char *Cmd);
int CmdHF14ASnoop(const char *Cmd); int CmdHF14ASnoop(const char *Cmd);
char* getTagInfo(uint8_t uid); char* getTagInfo(uint8_t uid);
#endif #endif

View file

@ -8,15 +8,19 @@
// Commands related to the German electronic Identification Card // Commands related to the German electronic Identification Card
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "util.h" #include "cmdhfepa.h"
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include "util.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "ui.h" #include "ui.h"
#include "cmdparser.h" #include "cmdparser.h"
#include "common.h" #include "common.h"
#include "cmdmain.h" #include "cmdmain.h"
#include "sleep.h"
#include "cmdhfepa.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
@ -37,7 +41,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
n = n > 0 ? n : 1; n = n > 0 ? n : 1;
PrintAndLog("Collecting %u %u-byte nonces", n, m); PrintAndLog("Collecting %u %u-byte nonces", n, m);
PrintAndLog("Start: %u", time(NULL)); PrintAndLog("Start: %" PRIu64 , msclock()/1000);
// repeat n times // repeat n times
for (unsigned int i = 0; i < n; i++) { for (unsigned int i = 0; i < n; i++) {
// execute PACE // execute PACE
@ -64,7 +68,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
sleep(d); sleep(d);
} }
} }
PrintAndLog("End: %u", time(NULL)); PrintAndLog("End: %" PRIu64, msclock()/1000);
return 1; return 1;
} }

View file

@ -9,8 +9,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <inttypes.h> #include <inttypes.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include "proxmark3.h" #include "proxmark3.h"
#include "cmdmain.h" #include "cmdmain.h"
#include "util.h" #include "util.h"
@ -688,8 +690,8 @@ int CmdHF14AMfNested(const char *Cmd)
} }
} }
else { // ------------------------------------ multiple sectors working else { // ------------------------------------ multiple sectors working
clock_t time1; uint64_t msclock1;
time1 = clock(); msclock1 = msclock();
e_sector = calloc(SectorsCnt, sizeof(sector_t)); e_sector = calloc(SectorsCnt, sizeof(sector_t));
if (e_sector == NULL) return 1; if (e_sector == NULL) return 1;
@ -759,7 +761,7 @@ int CmdHF14AMfNested(const char *Cmd)
} }
} }
printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/iterations/CLOCKS_PER_SEC); printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)(msclock() - msclock1))/1000.0, ((float)(msclock() - msclock1))/iterations/1000.0);
PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations); PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);
//print them //print them

View file

@ -8,12 +8,15 @@
// High frequency MIFARE ULTRALIGHT (C) commands // High frequency MIFARE ULTRALIGHT (C) commands
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "cmdhfmfu.h"
#include <stdint.h>
#include <stdio.h>
#include "proxmark3.h" #include "proxmark3.h"
#include "usb_cmd.h" #include "usb_cmd.h"
#include "cmdmain.h" #include "cmdmain.h"
#include "ui.h" #include "ui.h"
#include "loclass/des.h" #include "loclass/des.h"
#include "cmdhfmfu.h"
#include "cmdhfmf.h" #include "cmdhfmf.h"
#include "cmdhf14a.h" #include "cmdhf14a.h"
#include "mifare.h" #include "mifare.h"

View file

@ -10,6 +10,7 @@
// Low frequency AWID26 commands // Low frequency AWID26 commands
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <string.h>
#include <stdio.h> // sscanf #include <stdio.h> // sscanf
#include "proxmark3.h" // Definitions, USB controls, etc #include "proxmark3.h" // Definitions, USB controls, etc
#include "ui.h" // PrintAndLog #include "ui.h" // PrintAndLog

View file

@ -14,6 +14,7 @@
#include "proxmark3.h" #include "proxmark3.h"
#include "ui.h" #include "ui.h"
#include "util.h" #include "util.h"
#include "data.h"
#include "graph.h" #include "graph.h"
#include "cmdparser.h" #include "cmdparser.h"
#include "cmddata.h" #include "cmddata.h"

View file

@ -19,7 +19,6 @@
#include "util.h" #include "util.h"
#include "hitag2.h" #include "hitag2.h"
#include "hitagS.h" #include "hitagS.h"
#include "sleep.h"
#include "cmdmain.h" #include "cmdmain.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);

View file

@ -8,6 +8,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h>
#include "cmdlfpresco.h" #include "cmdlfpresco.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "ui.h" #include "ui.h"

View file

@ -8,6 +8,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h>
#include "cmdlfpyramid.h" #include "cmdlfpyramid.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "ui.h" #include "ui.h"

View file

@ -10,6 +10,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <ctype.h>
#include <time.h>
#include "proxmark3.h" #include "proxmark3.h"
#include "ui.h" #include "ui.h"
#include "graph.h" #include "graph.h"

View file

@ -12,7 +12,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include "sleep.h"
#include "cmdparser.h" #include "cmdparser.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "data.h" #include "data.h"

View file

@ -12,8 +12,9 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include <unistd.h>
#include "proxmark3.h" #include "proxmark3.h"
#include "sleep.h" #include "util.h"
#include "flash.h" #include "flash.h"
#include "elf.h" #include "elf.h"
#include "proxendian.h" #include "proxendian.h"

View file

@ -10,8 +10,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include "sleep.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "util.h"
#include "flash.h" #include "flash.h"
#include "uart.h" #include "uart.h"
#include "usb_cmd.h" #include "usb_cmd.h"

View file

@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "sleep.h"
#include "proxusb.h" #include "proxusb.h"
#include "flash.h" #include "flash.h"
#include "elf.h" #include "elf.h"

View file

@ -9,7 +9,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "sleep.h"
#include "proxusb.h" #include "proxusb.h"
#include "flash.h" #include "flash.h"

View file

@ -18,7 +18,6 @@
#include <strings.h> #include <strings.h>
#include <errno.h> #include <errno.h>
#include "sleep.h"
#include "proxusb.h" #include "proxusb.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "usb_cmd.h" #include "usb_cmd.h"

View file

@ -40,7 +40,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include "util.h"
#include "cipherutils.h" #include "cipherutils.h"
#include "cipher.h" #include "cipher.h"
#include "ikeys.h" #include "ikeys.h"
@ -512,7 +512,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[])
uint8_t i; uint8_t i;
int errors = 0; int errors = 0;
size_t itemsize = sizeof(dumpdata); size_t itemsize = sizeof(dumpdata);
clock_t t1 = clock(); uint64_t t1 = msclock();
dumpdata* attack = (dumpdata* ) malloc(itemsize); dumpdata* attack = (dumpdata* ) malloc(itemsize);
@ -522,8 +522,8 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[])
errors += bruteforceItem(*attack, keytable); errors += bruteforceItem(*attack, keytable);
} }
free(attack); free(attack);
t1 = clock() - t1; t1 = msclock() - t1;
float diff = ((float)t1 / CLOCKS_PER_SEC ); float diff = (float)t1 / 1000.0;
prnlog("\nPerformed full crack in %f seconds", diff); prnlog("\nPerformed full crack in %f seconds", diff);
// Pick out the first 16 bytes of the keytable. // Pick out the first 16 bytes of the keytable.

View file

@ -10,10 +10,9 @@
// MIFARE Darkside hack // MIFARE Darkside hack
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <inttypes.h>
#include <time.h>
#include "nonce2key.h" #include "nonce2key.h"
#include <inttypes.h>
#include "mifarehost.h" #include "mifarehost.h"
#include "ui.h" #include "ui.h"
#include "util.h" #include "util.h"
@ -160,7 +159,7 @@ bool mfkey32(nonces_t data, uint64_t *outputkey) {
uint32_t ar0_enc = data.ar; // first encrypted reader response uint32_t ar0_enc = data.ar; // first encrypted reader response
uint32_t nr1_enc = data.nr2; // second encrypted reader challenge uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
uint32_t ar1_enc = data.ar2; // second encrypted reader response uint32_t ar1_enc = data.ar2; // second encrypted reader response
clock_t t1 = clock(); uint64_t t1 = msclock();
bool isSuccess = false; bool isSuccess = false;
uint8_t counter=0; uint8_t counter=0;
@ -181,8 +180,8 @@ bool mfkey32(nonces_t data, uint64_t *outputkey) {
} }
} }
isSuccess = (counter == 1); isSuccess = (counter == 1);
t1 = clock() - t1; t1 = msclock() - t1;
//if ( t1 > 0 ) PrintAndLog("Time in mfkey32: %.0f ticks \nFound %d possible keys", (float)t1, counter); //if ( t1 > 0 ) PrintAndLog("Time in mfkey32: %.1f seconds \nFound %d possible keys", (float)t1/1000.0, counter);
*outputkey = ( isSuccess ) ? outkey : 0; *outputkey = ( isSuccess ) ? outkey : 0;
crypto1_destroy(s); crypto1_destroy(s);
/* //un-comment to save all keys to a stats.txt file /* //un-comment to save all keys to a stats.txt file
@ -212,7 +211,7 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) {
int counter = 0; int counter = 0;
//PrintAndLog("Enter mfkey32_moebius"); //PrintAndLog("Enter mfkey32_moebius");
clock_t t1 = clock(); uint64_t t1 = msclock();
s = lfsr_recovery32(ar0_enc ^ prng_successor(nt0, 64), 0); s = lfsr_recovery32(ar0_enc ^ prng_successor(nt0, 64), 0);
@ -233,8 +232,8 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) {
} }
} }
isSuccess = (counter == 1); isSuccess = (counter == 1);
t1 = clock() - t1; t1 = msclock() - t1;
//if ( t1 > 0 ) PrintAndLog("Time in mfkey32_moebius: %.0f ticks \nFound %d possible keys", (float)t1,counter); //if ( t1 > 0 ) PrintAndLog("Time in mfkey32_moebius: %.1f seconds \nFound %d possible keys", (float)t1/1000.0, counter);
*outputkey = ( isSuccess ) ? outkey : 0; *outputkey = ( isSuccess ) ? outkey : 0;
crypto1_destroy(s); crypto1_destroy(s);
/* // un-comment to output all keys to stats.txt /* // un-comment to output all keys to stats.txt
@ -265,7 +264,7 @@ int tryMfk64(uint32_t uid, uint32_t nt, uint32_t nr_enc, uint32_t ar_enc, uint32
struct Crypto1State *revstate; struct Crypto1State *revstate;
PrintAndLog("Enter mfkey64"); PrintAndLog("Enter mfkey64");
clock_t t1 = clock(); uint64_t t1 = msclock();
// Extract the keystream from the messages // Extract the keystream from the messages
ks2 = ar_enc ^ prng_successor(nt, 64); ks2 = ar_enc ^ prng_successor(nt, 64);
@ -280,8 +279,8 @@ int tryMfk64(uint32_t uid, uint32_t nt, uint32_t nr_enc, uint32_t ar_enc, uint32
crypto1_destroy(revstate); crypto1_destroy(revstate);
*outputkey = key; *outputkey = key;
t1 = clock() - t1; t1 = msclock() - t1;
if ( t1 > 0 ) PrintAndLog("Time in mfkey64: %.0f ticks \n", (float)t1); if ( t1 > 0 ) PrintAndLog("Time in mfkey64: %.1f seconds \n", (float)t1/1000.0);
return 0; return 0;
} }

View file

@ -22,7 +22,6 @@
#include "cmdmain.h" #include "cmdmain.h"
#include "uart.h" #include "uart.h"
#include "ui.h" #include "ui.h"
#include "sleep.h"
#include "cmdparser.h" #include "cmdparser.h"
#include "cmdhw.h" #include "cmdhw.h"
#include "whereami.h" #include "whereami.h"

View file

@ -1,28 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// platform-independant sleep macros
//-----------------------------------------------------------------------------
#ifndef _WIN32
#define _POSIX_C_SOURCE 199309L
#include "sleep.h"
#include <time.h>
#include <stdio.h>
#include <sys/time.h>
#include <errno.h>
void nsleep(uint64_t n) {
struct timespec timeout;
timeout.tv_sec = n/1000000000;
timeout.tv_nsec = n%1000000000;
while (nanosleep(&timeout, &timeout) && errno == EINTR);
}
#endif // _WIN32

View file

@ -1,27 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// platform-independant sleep macros
//-----------------------------------------------------------------------------
#ifndef SLEEP_H__
#define SLEEP_H__
#ifdef _WIN32
# include <windows.h>
# define sleep(n) Sleep(1000 * n)
# define msleep(n) Sleep(n)
#else
# include <inttypes.h>
# include <unistd.h>
void nsleep(uint64_t n);
# define msleep(n) nsleep(1000000 * n)
# define usleep(n) nsleep(1000 * n)
#endif // _WIN32
#endif // SLEEP_H__

View file

@ -8,7 +8,6 @@
// Snooper binary // Snooper binary
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "sleep.h"
#include "ui.h" #include "ui.h"
#include "proxusb.h" #include "proxusb.h"
#include "cmdmain.h" #include "cmdmain.h"

View file

@ -12,7 +12,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <time.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <pthread.h> #include <pthread.h>
@ -34,7 +33,7 @@ void PrintAndLog(char *fmt, ...)
static FILE *logfile = NULL; static FILE *logfile = NULL;
static int logging=1; static int logging=1;
// lock this section to avoid interlacing prints from different threats // lock this section to avoid interlacing prints from different threads
pthread_mutex_lock(&print_lock); pthread_mutex_lock(&print_lock);
if (logging && !logfile) { if (logging && !logfile) {

View file

@ -8,15 +8,26 @@
// utilities // utilities
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <ctype.h> #if !defined(_WIN32)
#define _POSIX_C_SOURCE 199309L // need nanosleep()
#endif
#include "util.h" #include "util.h"
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "data.h"
#define MAX_BIN_BREAK_LENGTH (3072+384+1) #define MAX_BIN_BREAK_LENGTH (3072+384+1)
#ifndef _WIN32 #ifndef _WIN32
#include <termios.h> #include <termios.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
int ukbhit(void) int ukbhit(void)
{ {
int cnt = 0; int cnt = 0;
@ -42,6 +53,7 @@ int ukbhit(void)
} }
#else #else
#include <conio.h> #include <conio.h>
int ukbhit(void) { int ukbhit(void) {
return kbhit(); return kbhit();
@ -591,3 +603,38 @@ void clean_ascii(unsigned char *buf, size_t len) {
buf[i] = '.'; buf[i] = '.';
} }
} }
// Timer functions
#if !defined (_WIN32)
#include <errno.h>
static void nsleep(uint64_t n) {
struct timespec timeout;
timeout.tv_sec = n/1000000000;
timeout.tv_nsec = n%1000000000;
while (nanosleep(&timeout, &timeout) && errno == EINTR);
}
void msleep(uint32_t n) {
nsleep(1000000 * n);
}
#endif // _WIN32
// a milliseconds timer for performance measurement
uint64_t msclock() {
#if defined(_WIN32)
#include <sys/types.h>
struct _timeb t;
if (_ftime_s(&t)) {
return 0;
} else {
return 1000 * t.time + t.millitm;
}
#else
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return (t.tv_sec * 1000 + t.tv_nsec / 1000000);
#endif
}

View file

@ -8,13 +8,11 @@
// utilities // utilities
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <stdio.h> #ifndef UTIL_H__
#include <stdint.h> //included in data.h #define UTIL_H__
#include <stdlib.h>
#include <string.h> #include <stdint.h>
#include <ctype.h> #include <stddef.h>
#include <time.h> //time, gmtime
#include "data.h" //for FILE_PATH_SIZE
#ifndef ROTR #ifndef ROTR
# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n)))) # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
@ -25,54 +23,68 @@
#ifndef MAX #ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b)) # define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif #endif
#define EVEN 0 #define EVEN 0
#define ODD 1 #define ODD 1
int ukbhit(void); extern int ukbhit(void);
void AddLogLine(char *fileName, char *extData, char *c); extern void AddLogLine(char *fileName, char *extData, char *c);
void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len); extern void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len);
void AddLogUint64(char *fileName, char *extData, const uint64_t data); extern void AddLogUint64(char *fileName, char *extData, const uint64_t data);
void AddLogCurrentDT(char *fileName); extern void AddLogCurrentDT(char *fileName);
void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount); extern void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
void print_hex(const uint8_t * data, const size_t len); extern void print_hex(const uint8_t * data, const size_t len);
char * sprint_hex(const uint8_t * data, const size_t len); extern char *sprint_hex(const uint8_t * data, const size_t len);
char * sprint_bin(const uint8_t * data, const size_t len); extern char *sprint_bin(const uint8_t * data, const size_t len);
char * sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks); extern char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
char * sprint_hex_ascii(const uint8_t *data, const size_t len); extern char *sprint_hex_ascii(const uint8_t *data, const size_t len);
char * sprint_ascii(const uint8_t *data, const size_t len); extern char *sprint_ascii(const uint8_t *data, const size_t len);
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest); extern void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
uint64_t bytes_to_num(uint8_t* src, size_t len); extern uint64_t bytes_to_num(uint8_t* src, size_t len);
void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest); extern void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest);
void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest); extern void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest);
char * printBits(size_t const size, void const * const ptr); extern char *printBits(size_t const size, void const * const ptr);
uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize); extern uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);
void SwapEndian64ex(const uint8_t *src, const size_t len, const uint8_t blockSize, uint8_t *dest); extern void SwapEndian64ex(const uint8_t *src, const size_t len, const uint8_t blockSize, uint8_t *dest);
char param_getchar(const char *line, int paramnum); extern char param_getchar(const char *line, int paramnum);
int param_getptr(const char *line, int *bg, int *en, int paramnum); extern int param_getptr(const char *line, int *bg, int *en, int paramnum);
uint8_t param_get8(const char *line, int paramnum); extern uint8_t param_get8(const char *line, int paramnum);
uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base); extern uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base);
uint32_t param_get32ex(const char *line, int paramnum, int deflt, int base); extern uint32_t param_get32ex(const char *line, int paramnum, int deflt, int base);
uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base); extern uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base);
uint8_t param_getdec(const char *line, int paramnum, uint8_t *destination); extern uint8_t param_getdec(const char *line, int paramnum, uint8_t *destination);
uint8_t param_isdec(const char *line, int paramnum); extern uint8_t param_isdec(const char *line, int paramnum);
int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt); extern int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt);
int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt); extern int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt);
int param_getstr(const char *line, int paramnum, char * str); extern int param_getstr(const char *line, int paramnum, char * str);
int hextobinarray( char *target, char *source); extern int hextobinarray( char *target, char *source);
int hextobinstring( char *target, char *source); extern int hextobinstring( char *target, char *source);
int binarraytohex( char *target, char *source, int length); extern int binarraytohex( char *target, char *source, int length);
void binarraytobinstring(char *target, char *source, int length); extern void binarraytobinstring(char *target, char *source, int length);
uint8_t GetParity( uint8_t *string, uint8_t type, int length); extern uint8_t GetParity( uint8_t *string, uint8_t type, int length);
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length); extern void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
void xor(unsigned char *dst, unsigned char *src, size_t len); extern void xor(unsigned char *dst, unsigned char *src, size_t len);
int32_t le24toh(uint8_t data[3]); extern int32_t le24toh(uint8_t data[3]);
uint32_t le32toh (uint8_t *data); extern uint32_t le32toh (uint8_t *data);
void rol(uint8_t *data, const size_t len); extern void rol(uint8_t *data, const size_t len);
void clean_ascii(unsigned char *buf, size_t len); extern void clean_ascii(unsigned char *buf, size_t len);
// timer functions/macros
#ifdef _WIN32
# include <windows.h>
# define sleep(n) Sleep(1000 *(n))
# define msleep(n) Sleep((n))
#else
extern void msleep(uint32_t n); // sleep n milliseconds
#endif // _WIN32
extern uint64_t msclock(); // a milliseconds clock
#endif // UTIL_H__