diff --git a/client/cmddata.c b/client/cmddata.c index 67e711293..c568315c9 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -262,33 +262,37 @@ bool getDemodBuff(uint8_t *buff, size_t *size) { // include // Root mean square -double rms(double *v, size_t n) { +/* +static double rms(double *v, size_t n) { double sum = 0.0; for (size_t i = 0; i < n; i++) sum += v[i] * v[i]; return sqrt(sum / n); } -int cmp_int(const void *a, const void *b) { + +static int cmp_int(const void *a, const void *b) { if (*(const int *)a < * (const int *)b) return -1; else return *(const int *)a > *(const int *)b; } -int cmp_uint8(const void *a, const void *b) { +static int cmp_uint8(const void *a, const void *b) { if (*(const uint8_t *)a < * (const uint8_t *)b) return -1; else return *(const uint8_t *)a > *(const uint8_t *)b; } // Median of a array of values -double median_int(int *src, size_t size) { + +static double median_int(int *src, size_t size) { qsort(src, size, sizeof(int), cmp_int); return 0.5 * (src[size / 2] + src[(size - 1) / 2]); } -double median_uint8(uint8_t *src, size_t size) { +static double median_uint8(uint8_t *src, size_t size) { qsort(src, size, sizeof(uint8_t), cmp_uint8); return 0.5 * (src[size / 2] + src[(size - 1) / 2]); } +*/ // function to compute mean for a series static double compute_mean(const int *data, size_t n) { double mean = 0.0; @@ -358,7 +362,7 @@ void save_restoreDB(uint8_t saveOpt) { } } -int CmdSetDebugMode(const char *Cmd) { +static int CmdSetDebugMode(const char *Cmd) { int demod = 0; sscanf(Cmd, "%i", &demod); g_debugMode = (uint8_t)demod; @@ -550,7 +554,7 @@ int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) { //takes 5 arguments - clock, invert, maxErr, maxLen as integers and amplify as char == 'a' //attempts to demodulate ask while decoding manchester //prints binary found and saves in graphbuffer for further commands -int Cmdaskmandemod(const char *Cmd) { +static int Cmdaskmandemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 45 || cmdp == 'h') return usage_data_rawdemod_am(); @@ -705,7 +709,7 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose) { return 1; } //by marshmellow - see ASKbiphaseDemod -int Cmdaskbiphdemod(const char *Cmd) { +static int Cmdaskbiphdemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 25 || cmdp == 'h') return usage_data_rawdemod_ab(); @@ -713,7 +717,7 @@ int Cmdaskbiphdemod(const char *Cmd) { } //by marshmellow - see ASKDemod -int Cmdaskrawdemod(const char *Cmd) { +static int Cmdaskrawdemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 25 || cmdp == 'h') return usage_data_rawdemod_ar(); @@ -954,7 +958,7 @@ int AskEdgeDetect(const int *in, int *out, int len, int threshold) { //use large jumps in read samples to identify edges of waves and then amplify that wave to max //similar to dirtheshold, threshold commands //takes a threshold length which is the measured length between two samples then determines an edge -int CmdAskEdgeDetect(const char *Cmd) { +static int CmdAskEdgeDetect(const char *Cmd) { int thresLen = 25; int ans = 0; sscanf(Cmd, "%i", &thresLen); @@ -967,7 +971,7 @@ int CmdAskEdgeDetect(const char *Cmd) { /* Print our clock rate */ // uses data from graphbuffer // adjusted to take char parameter for type of modulation to find the clock - by marshmellow. -int CmdDetectClockRate(const char *Cmd) { +static int CmdDetectClockRate(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 6 || strlen(Cmd) == 0 || cmdp == 'h') return usage_data_detectclock(); @@ -994,7 +998,7 @@ int CmdDetectClockRate(const char *Cmd) { return clock1; } -char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) { +static char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) { static char fType[8]; memset(fType, 0x00, 8); char *fskType = fType; @@ -1088,7 +1092,7 @@ int FSKrawDemod(const char *Cmd, bool verbose) { //fsk raw demod and print binary //takes 4 arguments - Clock, invert, fchigh, fclow //defaults: clock = 50, invert=1, fchigh=10, fclow=8 (RF/10 RF/8 (fsk2a)) -int CmdFSKrawdemod(const char *Cmd) { +static int CmdFSKrawdemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 20 || cmdp == 'h') return usage_data_rawdemod_fs(); @@ -1258,7 +1262,7 @@ int NRZrawDemod(const char *Cmd, bool verbose) { return 1; } -int CmdNRZrawDemod(const char *Cmd) { +static int CmdNRZrawDemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_nr(); @@ -1287,7 +1291,7 @@ int CmdPSK1rawDemod(const char *Cmd) { // by marshmellow // takes same args as cmdpsk1rawdemod -int CmdPSK2rawDemod(const char *Cmd) { +static int CmdPSK2rawDemod(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_p2(); @@ -1304,7 +1308,7 @@ int CmdPSK2rawDemod(const char *Cmd) { } // by marshmellow - combines all raw demod functions into one menu command -int CmdRawDemod(const char *Cmd) { +static int CmdRawDemod(const char *Cmd) { int ans = 0; if (strlen(Cmd) > 35 || strlen(Cmd) < 2) @@ -1359,13 +1363,13 @@ int CmdGrid(const char *Cmd) { return 0; } -int CmdSetGraphMarkers(const char *Cmd) { +static int CmdSetGraphMarkers(const char *Cmd) { sscanf(Cmd, "%i %i", &CursorCPos, &CursorDPos); RepaintGraphWindow(); return 0; } -int CmdHexsamples(const char *Cmd) { +static int CmdHexsamples(const char *Cmd) { int i, j, requested = 0, offset = 0; char string_buf[25]; char *string_ptr = string_buf; @@ -1503,7 +1507,7 @@ int getSamples(int n, bool silent) { return 0; } -int CmdSamples(const char *Cmd) { +static int CmdSamples(const char *Cmd) { int n = strtol(Cmd, NULL, 0); return getSamples(n, false); } @@ -1609,7 +1613,7 @@ int CmdTuneSamples(const char *Cmd) { return 0; } -int CmdLoad(const char *Cmd) { +static int CmdLoad(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0x00}; int len = 0; @@ -1665,7 +1669,7 @@ int CmdLtrim(const char *Cmd) { } // trim graph from the beginning -int CmdRtrim(const char *Cmd) { +static int CmdRtrim(const char *Cmd) { int ds = atoi(Cmd); @@ -1678,7 +1682,7 @@ int CmdRtrim(const char *Cmd) { } // trim graph (middle) piece -int CmdMtrim(const char *Cmd) { +static int CmdMtrim(const char *Cmd) { int start = 0, stop = 0; sscanf(Cmd, "%i %i", &start, &stop); @@ -1727,7 +1731,7 @@ int CmdPlot(const char *Cmd) { return 0; } -int CmdSave(const char *Cmd) { +static int CmdSave(const char *Cmd) { int len = 0; char filename[FILE_PATH_SIZE] = {0x00}; @@ -1752,7 +1756,7 @@ int CmdSave(const char *Cmd) { return 0; } -int CmdScale(const char *Cmd) { +static int CmdScale(const char *Cmd) { CursorScaleFactor = atoi(Cmd); if (CursorScaleFactor == 0) { PrintAndLogEx(FAILED, "bad, can't have zero scale"); @@ -1791,7 +1795,7 @@ int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t return 0; } -int CmdDirectionalThreshold(const char *Cmd) { +static int CmdDirectionalThreshold(const char *Cmd) { int8_t up = param_get8(Cmd, 0); int8_t down = param_get8(Cmd, 1); @@ -1809,7 +1813,7 @@ int CmdDirectionalThreshold(const char *Cmd) { return 0; } -int CmdZerocrossings(const char *Cmd) { +static int CmdZerocrossings(const char *Cmd) { (void)Cmd; // Cmd is not used so far // Zero-crossings aren't meaningful unless the signal is zero-mean. CmdHpf(""); @@ -1846,7 +1850,7 @@ int CmdZerocrossings(const char *Cmd) { * @param Cmd * @return */ -int Cmdbin2hex(const char *Cmd) { +static int Cmdbin2hex(const char *Cmd) { int bg = 0, en = 0; if (param_getptr(Cmd, &bg, &en, 0)) return usage_data_bin2hex(); @@ -1876,7 +1880,7 @@ int Cmdbin2hex(const char *Cmd) { return 0; } -int Cmdhex2bin(const char *Cmd) { +static int Cmdhex2bin(const char *Cmd) { int bg = 0, en = 0; if (param_getptr(Cmd, &bg, &en, 0)) return usage_data_hex2bin(); @@ -1918,7 +1922,7 @@ static const int HighTone[] = { 1, 1, 1, 1, -1, -1, -1, -1, -1, // note one extra -1 to padd due to 50/8 remainder }; */ -void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighToneFC) { +static void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighToneFC) { int i, j = 0; int Left_Modifier = ((clk % LowToneFC) % 2) + ((clk % LowToneFC) / 2); int Right_Modifier = (clk % LowToneFC) / 2; @@ -1981,7 +1985,7 @@ void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighTo //old CmdFSKdemod adapted by marshmellow //converts FSK to clear NRZ style wave. (or demodulates) -int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) { +static int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) { uint8_t ans = 0; if (clk == 0 || LowToneFC == 0 || HighToneFC == 0) { int firstClockEdge = 0; @@ -2042,7 +2046,7 @@ int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) { return 0; } -int CmdFSKToNRZ(const char *Cmd) { +static int CmdFSKToNRZ(const char *Cmd) { // take clk, fc_low, fc_high // blank = auto; bool errors = false; @@ -2082,7 +2086,7 @@ int CmdFSKToNRZ(const char *Cmd) { return ans; } -int CmdDataIIR(const char *Cmd) { +static int CmdDataIIR(const char *Cmd) { uint8_t k = param_get8(Cmd, 0); //iceIIR_Butterworth(GraphBuffer, GraphTraceLen); iceSimple_Filter(GraphBuffer, GraphTraceLen, k); @@ -2136,14 +2140,15 @@ static command_t CommandTable[] = { {NULL, NULL, 0, NULL} }; +static int CmdHelp(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + CmdsHelp(CommandTable); + return 0; +} + int CmdData(const char *Cmd) { clearCommandBuffer(); CmdsParse(CommandTable, Cmd); return 0; } -int CmdHelp(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - CmdsHelp(CommandTable); - return 0; -} diff --git a/client/cmddata.h b/client/cmddata.h index 94b537d65..702775598 100644 --- a/client/cmddata.h +++ b/client/cmddata.h @@ -32,18 +32,12 @@ #include "loclass/cipherutils.h" // for decimating samples in getsamples #include "cmdlfem4x.h" // askem410xdecode -command_t *CmdDataCommands(void); - int CmdData(const char *Cmd); -void printDemodBuff(void); -void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx); -bool getDemodBuff(uint8_t *buff, size_t *size); -void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other to restore -int CmdPrintDemodBuff(const char *Cmd); +// Still quite work to do here to provide proper functions for internal usage... +/* int Cmdaskrawdemod(const char *Cmd); int Cmdaskmandemod(const char *Cmd); -int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose); int CmdAskEdgeDetect(const char *Cmd); int CmdAutoCorr(const char *Cmd); int CmdBiphaseDecodeRaw(const char *Cmd); @@ -52,41 +46,48 @@ int CmdBuffClear(const char *Cmd); int CmdDec(const char *Cmd); int CmdDetectClockRate(const char *Cmd); int CmdFSKrawdemod(const char *Cmd); -int CmdPSK1rawDemod(const char *Cmd); int CmdPSK2rawDemod(const char *Cmd); -int CmdGrid(const char *Cmd); -int CmdGetBitStream(const char *Cmd); int CmdHexsamples(const char *Cmd); int CmdHide(const char *Cmd); -int CmdHpf(const char *Cmd); int CmdLoad(const char *Cmd); -int CmdLtrim(const char *Cmd); int CmdRtrim(const char *Cmd); int Cmdmandecoderaw(const char *Cmd); -int CmdNorm(const char *Cmd); int CmdNRZrawDemod(const char *Cmd); -int CmdPlot(const char *Cmd); int CmdPrintDemodBuff(const char *Cmd); int CmdRawDemod(const char *Cmd); int CmdSamples(const char *Cmd); -int CmdTuneSamples(const char *Cmd); int CmdSave(const char *Cmd); int CmdScale(const char *Cmd); int CmdDirectionalThreshold(const char *Cmd); int CmdZerocrossings(const char *Cmd); -int ASKbiphaseDemod(const char *Cmd, bool verbose); -int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType); -int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck); -int FSKrawDemod(const char *Cmd, bool verbose); -int PSKDemod(const char *Cmd, bool verbose); -int NRZrawDemod(const char *Cmd, bool verbose); +int CmdDataIIR(const char *Cmd); +*/ +int CmdPrintDemodBuff(const char *Cmd); // used by cmd lf keri, lf nexwatch +int CmdPSK1rawDemod(const char *Cmd); // used by cmd lf +int CmdGetBitStream(const char *Cmd); // used by cmd lf +int CmdGrid(const char *Cmd); // used by cmd lf cotag +int CmdHpf(const char *Cmd); // used by cmd lf data (!) +int CmdLtrim(const char *Cmd); // used by cmd lf em4x, lf t55xx +int CmdNorm(const char *Cmd); // used by cmd lf data (!) +int CmdPlot(const char *Cmd); // used by cmd lf cotag +int CmdTuneSamples(const char *Cmd); // used by cmd lf hw +int ASKbiphaseDemod(const char *Cmd, bool verbose); // used by cmd lf em4x, lf fdx, lf guard, lf jablotron, lf nedap, lf t55xx +int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType); // used by cmd lf em4x, lf t55xx, lf viking +int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck); // used by cmd lf, lf em4x, lf noralsy, le presco, lf securekey, lf t55xx, lf visa2k +int FSKrawDemod(const char *Cmd, bool verbose); // used by cmd lf, lf em4x, lf t55xx +int PSKDemod(const char *Cmd, bool verbose); // used by cmd lf em4x, lf indala, lf keri, lf nexwatch, lf t55xx +int NRZrawDemod(const char *Cmd, bool verbose); // used by cmd lf pac, lf t55xx + + +void printDemodBuff(void); +void setDemodBuff(uint8_t *buff, size_t size, size_t start_idx); +bool getDemodBuff(uint8_t *buff, size_t *size); +void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other to restore +int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose); int getSamples(int n, bool silent); void setClockGrid(int clk, int offset); int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down); int AskEdgeDetect(const int *in, int *out, int len, int threshold); - -int CmdDataIIR(const char *Cmd); - int demodIdteck(void); #define MAX_DEMOD_BUF_LEN (1024*128) diff --git a/client/comms.c b/client/comms.c index cf8aac7f0..afa79c38c 100644 --- a/client/comms.c +++ b/client/comms.c @@ -218,7 +218,7 @@ bool hookUpPM3() { } */ -void +static void #ifdef __has_attribute #if __has_attribute(force_align_arg_pointer) __attribute__((force_align_arg_pointer)) diff --git a/client/crypto/libpcrypto.c b/client/crypto/libpcrypto.c index f1f6e782d..775080c42 100644 --- a/client/crypto/libpcrypto.c +++ b/client/crypto/libpcrypto.c @@ -121,7 +121,7 @@ int sha512hash(uint8_t *input, int length, uint8_t *hash) { return 0; } -int ecdsa_init_str(mbedtls_ecdsa_context *ctx, const char *key_d, const char *key_x, const char *key_y) { +static int ecdsa_init_str(mbedtls_ecdsa_context *ctx, const char *key_d, const char *key_x, const char *key_y) { if (!ctx) return 1; @@ -147,7 +147,7 @@ int ecdsa_init_str(mbedtls_ecdsa_context *ctx, const char *key_d, const char *ke return 0; } -int ecdsa_init(mbedtls_ecdsa_context *ctx, uint8_t *key_d, uint8_t *key_xy) { +static int ecdsa_init(mbedtls_ecdsa_context *ctx, uint8_t *key_d, uint8_t *key_xy) { if (!ctx) return 1; @@ -279,7 +279,7 @@ exit: return res; } -int ecdsa_signature_create_test(const char *key_d, const char *key_x, const char *key_y, const char *random, uint8_t *input, int length, uint8_t *signature, size_t *signaturelen) { +static int ecdsa_signature_create_test(const char *key_d, const char *key_x, const char *key_y, const char *random, uint8_t *input, int length, uint8_t *signature, size_t *signaturelen) { int res; *signaturelen = 0; @@ -299,7 +299,7 @@ int ecdsa_signature_create_test(const char *key_d, const char *key_x, const char return res; } -int ecdsa_signature_verify_keystr(const char *key_x, const char *key_y, uint8_t *input, int length, uint8_t *signature, size_t signaturelen) { +static int ecdsa_signature_verify_keystr(const char *key_x, const char *key_y, uint8_t *input, int length, uint8_t *signature, size_t signaturelen) { int res; uint8_t shahash[32] = {0}; res = sha256hash(input, length, shahash); diff --git a/client/emv/apduinfo.c b/client/emv/apduinfo.c index c497eb4f8..27e48156c 100644 --- a/client/emv/apduinfo.c +++ b/client/emv/apduinfo.c @@ -259,7 +259,7 @@ const APDUCode APDUCodeTable[] = { }; const size_t APDUCodeTableLen = sizeof(APDUCodeTable) / sizeof(APDUCode); -int CodeCmp(const char *code1, const char *code2) { +static int CodeCmp(const char *code1, const char *code2) { int xsymb = 0; int cmp = 0; for (int i = 0; i < 4; i++) { diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index d8c7b6c54..df2a1a22e 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -20,7 +20,7 @@ static int CmdHelp(const char *Cmd); #define TLV_ADD(tag, value)( tlvdb_change_or_add_node(tlvRoot, tag, sizeof(value) - 1, (const unsigned char *)value) ) -void ParamLoadDefaults(struct tlvdb *tlvRoot) { +static void ParamLoadDefaults(struct tlvdb *tlvRoot) { //9F02:(Amount, authorized (Numeric)) len:6 TLV_ADD(0x9F02, "\x00\x00\x00\x00\x01\x00"); //9F1A:(Terminal Country Code) len:2 @@ -43,7 +43,7 @@ void ParamLoadDefaults(struct tlvdb *tlvRoot) { TLV_ADD(0x95, "\x00\x00\x00\x00\x00"); } -void PrintChannel(EMVCommandChannel channel) { +static void PrintChannel(EMVCommandChannel channel) { switch (channel) { case ECC_CONTACTLESS: PrintAndLogEx(INFO, "Channel: CONTACTLESS"); @@ -642,7 +642,7 @@ static int CmdEMVInternalAuthenticate(const char *Cmd) { #define dreturn(n) {free(pdol_data_tlv); tlvdb_free(tlvSelect); tlvdb_free(tlvRoot); DropFieldEx( channel ); return n;} -void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum TransactionType TrType, bool GenACGPO) { +static void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum TransactionType TrType, bool GenACGPO) { ParamLoadDefaults(tlvRoot); @@ -675,7 +675,7 @@ void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum T } } -void ProcessGPOResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV) { +static void ProcessGPOResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV) { if (buf[0] == 0x80) { if (decodeTLV) { PrintAndLog("GPO response format1:"); @@ -705,7 +705,7 @@ void ProcessGPOResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, } } -void ProcessACResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV) { +static void ProcessACResponseFormat1(struct tlvdb *tlvRoot, uint8_t *buf, size_t len, bool decodeTLV) { if (buf[0] == 0x80) { if (decodeTLV) { PrintAndLog("GPO response format1:"); diff --git a/client/emv/emv_roca.c b/client/emv/emv_roca.c index df43db4ee..a189fdd70 100644 --- a/client/emv/emv_roca.c +++ b/client/emv/emv_roca.c @@ -29,7 +29,7 @@ static uint8_t g_primes[ROCA_PRINTS_LENGTH] = { mbedtls_mpi g_prints[ROCA_PRINTS_LENGTH]; -void rocacheck_init(void) { +static void rocacheck_init(void) { for (int i = 0; i < ROCA_PRINTS_LENGTH; i++) mbedtls_mpi_init(&g_prints[i]); @@ -53,12 +53,12 @@ void rocacheck_init(void) { mbedtls_mpi_read_string(&g_prints[16], 10, "126304807362733370595828809000324029340048915994"); } -void rocacheck_cleanup(void) { +static void rocacheck_cleanup(void) { for (int i = 0; i < ROCA_PRINTS_LENGTH; i++) mbedtls_mpi_free(&g_prints[i]); } -int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b) { +static int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b) { for (int i = 0; i < mbedtls_mpi_bitlen(a); i++) { @@ -69,7 +69,7 @@ int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b) { } -mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X) { +static mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X) { if (X->n == 1 && X->s > 0) { return X->p[0]; @@ -78,7 +78,8 @@ mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X) { return 0; } -void print_mpi(const char *msg, int radix, const mbedtls_mpi *X) { +/* +static void print_mpi(const char *msg, int radix, const mbedtls_mpi *X) { char Xchar[400] = {0}; size_t len = 0; @@ -86,7 +87,7 @@ void print_mpi(const char *msg, int radix, const mbedtls_mpi *X) { mbedtls_mpi_write_string(X, radix, Xchar, sizeof(Xchar), &len); printf("%s[%zu] %s\n", msg, len, Xchar); } - +*/ bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) { mbedtls_mpi t_modulus; diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index 7e0174baa..70cfec82a 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -263,7 +263,7 @@ struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2) { return tlvdb_fixed(0x02, dCVVlen, dCVV); } -int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool IncludeLe, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { +static int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool IncludeLe, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { uint8_t data[APDU_RES_LEN] = {0}; *ResultLen = 0; @@ -366,7 +366,7 @@ int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO return res; } -int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { +static int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { int retrycnt = 0; int res = 0; do { @@ -393,7 +393,7 @@ int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool Leave return res; } -int EMVCheckAID(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlvdbelm, struct tlvdb *tlv) { +static int EMVCheckAID(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlvdbelm, struct tlvdb *tlv) { uint8_t data[APDU_RES_LEN] = {0}; size_t datalen = 0; int res = 0; diff --git a/client/emv/emvjson.c b/client/emv/emvjson.c index dadff33fc..59de9d37e 100644 --- a/client/emv/emvjson.c +++ b/client/emv/emvjson.c @@ -239,7 +239,7 @@ int JsonSaveTLVTree(json_t *root, json_t *elm, const char *path, struct tlvdb *t return 0; } -bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t *buffer, size_t maxbufferlen, size_t *bufferlen) { +static bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t *buffer, size_t maxbufferlen, size_t *bufferlen) { int buflen = 0; switch (param_gethex_to_eol(hexvalue, 0, buffer, maxbufferlen, &buflen)) { diff --git a/client/emv/test/crypto_test.c b/client/emv/test/crypto_test.c index 21e924858..4220515df 100644 --- a/client/emv/test/crypto_test.c +++ b/client/emv/test/crypto_test.c @@ -24,6 +24,7 @@ #include #include #include +#include "crypto_test.h" static int test_genkey(unsigned int keylength, unsigned char *msg, size_t msg_len, bool verbose) { int ret = 1; diff --git a/client/emv/test/sda_test.c b/client/emv/test/sda_test.c index 1f43d30b2..86f201e58 100644 --- a/client/emv/test/sda_test.c +++ b/client/emv/test/sda_test.c @@ -26,6 +26,7 @@ #include #include #include +#include "sda_test.h" struct emv_pk vsdc_01 = { .rid = { 0xa0, 0x00, 0x00, 0x00, 0x03, }, diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index 78055cc9e..1864ac7c3 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -184,7 +184,7 @@ static CborError dumprecursive(uint8_t cmdCode, bool isResponse, CborValue *it, return CborNoError; } -int TinyCborInit(uint8_t *data, size_t length, CborValue *cb) { +static int TinyCborInit(uint8_t *data, size_t length, CborValue *cb) { CborParser parser; CborError err = cbor_parser_init(data, length, 0, &parser, cb); if (err) @@ -216,7 +216,7 @@ int TinyCborPrintFIDOPackage(uint8_t cmdCode, bool isResponse, uint8_t *data, si return 0; } -int JsonObjElmCount(json_t *elm) { +static int JsonObjElmCount(json_t *elm) { int res = 0; const char *key; json_t *value; diff --git a/client/fido/cose.c b/client/fido/cose.c index 134c29772..3201d6615 100644 --- a/client/fido/cose.c +++ b/client/fido/cose.c @@ -38,7 +38,7 @@ COSEValueNameDesc_t COSEKeyTypeValueDesc[] = { {4, "Symmetric", "Symmetric Key"}, }; -COSEValueNameDesc_t *GetCOSEktyElm(int id) { +static COSEValueNameDesc_t *GetCOSEktyElm(int id) { for (int i = 0; i < ARRAYLEN(COSEKeyTypeValueDesc); i++) if (COSEKeyTypeValueDesc[i].Value == id) return &COSEKeyTypeValueDesc[i]; diff --git a/client/fido/fidocore.c b/client/fido/fidocore.c index 915617244..a688d9a9a 100644 --- a/client/fido/fidocore.c +++ b/client/fido/fidocore.c @@ -355,7 +355,7 @@ bool CheckrpIdHash(json_t *json, uint8_t *hash) { } // check ANSI X9.62 format ECDSA signature (on P-256) -int FIDO2CheckSignature(json_t *root, uint8_t *publickey, uint8_t *sign, size_t signLen, uint8_t *authData, size_t authDataLen, bool verbose) { +static int FIDO2CheckSignature(json_t *root, uint8_t *publickey, uint8_t *sign, size_t signLen, uint8_t *authData, size_t authDataLen, bool verbose) { int res; uint8_t rval[300] = {0}; uint8_t sval[300] = {0}; diff --git a/client/loclass/cipher.c b/client/loclass/cipher.c index 2fe178829..331e0b44e 100644 --- a/client/loclass/cipher.c +++ b/client/loclass/cipher.c @@ -67,7 +67,7 @@ typedef struct { * is defined as * T (x 0 x 1 . . . . . . x 15 ) = x 0 ⊕ x 1 ⊕ x 5 ⊕ x 7 ⊕ x 10 ⊕ x 11 ⊕ x 14 ⊕ x 15 . **/ -bool T(State state) { +static bool T(State state) { bool x0 = state.t & 0x8000; bool x1 = state.t & 0x4000; bool x5 = state.t & 0x0400; @@ -82,7 +82,7 @@ bool T(State state) { * Similarly, the feedback function for the bottom register B : F 8/2 → F 2 is defined as * B(x 0 x 1 . . . x 7 ) = x 1 ⊕ x 2 ⊕ x 3 ⊕ x 7 . **/ -bool B(State state) { +static bool B(State state) { bool x1 = state.b & 0x40; bool x2 = state.b & 0x20; bool x3 = state.b & 0x10; @@ -98,7 +98,7 @@ bool B(State state) { * z 1 = (r 0 ∨ r 2 ) ⊕ (r 5 ∨ r 7 ) ⊕ r 1 ⊕ r 6 ⊕ x ⊕ y * z 2 = (r 3 ∧ r 5 ) ⊕ (r 4 ∧ r 6 ) ⊕ r 7 ⊕ x **/ -uint8_t _select(bool x, bool y, uint8_t r) { +static uint8_t _select(bool x, bool y, uint8_t r) { bool r0 = r >> 7 & 0x1; bool r1 = r >> 6 & 0x1; bool r2 = r >> 5 & 0x1; @@ -134,7 +134,7 @@ uint8_t _select(bool x, bool y, uint8_t r) { * @param s - state * @param k - array containing 8 bytes **/ -State successor(uint8_t *k, State s, bool y) { +static State successor(uint8_t *k, State s, bool y) { bool r0 = s.r >> 7 & 0x1; bool r4 = s.r >> 3 & 0x1; bool r7 = s.r & 0x1; @@ -160,7 +160,7 @@ State successor(uint8_t *k, State s, bool y) { * to multiple bit input x ∈ F n 2 which we define as * @param k - array containing 8 bytes **/ -State suc(uint8_t *k, State s, BitstreamIn *bitstream) { +static State suc(uint8_t *k, State s, BitstreamIn *bitstream) { if (bitsLeft(bitstream) == 0) { return s; } @@ -176,7 +176,7 @@ State suc(uint8_t *k, State s, BitstreamIn *bitstream) { * output(k, s, x 0 . . . x n ) = output(s) · output(k, s ′ , x 1 . . . x n ) * where s ′ = suc(k, s, x 0 ). **/ -void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) { +static void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) { if (bitsLeft(in) == 0) { return; } @@ -192,7 +192,7 @@ void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) { * key k ∈ (F 82 ) 8 and outputs the initial cipher state s =< l, r, t, b > **/ -State init(uint8_t *k) { +static State init(uint8_t *k) { State s = { ((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l ((k[0] ^ 0x4c) + 0x21) & 0xFF,// r @@ -201,7 +201,8 @@ State init(uint8_t *k) { }; return s; } -void MAC(uint8_t *k, BitstreamIn input, BitstreamOut out) { + +static void MAC(uint8_t *k, BitstreamIn input, BitstreamOut out) { uint8_t zeroes_32[] = {0, 0, 0, 0}; BitstreamIn input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0}; State initState = suc(k, init(k), &input); diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index bb457e371..c829574e9 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -104,10 +104,11 @@ int bitsLeft(BitstreamIn *stream) { * @param stream * @return Number of bits stored in stream */ -int numBits(BitstreamOut *stream) { +/* +static int numBits(BitstreamOut *stream) { return stream->numbits; } - +*/ void x_num_to_bytes(uint64_t n, size_t len, uint8_t *dest) { while (len--) { dest[len] = (uint8_t) n; @@ -187,7 +188,7 @@ void printarr_human_readable(const char *title, uint8_t *arr, int len) { //----------------------------- #ifndef ON_DEVICE -int testBitStream() { +static int testBitStream() { uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF}; uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0}; BitstreamIn in = { input, sizeof(input) * 8, 0}; @@ -212,7 +213,7 @@ int testBitStream() { return 0; } -int testReversedBitstream() { +static int testReversedBitstream() { uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF}; uint8_t reverse [] = {0, 0, 0, 0, 0, 0, 0, 0}; uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 5a280e7c1..7df30c696 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -162,7 +162,7 @@ Definition 14. Define the rotate key function rk : (F 82 ) 8 × N → (F 82 ) 8 rk(x [0] . . . x [7] , 0) = x [0] . . . x [7] rk(x [0] . . . x [7] , n + 1) = rk(rl(x [0] ) . . . rl(x [7] ), n) **/ -void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) { +static void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) { memcpy(outp_key, key, 8); uint8_t j; while (n-- > 0) { @@ -175,14 +175,14 @@ void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) { static mbedtls_des_context ctx_enc; static mbedtls_des_context ctx_dec; -void desdecrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) { +static void desdecrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) { uint8_t key_std_format[8] = {0}; permutekey_rev(iclass_key, key_std_format); mbedtls_des_setkey_dec(&ctx_dec, key_std_format); mbedtls_des_crypt_ecb(&ctx_dec, input, output); } -void desencrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) { +static void desencrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) { uint8_t key_std_format[8] = {0}; permutekey_rev(iclass_key, key_std_format); mbedtls_des_setkey_enc(&ctx_enc, key_std_format); @@ -266,7 +266,8 @@ void hash2(uint8_t *key64, uint8_t *outp_keytable) { * @param i the number to read. Should be less than 127, or something is wrong... * @return */ -int _readFromDump(uint8_t dump[], dumpdata *item, uint8_t i) { +/* +static int _readFromDump(uint8_t dump[], dumpdata *item, uint8_t i) { size_t itemsize = sizeof(dumpdata); memcpy(item, dump + i * itemsize, itemsize); @@ -277,7 +278,7 @@ int _readFromDump(uint8_t dump[], dumpdata *item, uint8_t i) { } return 0; } - +*/ //static uint32_t startvalue = 0; /** * @brief Performs brute force attack against a dump-data item, containing csn, cc_nr and mac. @@ -580,7 +581,7 @@ int bruteforceFileNoKeys(const char *filename) { // ---------------------------------------------------------------------------- // TEST CODE BELOW // ---------------------------------------------------------------------------- -int _testBruteforce() { +static int _testBruteforce() { int errors = 0; if (true) { // First test @@ -617,7 +618,7 @@ int _testBruteforce() { return errors; } -int _test_iclass_key_permutation() { +static int _test_iclass_key_permutation() { uint8_t testcase[8] = {0x6c, 0x8d, 0x44, 0xf9, 0x2a, 0x2d, 0x01, 0xbf}; uint8_t testcase_output[8] = {0}; uint8_t testcase_output_correct[8] = {0x8a, 0x0d, 0xb9, 0x88, 0xbb, 0xa7, 0x90, 0xea}; @@ -643,7 +644,7 @@ int _test_iclass_key_permutation() { return 0; } -int _testHash1() { +static int _testHash1() { uint8_t expected[8] = {0x7E, 0x72, 0x2F, 0x40, 0x2D, 0x02, 0x51, 0x42}; uint8_t csn[8] = {0x01, 0x02, 0x03, 0x04, 0xF7, 0xFF, 0x12, 0xE0}; uint8_t k[8] = {0}; diff --git a/client/loclass/hash1_brute.c b/client/loclass/hash1_brute.c index 6007e1b9f..fb08da756 100644 --- a/client/loclass/hash1_brute.c +++ b/client/loclass/hash1_brute.c @@ -7,7 +7,8 @@ #include #include "elite_crack.h" -void calc_score(uint8_t *csn, uint8_t *k) { +/* +static void calc_score(uint8_t *csn, uint8_t *k) { uint8_t score = 0 ; uint8_t i; uint8_t goodvals[16] = {0}; @@ -53,7 +54,7 @@ void calc_score(uint8_t *csn, uint8_t *k) { } } -void brute_hash1(void) { +static void brute_hash1(void) { uint16_t a, b, c, d; uint8_t csn[8] = {0, 0, 0, 0, 0xf7, 0xff, 0x12, 0xe0}; uint8_t k[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -81,4 +82,4 @@ void brute_hash1(void) { } } } - +*/ diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index 43959b421..e3128e47b 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -85,7 +85,7 @@ static int debug_print = 0; * @param n bitnumber * @return */ -uint8_t getSixBitByte(uint64_t c, int n) { +static uint8_t getSixBitByte(uint64_t c, int n) { return (c >> (42 - 6 * n)) & 0x3F; } @@ -95,7 +95,7 @@ uint8_t getSixBitByte(uint64_t c, int n) { * @param z the value to place there * @param n bitnumber. */ -void pushbackSixBitByte(uint64_t *c, uint8_t z, int n) { +static void pushbackSixBitByte(uint64_t *c, uint8_t z, int n) { //0x XXXX YYYY ZZZZ ZZZZ ZZZZ // ^z0 ^z7 //z0: 1111 1100 0000 0000 @@ -120,7 +120,7 @@ void pushbackSixBitByte(uint64_t *c, uint8_t z, int n) { * @param c * @return */ -uint64_t swapZvalues(uint64_t c) { +static uint64_t swapZvalues(uint64_t c) { uint64_t newz = 0; pushbackSixBitByte(&newz, getSixBitByte(c, 0), 7); pushbackSixBitByte(&newz, getSixBitByte(c, 1), 6); @@ -137,7 +137,7 @@ uint64_t swapZvalues(uint64_t c) { /** * @return 4 six-bit bytes chunked into a uint64_t,as 00..00a0a1a2a3 */ -uint64_t ck(int i, int j, uint64_t z) { +static uint64_t ck(int i, int j, uint64_t z) { if (i == 1 && j == -1) { // ck(1, −1, z [0] . . . z [3] ) = z [0] . . . z [3] return z; @@ -179,7 +179,7 @@ uint64_t ck(int i, int j, uint64_t z) { otherwise. **/ -uint64_t check(uint64_t z) { +static uint64_t check(uint64_t z) { //These 64 bits are divided as c = x, y, z [0] , . . . , z [7] // ck(3, 2, z [0] . . . z [3] ) @@ -197,7 +197,7 @@ uint64_t check(uint64_t z) { } -void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) { +static void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) { if (bitsLeft(p_in) == 0) return; @@ -214,14 +214,14 @@ void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) { permute(p_in, z, l, r + 1, out); } } -void printbegin() { +static void printbegin() { if (debug_print < 2) return; PrintAndLogDevice(NORMAL, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); } -void printState(const char *desc, uint64_t c) { +static void printState(const char *desc, uint64_t c) { if (debug_print < 2) return; @@ -366,8 +366,8 @@ void diversifyKey(uint8_t csn[8], uint8_t key[8], uint8_t div_key[8]) { hash0(crypt_csn, div_key); } - -void testPermute() { +/* +static void testPermute() { uint64_t x = 0; pushbackSixBitByte(&x, 0x00, 0); pushbackSixBitByte(&x, 0x01, 1); @@ -411,7 +411,7 @@ void testPermute() { }; printarr("permuted", res, 8); } - +*/ // These testcases are // { UID , TEMP_KEY, DIV_KEY} using the specific key typedef struct { @@ -420,7 +420,7 @@ typedef struct { uint8_t div_key[8]; } Testcase; -int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context ctx_dec) { +static int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context ctx_dec) { uint8_t des_encrypted_csn[8] = {0}; uint8_t decrypted[8] = {0}; uint8_t div_key[8] = {0}; @@ -456,7 +456,7 @@ int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context } return retval; } -bool des_getParityBitFromKey(uint8_t key) { +static bool des_getParityBitFromKey(uint8_t key) { // The top 7 bits is used bool parity = ((key & 0x80) >> 7) ^ ((key & 0x40) >> 6) ^ ((key & 0x20) >> 5) @@ -465,7 +465,7 @@ bool des_getParityBitFromKey(uint8_t key) { return !parity; } -void des_checkParity(uint8_t *key) { +static void des_checkParity(uint8_t *key) { int i; int fails = 0; for (i = 0; i < 8; i++) { @@ -553,7 +553,7 @@ Testcase testcases[] = { {{0}, {0}, {0}} }; -int testKeyDiversificationWithMasterkeyTestcases() { +static int testKeyDiversificationWithMasterkeyTestcases() { int i, error = 0; uint8_t empty[8] = {0}; @@ -569,11 +569,11 @@ int testKeyDiversificationWithMasterkeyTestcases() { return error; } -void print64bits(const char *name, uint64_t val) { +static void print64bits(const char *name, uint64_t val) { printf("%s%08x%08x\n", name, (uint32_t)(val >> 32), (uint32_t)(val & 0xFFFFFFFF)); } -uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected) { +static uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected) { int retval = 0; uint8_t result[8] = {0}; if (debug_print) PrintAndLogDevice(DEBUG, "debug_print %d", debug_print); @@ -626,7 +626,7 @@ int testDES2(uint64_t csn, uint64_t expected) { * @brief doTestsWithKnownInputs * @return */ -int doTestsWithKnownInputs() { +static int doTestsWithKnownInputs() { // KSel from http://www.proxmark.org/forum/viewtopic.php?pid=10977#p10977 int errors = 0; PrintAndLogDevice(SUCCESS, "Testing DES encryption"); diff --git a/client/mifare/mad.c b/client/mifare/mad.c index 4c3d21022..47b7cb70a 100644 --- a/client/mifare/mad.c +++ b/client/mifare/mad.c @@ -107,7 +107,7 @@ static const char *GetAIDDescription(uint16_t AID) { return unknownAID; } -int madCRCCheck(uint8_t *sector, bool verbose, int MADver) { +static int madCRCCheck(uint8_t *sector, bool verbose, int MADver) { if (MADver == 1) { uint8_t crc = CRC8Mad(§or[16 + 1], 15 + 16); if (crc != sector[16]) { @@ -125,7 +125,7 @@ int madCRCCheck(uint8_t *sector, bool verbose, int MADver) { return 0; } -uint16_t madGetAID(uint8_t *sector, int MADver, int sectorNo) { +static uint16_t madGetAID(uint8_t *sector, int MADver, int sectorNo) { if (MADver == 1) return (sector[16 + 2 + (sectorNo - 1) * 2] << 8) + (sector[16 + 2 + (sectorNo - 1) * 2 + 1]); else diff --git a/client/mifare/mifare4.c b/client/mifare/mifare4.c index 757865564..b172e5131 100644 --- a/client/mifare/mifare4.c +++ b/client/mifare/mifare4.c @@ -95,8 +95,8 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data) { return StaticNone; }; - -int CalculateEncIVCommand(mf4Session *session, uint8_t *iv, bool verbose) { +/* +static int CalculateEncIVCommand(mf4Session *session, uint8_t *iv, bool verbose) { memcpy(&iv[0], session->TI, 4); memcpy(&iv[4], &session->R_Ctr, 2); memcpy(&iv[6], &session->W_Ctr, 2); @@ -108,7 +108,7 @@ int CalculateEncIVCommand(mf4Session *session, uint8_t *iv, bool verbose) { return 0; } -int CalculateEncIVResponse(mf4Session *session, uint8_t *iv, bool verbose) { +static int CalculateEncIVResponse(mf4Session *session, uint8_t *iv, bool verbose) { memcpy(&iv[0], &session->R_Ctr, 2); memcpy(&iv[2], &session->W_Ctr, 2); memcpy(&iv[4], &session->R_Ctr, 2); @@ -119,7 +119,7 @@ int CalculateEncIVResponse(mf4Session *session, uint8_t *iv, bool verbose) { return 0; } - +*/ int CalculateMAC(mf4Session *session, MACType_t mtype, uint8_t blockNum, uint8_t blockCount, uint8_t *data, int datalen, uint8_t *mac, bool verbose) { if (!session || !session->Authenticated || !mac || !data || !datalen || datalen < 1) @@ -308,7 +308,7 @@ int MifareAuth4(mf4Session *session, uint8_t *keyn, uint8_t *key, bool activateF return 0; } -int intExchangeRAW14aPlus(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) { +static int intExchangeRAW14aPlus(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) { if (VerboseMode) PrintAndLogEx(INFO, ">>> %s", sprint_hex(datain, datainlen)); diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index b02c3e883..0b2a49048 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -263,14 +263,14 @@ int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultk } // Compare 16 Bits out of cryptostate -int Compare16Bits(const void *a, const void *b) { +static int Compare16Bits(const void *a, const void *b) { if ((*(uint64_t *)b & 0x00ff000000ff0000) == (*(uint64_t *)a & 0x00ff000000ff0000)) return 0; if ((*(uint64_t *)b & 0x00ff000000ff0000) > (*(uint64_t *)a & 0x00ff000000ff0000)) return 1; return -1; } // wrapper function for multi-threaded lfsr_recovery32 -void +static void #ifdef __has_attribute #if __has_attribute(force_align_arg_pointer) __attribute__((force_align_arg_pointer)) diff --git a/client/util.c b/client/util.c index 7febdac9f..9f600f85a 100644 --- a/client/util.c +++ b/client/util.c @@ -852,7 +852,7 @@ uint64_t HornerScheme(uint64_t num, uint64_t divider, uint64_t factor) { } // determine number of logical CPU cores (use for multithreaded functions) -extern int num_CPUs(void) { +int num_CPUs(void) { #if defined(_WIN32) #include SYSTEM_INFO sysinfo; @@ -866,16 +866,16 @@ extern int num_CPUs(void) { #endif } -extern void str_lower(char *s) { +void str_lower(char *s) { for (int i = 0; i < strlen(s); i++) s[i] = tolower(s[i]); } -extern bool str_startswith(const char *s, const char *pre) { +bool str_startswith(const char *s, const char *pre) { return strncmp(pre, s, strlen(pre)) == 0; } // Replace unprintable characters with a dot in char buffer -extern void clean_ascii(unsigned char *buf, size_t len) { +void clean_ascii(unsigned char *buf, size_t len) { for (size_t i = 0; i < len; i++) { if (!isprint(buf[i])) buf[i] = '.'; @@ -883,20 +883,20 @@ extern void clean_ascii(unsigned char *buf, size_t len) { } // replace \r \n to \0 -extern void strcleanrn(char *buf, size_t len) { +void strcleanrn(char *buf, size_t len) { strcreplace(buf, len, '\n', '\0'); strcreplace(buf, len, '\r', '\0'); } // replace char in buffer -extern void strcreplace(char *buf, size_t len, char from, char to) { +void strcreplace(char *buf, size_t len, char from, char to) { for (size_t i = 0; i < len; i++) { if (buf[i] == from) buf[i] = to; } } -extern char *strmcopy(char *buf) { +char *strmcopy(char *buf) { char *str = (char *) calloc(strlen(buf) + 1, sizeof(uint8_t)); if (str != NULL) { memset(str, 0, strlen(buf) + 1); diff --git a/client/util.h b/client/util.h index 978dcde81..5e60868bb 100644 --- a/client/util.h +++ b/client/util.h @@ -261,6 +261,7 @@ int num_CPUs(void); // number of logical CPUs void str_lower(char *s); // converts string to lower case bool str_startswith(const char *s, const char *pre); // check for prefix in string +void clean_ascii(unsigned char *buf, size_t len); void strcleanrn(char *buf, size_t len); void strcreplace(char *buf, size_t len, char from, char to); char *strmcopy(char *buf); diff --git a/common/lfdemod.c b/common/lfdemod.c index 81a8bb545..107a82f2b 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -286,7 +286,7 @@ bool preambleSearchEx(uint8_t *bits, uint8_t *preamble, size_t pLen, size_t *siz } // find start of modulating data (for fsk and psk) in case of beginning noise or slow chip startup. -size_t findModStart(uint8_t *src, size_t size, uint8_t expWaveSize) { +static size_t findModStart(uint8_t *src, size_t size, uint8_t expWaveSize) { size_t i = 0; size_t waveSizeCnt = 0; uint8_t thresholdCnt = 0; @@ -311,7 +311,7 @@ size_t findModStart(uint8_t *src, size_t size, uint8_t expWaveSize) { return i; } -int getClosestClock(int testclk) { +static int getClosestClock(int testclk) { uint16_t clocks[] = {8, 16, 32, 40, 50, 64, 100, 128, 256, 384}; uint8_t limit[] = {1, 2, 4, 4, 5, 8, 8, 8, 8, 8}; @@ -1175,7 +1175,7 @@ uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, // look for Sequence Terminator - should be pulses of clk*(1 or 2), clk*2, clk*(1.5 or 2), by idx we mean graph position index... -bool findST(int *stStopLoc, int *stStartIdx, int lowToLowWaveLen[], int highToLowWaveLen[], int clk, int tol, int buffSize, size_t *i) { +static bool findST(int *stStopLoc, int *stStartIdx, int lowToLowWaveLen[], int highToLowWaveLen[], int clk, int tol, int buffSize, size_t *i) { if (buffSize < *i + 4) return false; for (; *i < buffSize - 4; *i += 1) { @@ -1322,7 +1322,8 @@ bool DetectST(uint8_t *buffer, size_t *size, int *foundclock, size_t *ststart, s //check for phase errors - should never have half a 1 or 0 by itself and should never exceed 1111 or 0000 in a row //decodes miller encoded binary //NOTE askrawdemod will NOT demod miller encoded ask unless the clock is manually set to 1/2 what it is detected as! -int millerRawDecode(uint8_t *bits, size_t *size, int invert) { +/* +static int millerRawDecode(uint8_t *bits, size_t *size, int invert) { if (*size < 16) return -1; uint16_t MaxBits = 512, errCnt = 0; @@ -1355,6 +1356,7 @@ int millerRawDecode(uint8_t *bits, size_t *size, int invert) { *size = bitCnt; return errCnt; } +*/ //by marshmellow //take 01 or 10 = 1 and 11 or 00 = 0 @@ -1448,7 +1450,7 @@ int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos) //by marshmellow //demodulates strong heavily clipped samples //RETURN: num of errors. if 0, is ok. -int cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int invert, int high, int low, int *startIdx) { +static int cleanAskRawDemod(uint8_t *bits, size_t *size, int clk, int invert, int high, int low, int *startIdx) { *startIdx = 0; size_t bitCnt = 0, smplCnt = 1, errCnt = 0, pos = 0; uint8_t cl_4 = clk / 4; @@ -1675,7 +1677,7 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startId } //translate wave to 11111100000 (1 for each short wave [higher freq] 0 for each long wave [lower freq]) -size_t fsk_wave_demod(uint8_t *dest, size_t size, uint8_t fchigh, uint8_t fclow, int *startIdx) { +static size_t fsk_wave_demod(uint8_t *dest, size_t size, uint8_t fchigh, uint8_t fclow, int *startIdx) { if (size < 1024) return 0; // not enough samples @@ -1770,7 +1772,7 @@ size_t fsk_wave_demod(uint8_t *dest, size_t size, uint8_t fchigh, uint8_t fclow, //translate 11111100000 to 10 //rfLen = clock, fchigh = larger field clock, fclow = smaller field clock -size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { +static size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) { uint8_t lastval = dest[0]; size_t i = 0;