Fixed random_r redefinition warning

See #64
This commit is contained in:
wiire-a 2017-10-31 14:59:45 +01:00
parent d3e4aab2e8
commit 60e8db7b93
5 changed files with 32 additions and 63 deletions

View File

@ -4,6 +4,6 @@ include $(CLEAR_VARS)
LOCAL_CFLAGS:=-std=c99 -O3 LOCAL_CFLAGS:=-std=c99 -O3
LOCAL_MODULE:=pixiewps LOCAL_MODULE:=pixiewps
LOCAL_SRC_FILES:=pixiewps.c random_r.c mbedtls/sha256.c mbedtls/md.c mbedtls/md_wrap.c LOCAL_SRC_FILES:=pixiewps.c mbedtls/sha256.c mbedtls/md.c mbedtls/md_wrap.c
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)

View File

@ -2,7 +2,7 @@ CFLAGS ?= -std=c99 -O3
TARGET = pixiewps TARGET = pixiewps
CRYPTO = mbedtls/sha256.c mbedtls/md.c mbedtls/md_wrap.c CRYPTO = mbedtls/sha256.c mbedtls/md.c mbedtls/md_wrap.c
SOURCE = $(TARGET).c random_r.c $(CRYPTO) SOURCE = $(TARGET).c $(CRYPTO)
LIBS = -lpthread LIBS = -lpthread
PREFIX ?= /usr PREFIX ?= /usr

View File

