diff --git a/src/Makefile b/src/Makefile index 3affc65..8e82790 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ CFLAGS = -std=c99 -O3 -LIBS = -lpthread +LIBS = -lpthread ifeq ($(OPENSSL),1) LIBS += -lcrypto CFLAGS += -DUSE_OPENSSL diff --git a/src/config.h b/src/config.h index f73845f..ce0a157 100644 --- a/src/config.h +++ b/src/config.h @@ -29,13 +29,13 @@ #define hmac_sha256(k, l, i, n, o) \ hmac_sha256_full(k, l, i, n, o) -#define u8 uint8_t -#define u16 uint16_t -#define u32 uint32_t -#define u64 uint64_t -#define os_memcpy memcpy -#define os_malloc malloc -#define os_memset memset -#define os_free free +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t +#define u64 uint64_t +#define os_memcpy memcpy +#define os_malloc malloc +#define os_memset memset +#define os_free free #endif /* CONFIG_H */ diff --git a/src/pixiewps.c b/src/pixiewps.c index 6995c01..cd4852e 100644 --- a/src/pixiewps.c +++ b/src/pixiewps.c @@ -252,7 +252,7 @@ static void init_crack_jobs(struct global *wps, int mode) job_control.nonce_seed = 0; memset(job_control.randr_enonce, 0, sizeof(job_control.randr_enonce)); - /* Converting enrollee nonce to the sequence may be generated by current random function */ + /* Convert Enrollee nonce to the sequence may be generated by current random function */ int i, j = 0; if (mode == -RTL819x) ; /* nuffin' */ else if (mode == RTL819x) @@ -362,7 +362,7 @@ static int find_rtl_es(struct global *wps) init_crack_jobs(wps, -RTL819x); - /* Checking distance 0 in the main thread, as it is the most likely */ + /* Check distance 0 in the main thread, as it is the most likely */ uint8_t nonce_buf[WPS_SECRET_NONCE_LEN]; char pin[WPS_PIN_LEN + 1]; @@ -961,7 +961,7 @@ usage_err: if (!wps->authkey) { if (wps->e_nonce) { if (wps->r_nonce) { - if (wps->e_bssid) { /* Computing AuthKey */ + if (wps->e_bssid) { /* Compute AuthKey */ wps->dhkey = malloc(WPS_HASH_LEN); if (!wps->dhkey) goto memory_err; @@ -1033,11 +1033,11 @@ usage_err: } } - /* Allocating memory for E-S1 and E-S2 */ + /* Allocate memory for E-S1 and E-S2 */ wps->e_s1 = malloc(WPS_SECRET_NONCE_LEN); if (!wps->e_s1) goto memory_err; wps->e_s2 = malloc(WPS_SECRET_NONCE_LEN); if (!wps->e_s2) goto memory_err; - /* Allocating memory for digests */ + /* Allocate memory for digests */ wps->psk1 = malloc(WPS_HASH_LEN); if (!wps->psk1) goto memory_err; wps->psk2 = malloc(WPS_HASH_LEN); if (!wps->psk2) goto memory_err; wps->empty_psk = malloc(WPS_HASH_LEN); if (!wps->empty_psk) goto memory_err; @@ -1133,7 +1133,7 @@ usage_err: DEBUG_PRINT(" * Mode: %d (%s)", ECOS_SIMPLE, p_mode_name[ECOS_SIMPLE]); - uint32_t known = wps->e_nonce[0] << 25; /* Reducing entropy from 32 to 25 bits */ + uint32_t known = wps->e_nonce[0] << 25; /* Reduce entropy from 32 to 25 bits */ uint32_t seed, counter = 0; while (counter < 0x02000000) { int i; @@ -1194,7 +1194,7 @@ usage_err: } else { - /* Checks if the sequence may actually be generated by current random function */ + /* Check if the sequence may actually be generated by current random function */ if (!(wps->e_nonce[0] & 0x80) && !(wps->e_nonce[4] & 0x80) && !(wps->e_nonce[8] & 0x80) && !(wps->e_nonce[12] & 0x80)) { @@ -1519,7 +1519,7 @@ static int check_empty_pin_half(const uint8_t *es, struct global *wps, const uin return !memcmp(result, ehash, WPS_HASH_LEN); } -/* returns 1 if numeric pin half found, -1 if empty pin found, 0 if not found */ +/* Return 1 if numeric pin half found, -1 if empty pin found, 0 if not found */ static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_override) { *pin = 0; @@ -1538,7 +1538,7 @@ static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_ov for (first_half = 0; first_half < 10000; first_half++) { uint_to_char_array(first_half, 4, pin); if (check_pin_half(&hc, pin, psk, es1, wps, wps->e_hash1)) { - pin[4] = 0; /* make sure pin string is zero-terminated */ + pin[4] = 0; /* Make sure pin string is zero-terminated */ memcpy(wps->psk1, psk, sizeof psk); return 1; } @@ -1547,7 +1547,7 @@ static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_ov return 0; } -/* returns non-zero if pin found, -1 if empty pin found, 0 if not found */ +/* Return non-zero if pin found, -1 if empty pin found, 0 if not found */ static int crack_second_half(struct global *wps, char *pin) { if (!pin[0] && check_empty_pin_half(wps->e_s2, wps, wps->e_hash2)) { @@ -1583,7 +1583,7 @@ static int crack_second_half(struct global *wps, char *pin) uint_to_char_array(second_half, 4, s_pin); if (check_pin_half(&hc, s_pin, psk, wps->e_s2, wps, wps->e_hash2)) { memcpy(wps->psk2, psk, sizeof psk); - pin[8] = 0; /* make sure pin string is zero-terminated */ + pin[8] = 0; /* Make sure pin string is zero-terminated */ return 1; } } @@ -1591,7 +1591,7 @@ static int crack_second_half(struct global *wps, char *pin) return 0; } -/* PIN cracking attempt - returns 0 for success, 1 for failure */ +/* PIN cracking attempt, return 0 for success, 1 for failure */ static int crack(struct global *wps, char *pin) { return !(crack_first_half(wps, pin, 0) && crack_second_half(wps, pin)); diff --git a/src/pixiewps.h b/src/pixiewps.h index 0f80e2b..c4bd6a6 100644 --- a/src/pixiewps.h +++ b/src/pixiewps.h @@ -45,7 +45,7 @@ #include "utils.h" #ifndef WPS_PIN_LEN -#define WPS_PIN_LEN 8 +# define WPS_PIN_LEN 8 #endif #if defined(DEBUG) @@ -87,13 +87,12 @@ const uint8_t wps_rtl_pke[] = { 0x66,0xA5,0xA4,0x90, 0x47,0x2C,0xEB,0xA9, 0xE3,0xB4,0x22,0x4F, 0x3D,0x89,0xFB,0x2B }; -/* Unused */ -const uint8_t rtl_rnd_seed[] = { +/* const uint8_t rtl_rnd_seed[] = { 0x52,0x65,0x61,0x6c, 0x74,0x65,0x6b,0x20, 0x57,0x69,0x46,0x69, 0x20,0x53,0x69,0x6d, 0x70,0x6c,0x65,0x2d, 0x43,0x6f,0x6e,0x66, 0x69,0x67,0x20,0x44, 0x61,0x65,0x6d,0x6f, 0x6e,0x20,0x70,0x72, 0x6f,0x67,0x72,0x61, 0x6d,0x20,0x32,0x30, 0x30,0x36,0x2d,0x30, 0x35,0x2d,0x31,0x35 -}; +}; */ struct global { char pin[WPS_PIN_LEN + 1]; @@ -154,8 +153,6 @@ char usage[] = "\n" " -m, --r-nonce : Registrar nonce\n" " -b, --e-bssid : Enrollee BSSID\n" -// " -S, --dh-small : Small Diffie-Hellman keys (PKr not needed) [No]\n" -// " -l, --length : Bruteforce entire pin length (experimental)\n" " -v, --verbosity : Verbosity level 1-3, 1 is quietest [3]\n" " -o, --output : Write output to file\n" " -j, --jobs : Number of parallel threads to use [Auto]\n" @@ -286,7 +283,7 @@ static inline uint_fast8_t parse_mode(char *list, uint_fast8_t *dst, const uint8 return 0; } -/* Checks if passed mode is selected */ +/* Check if passed mode is selected */ static inline uint_fast8_t is_mode_selected(const uint_fast8_t mode) { for (uint_fast8_t i = 0; i < MODE_LEN && p_mode[i] != NONE; i++) { diff --git a/src/utils.h b/src/utils.h index 1627912..97f3388 100644 --- a/src/utils.h +++ b/src/utils.h @@ -23,7 +23,7 @@ #include -/* Converts an hex string to a byte array */ +/* Convert an hex string to a byte array */ unsigned int hex_string_to_byte_array(char *in, uint8_t *out, const unsigned int n_len) { unsigned int len = strlen(in); @@ -57,7 +57,7 @@ unsigned int hex_string_to_byte_array(char *in, uint8_t *out, const unsigned int return 0; } -/* Converts an hex string to a byte array */ +/* Convert an hex string to a byte array */ unsigned int hex_string_to_byte_array_max( char *in, uint8_t *out, const unsigned int max_len, unsigned int *m_len) { @@ -111,7 +111,7 @@ end: return 0; } -/* Converts a string into an integer */ +/* Convert a string into an integer */ int get_int(char *in, int *out) { int i, o = 0, len = strlen(in); @@ -172,7 +172,7 @@ time_t c_timegm(register struct tm *t) return result; } -/* Converts a [mm/]yyyy string to Unix date time */ +/* Convert a [mm/]yyyy string to Unix date time */ unsigned int get_unix_datetime(char *s, time_t *datetime) { unsigned int len = strlen(s); @@ -217,14 +217,10 @@ unsigned int get_unix_datetime(char *s, time_t *datetime) *datetime = (time_t)0x7fffffff; } else { - struct tm t; - t.tm_sec = 0; - t.tm_min = 0; - t.tm_hour = 0; - t.tm_mday = 1; - t.tm_mon = month - 1; - t.tm_year = year - 1900; - t.tm_isdst = 0; + struct tm t = { + .tm_year = year - 1900, + .tm_mon = month - 1, + .tm_mday = 1 }; *datetime = c_timegm(&t); if (*datetime < 0) /* When time_t is 64 bits this check is pointless */ @@ -234,13 +230,13 @@ unsigned int get_unix_datetime(char *s, time_t *datetime) return 0; } -/* Returns the difference of time between the two in milliseconds */ +/* Return the difference of time between the two in milliseconds */ unsigned long get_elapsed_ms(struct timeval *start, struct timeval *end) { return (((end->tv_sec - start->tv_sec) * 1000000 + (end->tv_usec - start->tv_usec)) / 1000); } -/* Converts an unsigned integer to a char array without termination */ +/* Convert an unsigned integer to a char array without termination */ static inline void uint_to_char_array(unsigned int num, unsigned int len, char *dst) { unsigned int mul = 1; @@ -250,14 +246,11 @@ static inline void uint_to_char_array(unsigned int num, unsigned int len, char * } } -/* Prints a byte array in hexadecimal */ +/* Print a byte array in hexadecimal */ void byte_array_print(const uint8_t *buffer, const unsigned int length) { - for (unsigned int i = 0; i < length; i++) { + for (unsigned int i = 0; i < length; i++) printf("%02x", buffer[i]); -// if (i != length - 1) -// printf(":"); - } } #endif /* UTILS_H */