mirror of
https://github.com/wiire-a/pixiewps.git
synced 2025-07-27 15:54:29 +02:00
remove dynamic allocation from crack() - simplifies code a lot
it's just a couple hundred bytes, less than half a KB anyway - using malloc there was overkill and had huge error-handling overhead.
This commit is contained in:
parent
c3fc4a81a0
commit
707894f2f1
@ -357,12 +357,6 @@ static int find_rtl_es_dir(struct global *wps, char *pin, int dir)
|
|||||||
found_p_mode = RTL819x;
|
found_p_mode = RTL819x;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r2 == MEM_ERROR) {
|
|
||||||
return -MEM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
return -MEM_ERROR;
|
|
||||||
}
|
}
|
||||||
} while (found_p_mode == NONE && i != break_cond);
|
} while (found_p_mode == NONE && i != break_cond);
|
||||||
|
|
||||||
@ -1039,9 +1033,6 @@ usage_err:
|
|||||||
found_p_mode = RT;
|
found_p_mode = RT;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
goto memory_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found_p_mode) {
|
if (!found_p_mode) {
|
||||||
init_crack_jobs(wps, RT);
|
init_crack_jobs(wps, RT);
|
||||||
@ -1074,9 +1065,6 @@ usage_err:
|
|||||||
found_p_mode = RT;
|
found_p_mode = RT;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
goto memory_err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1122,9 +1110,6 @@ usage_err:
|
|||||||
found_p_mode = ECOS_SIMPLE;
|
found_p_mode = ECOS_SIMPLE;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
goto memory_err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3 */
|
/* 3 */
|
||||||
@ -1147,9 +1132,6 @@ usage_err:
|
|||||||
found_p_mode = RTL819x;
|
found_p_mode = RTL819x;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
goto memory_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found_p_mode == NONE) {
|
if (found_p_mode == NONE) {
|
||||||
if (wps->small_dh_keys || check_small_dh_keys(wps->pkr)) {
|
if (wps->small_dh_keys || check_small_dh_keys(wps->pkr)) {
|
||||||
@ -1188,9 +1170,6 @@ usage_err:
|
|||||||
|
|
||||||
if (wps->nonce_seed) { /* Seed found */
|
if (wps->nonce_seed) { /* Seed found */
|
||||||
found_p_mode = find_rtl_es(wps, pin);
|
found_p_mode = find_rtl_es(wps, pin);
|
||||||
if (found_p_mode == -MEM_ERROR)
|
|
||||||
goto memory_err;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_p_mode == NONE && !wps->bruteforce) {
|
if (found_p_mode == NONE && !wps->bruteforce) {
|
||||||
@ -1248,9 +1227,6 @@ usage_err:
|
|||||||
found_p_mode = ECOS_SIMPLEST;
|
found_p_mode = ECOS_SIMPLEST;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
goto memory_err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 5 */
|
/* 5 */
|
||||||
@ -1296,9 +1272,6 @@ usage_err:
|
|||||||
found_p_mode = ECOS_KNUTH;
|
found_p_mode = ECOS_KNUTH;
|
||||||
DEBUG_PRINT("Pin found");
|
DEBUG_PRINT("Pin found");
|
||||||
}
|
}
|
||||||
else if (r == MEM_ERROR) {
|
|
||||||
goto memory_err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1486,15 +1459,8 @@ uint_fast8_t crack(struct global *g, char *pin)
|
|||||||
char mask[5];
|
char mask[5];
|
||||||
uint_fast8_t found = 0;
|
uint_fast8_t found = 0;
|
||||||
|
|
||||||
uint8_t *buffer = malloc(WPS_SECRET_NONCE_LEN + WPS_PSK_LEN + WPS_PKEY_LEN * 2);
|
uint8_t buffer[WPS_SECRET_NONCE_LEN + WPS_PSK_LEN + WPS_PKEY_LEN * 2];
|
||||||
if (!buffer)
|
uint8_t result[WPS_HASH_LEN];
|
||||||
return MEM_ERROR;
|
|
||||||
|
|
||||||
uint8_t *result = malloc(WPS_HASH_LEN);
|
|
||||||
if (!result) {
|
|
||||||
free(buffer);
|
|
||||||
return MEM_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wps->anylength) {
|
if (wps->anylength) {
|
||||||
|
|
||||||
@ -1564,9 +1530,6 @@ uint_fast8_t crack(struct global *g, char *pin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
free(result);
|
|
||||||
|
|
||||||
return !found;
|
return !found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1593,9 +1556,6 @@ uint_fast8_t crack(struct global *g, char *pin)
|
|||||||
if (!memcmp(result, wps->e_hash2, WPS_HASH_LEN)) {
|
if (!memcmp(result, wps->e_hash2, WPS_HASH_LEN)) {
|
||||||
|
|
||||||
/* Empty pin detected */
|
/* Empty pin detected */
|
||||||
free(buffer);
|
|
||||||
free(result);
|
|
||||||
|
|
||||||
pin[0] = '\0';
|
pin[0] = '\0';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1675,9 +1635,6 @@ uint_fast8_t crack(struct global *g, char *pin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
free(result);
|
|
||||||
|
|
||||||
snprintf(pin, WPS_PIN_LEN + 1, "%08u", first_half * 10000 + second_half);
|
snprintf(pin, WPS_PIN_LEN + 1, "%08u", first_half * 10000 + second_half);
|
||||||
|
|
||||||
return !found; /* 0 success, 1 failure */
|
return !found; /* 0 success, 1 failure */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user