Unified endian code

This commit is contained in:
wiire 2015-10-14 10:12:10 +02:00
parent d917f8f940
commit 6f42dc1279
3 changed files with 9 additions and 20 deletions

View File

@ -48,17 +48,6 @@
#include <sys/time.h>
#include "utils.h"
#ifdef __MACH__
# include <libkern/OSByteOrder.h>
# define be32(x) OSSwapBigToHostInt32(x)
#elif __ANDROID__
# define be32(x) h32tbe(x)
#else
# include <asm/byteorder.h>
# define be32(x) __be32_to_cpu(x)
#endif
#include "pixiewps.h"
#include "random_r.h"
@ -429,7 +418,7 @@ int main(int argc, char **argv) {
srandom_r(print_seed + 1, buf);
for (uint_fast8_t j = 0; j < 4; j++) {
random_r(buf, &res);
uint32_t be = be32(res);
uint32_t be = h32_to_be(res);
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 */
}

View File

@ -154,10 +154,10 @@ void kdf(const void *key, const size_t key_len, unsigned char *res) {
unsigned char *buffer = malloc(WPS_KDF_SALT_LEN + 4 * 2);
for (uint32_t i = 1; i < 4; i++) {
uint32_t be = be32(i);
uint32_t be = h32_to_be(i);
memcpy(buffer, &be, 4);
memcpy(buffer + 4, salt, WPS_KDF_SALT_LEN);
be = be32(kdk_len);
be = h32_to_be(kdk_len);
memcpy(buffer + 4 + 36, &be, 4);
hmac_sha256(key, WPS_HASH_LEN, buffer, WPS_KDF_SALT_LEN + 4 * 2, res + j);
j += WPS_HASH_LEN;

View File

@ -107,18 +107,18 @@ void byte_array_print(const unsigned char *buffer, const unsigned int length) {
}
/* Converts a 32 Little Endian bit number to its Big Endian representation */
unsigned int h32tbe(uint32_t num) {
uint32_t temp = num;
uint32_t h32_to_be(uint32_t num) {
uint32_t tmp = num;
uint32_t res;
uint32_t b0, b1, b2, b3;
unsigned int i = 1;
char *p = (char *) &i;
if (p[0] == 1) { /* LE */
b0 = (num & 0x000000ff) << 24;
b1 = (num & 0x0000ff00) << 8;
b2 = (num & 0x00ff0000) >> 8;
b3 = (num & 0xff000000) >> 24;
b0 = (tmp & 0x000000ff) << 24;
b1 = (tmp & 0x0000ff00) << 8;
b2 = (tmp & 0x00ff0000) >> 8;
b3 = (tmp & 0xff000000) >> 24;
res = b0 | b1 | b2 | b3;
} else { /* BE */
res = num;