Added endianness check for Android

This commit is contained in:
wiire 2015-08-24 14:08:25 +02:00
parent 86d6debe3a
commit d917f8f940
3 changed files with 27 additions and 4 deletions

View File

@ -46,17 +46,21 @@
#include <getopt.h> #include <getopt.h>
#include <sys/time.h> #include <sys/time.h>
#include "utils.h"
#ifdef __MACH__ #ifdef __MACH__
# include <libkern/OSByteOrder.h> # include <libkern/OSByteOrder.h>
# define be32(x) OSSwapBigToHostInt32(x) # define be32(x) OSSwapBigToHostInt32(x)
#elif __ANDROID__
# define be32(x) h32tbe(x)
#else #else
# include <asm/byteorder.h> # include <asm/byteorder.h>
# define be32(x) __be32_to_cpu(x) # define be32(x) __be32_to_cpu(x)
#endif /* __MACH__ */ #endif
#include "pixiewps.h" #include "pixiewps.h"
#include "random_r.h" #include "random_r.h"
#include "utils.h"
int32_t rand_r(uint32_t *seed); int32_t rand_r(uint32_t *seed);

View File

@ -145,7 +145,6 @@ void hmac_sha256(const void *key, int key_len, const unsigned char *data, const
/* Key Derivation Function */ /* Key Derivation Function */
void kdf(const void *key, const size_t key_len, unsigned char *res) { void kdf(const void *key, const size_t key_len, unsigned char *res) {
uint32_t i = 1;
uint32_t kdk_len = key_len * 8; uint32_t kdk_len = key_len * 8;
uint_fast8_t j = 0; uint_fast8_t j = 0;
@ -154,7 +153,7 @@ void kdf(const void *key, const size_t key_len, unsigned char *res) {
unsigned char *buffer = malloc(WPS_KDF_SALT_LEN + 4 * 2); unsigned char *buffer = malloc(WPS_KDF_SALT_LEN + 4 * 2);
for (i = 1; i < 4; i++) { for (uint32_t i = 1; i < 4; i++) {
uint32_t be = be32(i); uint32_t be = be32(i);
memcpy(buffer, &be, 4); memcpy(buffer, &be, 4);
memcpy(buffer + 4, salt, WPS_KDF_SALT_LEN); memcpy(buffer + 4, salt, WPS_KDF_SALT_LEN);

View File

@ -106,4 +106,24 @@ 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 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;
res = b0 | b1 | b2 | b3;
} else { /* BE */
res = num;
}
return res;
}
#endif /* UTILS_H */ #endif /* UTILS_H */