@ -43,7 +43,7 @@
#include "crypto/aes-cbc.c" #include "crypto/aes-cbc.c"
#include "utils.h" #include "utils.h"
#include "wps.h" #include "wps.h"
#include "random_r.h" #include "random_r.c"
#include "version.h" #include "version.h"
uint32_t ecos_rand_simplest(uint32_t *seed); uint32_t ecos_rand_simplest(uint32_t *seed);
@ -94,19 +94,19 @@ static struct job_control {
static void *crack_thread(void *arg) { static void *crack_thread(void *arg) {
struct crack_job *j = arg; struct crack_job *j = arg;
struct random_data *buf = calloc(1, sizeof(struct random_data)); struct m_random_data *buf = calloc(1, sizeof(struct m_random_data));
char *rand_statebuf = calloc(128, 1); char *rand_statebuf = calloc(128, 1);
uint32_t seed = j->start; uint32_t seed = j->start;
uint32_t limit = job_control.end; uint32_t limit = job_control.end;
initstate_r(seed, rand_statebuf, 128, buf); m_initstate_r(seed, rand_statebuf, 128, buf);
int32_t res = 0; int32_t res = 0;
while (!job_control.nonce_seed) { while (!job_control.nonce_seed) {
srandom_r(seed, buf); m_srandom_r(seed, buf);
unsigned int i; unsigned int i;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
random_r(buf, &res); m_random_r(buf, &res);
if ((uint32_t) res != job_control.randr_enonce[i]) if ((uint32_t) res != job_control.randr_enonce[i])
break; break;
} }
@ -868,9 +868,9 @@ usage_err:
nonce_seed = collect_crack_jobs(); nonce_seed = collect_crack_jobs();
struct random_data *buf = calloc(1, sizeof(struct random_data)); struct m_random_data *buf = calloc(1, sizeof(struct m_random_data));
char *rand_statebuf = calloc(1, 128); char *rand_statebuf = calloc(1, 128);
initstate_r(nonce_seed, rand_statebuf, 128, buf); m_initstate_r(nonce_seed, rand_statebuf, 128, buf);
if (nonce_seed) { /* Seed found */ if (nonce_seed) { /* Seed found */
int32_t res; int32_t res;
@ -881,9 +881,9 @@ usage_err:
do { do {
i++; i++;
srandom_r(nonce_seed + i, buf); m_srandom_r(nonce_seed + i, buf);
for (uint_fast8_t j = 0; j < 4; j++) { for (uint_fast8_t j = 0; j < 4; j++) {
random_r(buf, &res); m_random_r(buf, &res);
uint32_t be = h32_to_be(res); uint32_t be = h32_to_be(res);
memcpy(&(wps->e_s1[4 * j]), &be, 4); memcpy(&(wps->e_s1[4 * j]), &be, 4);
memcpy(wps->e_s2, wps->e_s1, WPS_SECRET_NONCE_LEN); /* E-S1 = E-S2 != E-Nonce */ memcpy(wps->e_s2, wps->e_s1, WPS_SECRET_NONCE_LEN); /* E-S1 = E-S2 != E-Nonce */
@ -934,9 +934,9 @@ usage_err:
i = 0; i = 0;
do { do {
i++; i++;
srandom_r(nonce_seed - i, buf); m_srandom_r(nonce_seed - i, buf);
for (uint_fast8_t j = 0; j < 4; j++) { for (uint_fast8_t j = 0; j < 4; j++) {
random_r(buf, &res); m_random_r(buf, &res);
uint32_t be = h32_to_be(res); uint32_t be = h32_to_be(res);
memcpy(&(wps->e_s1[4 * j]), &be, 4); memcpy(&(wps->e_s1[4 * j]), &be, 4);
memcpy(wps->e_s2, wps->e_s1, WPS_SECRET_NONCE_LEN); /* E-S1 = E-S2 != E-Nonce */ memcpy(wps->e_s2, wps->e_s1, WPS_SECRET_NONCE_LEN); /* E-S1 = E-S2 != E-Nonce */

View File

@ -37,7 +37,17 @@
# endif # endif
#endif #endif
#include "random_r.h" #include <stdint.h>
struct m_random_data {
int32_t *fptr; /* Front pointer */
int32_t *rptr; /* Rear pointer */
int32_t *state; /* Array of state values */
int rand_type; /* Type of random number generator */
int rand_deg; /* Degree of random number generator */
int rand_sep; /* Distance between front and rear */
int32_t *end_ptr; /* Pointer behind state table */
};
/* An improved random number generation package. In addition to the standard /* An improved random number generation package. In addition to the standard
rand()/srand() like interface, this package also has a special state info rand()/srand() like interface, this package also has a special state info
@ -116,7 +126,7 @@
#define MAX_TYPES 5 /* Max number of types above. */ #define MAX_TYPES 5 /* Max number of types above. */
struct random_poly_info struct m_random_poly_info
{ {
/* smallint seps[MAX_TYPES]; */ /* smallint seps[MAX_TYPES]; */
/* smallint degrees[MAX_TYPES]; */ /* smallint degrees[MAX_TYPES]; */
@ -124,7 +134,7 @@ struct random_poly_info
unsigned char degrees[MAX_TYPES]; unsigned char degrees[MAX_TYPES];
}; };
static const struct random_poly_info random_poly_info = static const struct m_random_poly_info random_poly_info =
{ {
{ SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }, { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 },
{ DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 } { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }
@ -142,7 +152,7 @@ static const struct random_poly_info random_poly_info =
rear pointers can't wrap on the same call by not testing the rear rear pointers can't wrap on the same call by not testing the rear
pointer if the front one has wrapped. Returns a 31-bit random number. */ pointer if the front one has wrapped. Returns a 31-bit random number. */
void random_r(struct random_data *buf, int32_t *result) void m_random_r(struct m_random_data *buf, int32_t *result)
{ {
int32_t *state; int32_t *state;
@ -200,7 +210,7 @@ void random_r(struct random_data *buf, int32_t *result)
information a given number of times to get rid of any initial dependencies information a given number of times to get rid of any initial dependencies
introduced by the L.C.R.N.G. Note that the initialization of randtbl[] introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
for default usage relies on values produced by this routine. */ for default usage relies on values produced by this routine. */
int srandom_r (unsigned int seed, struct random_data *buf) int m_srandom_r (unsigned int seed, struct m_random_data *buf)
{ {
int type; int type;
int32_t *state; int32_t *state;
@ -245,7 +255,7 @@ int srandom_r (unsigned int seed, struct random_data *buf)
while (--kc >= 0) while (--kc >= 0)
{ {
int32_t discard; int32_t discard;
(void) random_r (buf, &discard); (void) m_random_r (buf, &discard);
} }
done: done:
@ -268,7 +278,7 @@ fail:
Note: The first thing we do is save the current state, if any, just like Note: The first thing we do is save the current state, if any, just like
setstate so that it doesn't matter when initstate is called. setstate so that it doesn't matter when initstate is called.
Returns a pointer to the old state. */ Returns a pointer to the old state. */
int initstate_r (unsigned int seed, char *arg_state, size_t n, struct random_data *buf) int m_initstate_r (unsigned int seed, char *arg_state, size_t n, struct m_random_data *buf)
{ {
int type; int type;
int degree; int degree;
@ -304,7 +314,7 @@ int initstate_r (unsigned int seed, char *arg_state, size_t n, struct random_dat
buf->state = state; buf->state = state;
srandom_r (seed, buf); m_srandom_r (seed, buf);
state[-1] = TYPE_0; state[-1] = TYPE_0;
if (type != TYPE_0) if (type != TYPE_0)
@ -327,7 +337,7 @@ fail:
to the order in which things are done, it is OK to call setstate with the to the order in which things are done, it is OK to call setstate with the
same state as the current state same state as the current state
Returns a pointer to the old state information. */ Returns a pointer to the old state information. */
int setstate_r (char *arg_state, struct random_data *buf) int m_setstate_r (char *arg_state, struct m_random_data *buf)
{ {
int32_t *new_state = 1 + (int32_t *) arg_state; int32_t *new_state = 1 + (int32_t *) arg_state;
int type; int type;

View File

@ -1,41 +0,0 @@
/*
* Pixiewps: bruteforce the wps pin exploiting the low or non-existing entropy of some APs (pixie dust attack).
* All credits for the research go to Dominique Bongard.
*
* Copyright (c) 2015-2016, wiire <wi7ire@gmail.com>
* SPDX-License-Identifier: GPL-3.0+
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RANDOM_R_H
#define RANDOM_R_H
#include <stdint.h>
struct random_data {
int32_t *fptr; /* Front pointer */
int32_t *rptr; /* Rear pointer */
int32_t *state; /* Array of state values */
int rand_type; /* Type of random number generator */
int rand_deg; /* Degree of random number generator */
int rand_sep; /* Distance between front and rear */
int32_t *end_ptr; /* Pointer behind state table */
};
void random_r(struct random_data *buf, int32_t *result);
int srandom_r(unsigned int seed, struct random_data *buf);
int initstate_r(unsigned int seed, char *arg_state, size_t n, struct random_data *buf);
int setstate_r(char *arg_state, struct random_data *buf);
#endif /* RANDOM_R_H */