mirror of
https://github.com/wiire-a/pixiewps.git
synced 2025-07-27 15:54:29 +02:00
Added endianness check for Android
This commit is contained in:
parent
86d6debe3a
commit
d917f8f940
@ -46,17 +46,21 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#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 /* __MACH__ */
|
||||
#endif
|
||||
|
||||
#include "pixiewps.h"
|
||||
#include "random_r.h"
|
||||
#include "utils.h"
|
||||
|
||||
int32_t rand_r(uint32_t *seed);
|
||||
|
||||
|
@ -145,7 +145,6 @@ void hmac_sha256(const void *key, int key_len, const unsigned char *data, const
|
||||
|
||||
/* Key Derivation Function */
|
||||
void kdf(const void *key, const size_t key_len, unsigned char *res) {
|
||||
uint32_t i = 1;
|
||||
uint32_t kdk_len = key_len * 8;
|
||||
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);
|
||||
|
||||
for (i = 1; i < 4; i++) {
|
||||
for (uint32_t i = 1; i < 4; i++) {
|
||||
uint32_t be = be32(i);
|
||||
memcpy(buffer, &be, 4);
|
||||
memcpy(buffer + 4, salt, WPS_KDF_SALT_LEN);
|
||||
|
20
src/utils.h
20
src/utils.h
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user