From fd2186731141b3105f9a012fa89aabc3d0d8d28e Mon Sep 17 00:00:00 2001 From: wiire-a Date: Sun, 3 Dec 2017 21:18:02 +0100 Subject: [PATCH] Cosmetic changes --- src/crypto/hmac_sha256.c | 23 +++++++++++------------ src/pixiewps.c | 10 +++++----- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/crypto/hmac_sha256.c b/src/crypto/hmac_sha256.c index 9972a7b..07d1f55 100644 --- a/src/crypto/hmac_sha256.c +++ b/src/crypto/hmac_sha256.c @@ -1,15 +1,15 @@ -/* public domain hmac_sha256 implementation written by rofl0r for pixiewps */ +/* Public domain hmac_sha256 implementation written by rofl0r for pixiewps */ #include #include #ifdef USE_OPENSSL -#include +# include #else -#include "../mbedtls/sha256.h" -#define SHA256_CTX mbedtls_sha256_context -#define SHA256_Init(x) do { mbedtls_sha256_init(x); mbedtls_sha256_starts(x, 0); } while(0) -#define SHA256_Update(x, y, z) mbedtls_sha256_update(x, y, z) -#define SHA256_Final(y, x) mbedtls_sha256_finish(x, y) +# include "../mbedtls/sha256.h" +# define SHA256_CTX mbedtls_sha256_context +# define SHA256_Init(x) do { mbedtls_sha256_init(x); mbedtls_sha256_starts(x, 0); } while(0) +# define SHA256_Update(x, y, z) mbedtls_sha256_update(x, y, z) +# define SHA256_Final(y, x) mbedtls_sha256_finish(x, y) #endif #define PAD_SIZE 64 @@ -66,23 +66,23 @@ struct hmac_ctx { SHA256_CTX octx; }; -static void hmac_sha256_init(struct hmac_ctx *hctx, const uint8_t *key, size_t keylen) +static void hmac_sha256_init(struct hmac_ctx *hctx, const uint8_t *key, + size_t keylen) { size_t i; - uint8_t opad[PAD_SIZE], ipad[PAD_SIZE]; + uint8_t opad[PAD_SIZE], ipad[PAD_SIZE], hash[HASH_SIZE]; SHA256_CTX ctx; memset(ipad, 0x36, PAD_SIZE); memset(opad, 0x5C, PAD_SIZE); if (keylen > PAD_SIZE) { - uint8_t hash[HASH_SIZE]; SHA256_Init(&ctx); SHA256_Update(&ctx, key, keylen); SHA256_Final(hash, &ctx); - for (i = 0; ioctx, sizeof(ctx)); SHA256_Update(&ctx, hash, sizeof hash); diff --git a/src/pixiewps.c b/src/pixiewps.c index 92f9914..6bdb4fe 100644 --- a/src/pixiewps.c +++ b/src/pixiewps.c @@ -355,7 +355,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 */ + /* Checking 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]; @@ -373,7 +373,7 @@ static int find_rtl_es(struct global *wps) char pin_copy[WPS_PIN_LEN + 1]; strcpy(pin_copy, wps->pin); int j; - /* we assume that the seed used for es2 is within a range of 10 seconds + /* We assume that the seed used for es2 is within a range of 10 seconds forwards in time only */ for (j = 0; j < 10; j++) { strcpy(wps->pin, pin_copy); @@ -392,7 +392,7 @@ static int find_rtl_es(struct global *wps) static void empty_pin_hmac(struct global *wps) { - /* since the empty pin psk is static once initialized, we calculate it only once */ + /* Since the empty pin psk is static once initialized, we calculate it only once */ hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, NULL, 0, wps->empty_psk); } @@ -1474,7 +1474,7 @@ static uint32_t ecos_rand_knuth(uint32_t *seed) return *seed; } -/* return non-zero if pin half is correct, zero otherwise */ +/* Return non-zero if pin half is correct, zero otherwise */ static int check_pin_half(const struct hmac_ctx *hctx, const char pinhalf[4], uint8_t *psk, const uint8_t *es, struct global *wps, const uint8_t *ehash) { uint8_t buffer[WPS_SECRET_NONCE_LEN + WPS_PSK_LEN + WPS_PKEY_LEN * 2]; @@ -1490,7 +1490,7 @@ static int check_pin_half(const struct hmac_ctx *hctx, const char pinhalf[4], ui return !memcmp(result, ehash, WPS_HASH_LEN); } -/* return non-zero if pin half is correct, zero otherwise */ +/* Return non-zero if pin half is correct, zero otherwise */ static int check_empty_pin_half(const uint8_t *es, struct global *wps, const uint8_t *ehash) { uint8_t buffer[WPS_SECRET_NONCE_LEN + WPS_PSK_LEN + WPS_PKEY_LEN * 2];