1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/esp32: rename SDK crypto function

Renames crypto functions of ESP32 SDK in vendor code to resolve the conflicts between `wpa-supplicant` crypto functions and RIOT's `crypto` and `hashes` modules.
This commit is contained in:
Gunar Schorcht 2019-08-11 16:19:46 +02:00
parent f8c740c190
commit d8f0399eaa
21 changed files with 205 additions and 204 deletions

View File

@ -4,7 +4,8 @@ include $(RIOTBASE)/Makefile.base
# we have to do it in that way to avoid that $(RIOTBASE)/sys/include/crypto
# is found first
INCLUDES = -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/wpa_supplicant/port/include
INCLUDES = -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/wpa_supplicant/include
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/wpa_supplicant/port/include
INCLUDES += -I$(ESP32_SDK_DIR)/components/wpa_supplicant/include
INCLUDES += -I$(ESP32_SDK_DIR)/components/wpa_supplicant/port/include
CFLAGS += -D__ets__ -DESPRESSIF_USE -DESP32_IDF_CODE=1

View File

@ -28,14 +28,14 @@
* Returns: 0 on success, -1 on failure
*/
int
aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
wpa_aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
{
void *ctx;
u8 cbc[AES_BLOCK_SIZE];
u8 *pos = data;
int i, j, blocks;
ctx = aes_encrypt_init(key, 16);
ctx = wpa_aes_encrypt_init(key, 16);
if (ctx == NULL)
return -1;
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
@ -44,11 +44,11 @@ aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
for (i = 0; i < blocks; i++) {
for (j = 0; j < AES_BLOCK_SIZE; j++)
cbc[j] ^= pos[j];
aes_encrypt(ctx, cbc, cbc);
wpa_aes_encrypt(ctx, cbc, cbc);
os_memcpy(pos, cbc, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_encrypt_deinit(ctx);
wpa_aes_encrypt_deinit(ctx);
return 0;
}
@ -62,14 +62,14 @@ aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
* Returns: 0 on success, -1 on failure
*/
int
aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
wpa_aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
{
void *ctx;
u8 cbc[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE];
u8 *pos = data;
int i, j, blocks;
ctx = aes_decrypt_init(key, 16);
ctx = wpa_aes_decrypt_init(key, 16);
if (ctx == NULL)
return -1;
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
@ -77,12 +77,12 @@ aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
os_memcpy(tmp, pos, AES_BLOCK_SIZE);
aes_decrypt(ctx, pos, pos);
wpa_aes_decrypt(ctx, pos, pos);
for (j = 0; j < AES_BLOCK_SIZE; j++)
pos[j] ^= cbc[j];
os_memcpy(cbc, tmp, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_decrypt_deinit(ctx);
wpa_aes_decrypt_deinit(ctx);
return 0;
}

View File

@ -36,13 +36,13 @@
*
* @return the number of rounds for the given cipher key size.
*/
static int rijndaelKeySetupDec(u32 rk[], const u8 cipherKey[], int keyBits)
static int wpa_rijndaelKeySetupDec(u32 rk[], const u8 cipherKey[], int keyBits)
{
int Nr, i, j;
u32 temp;
/* expand the cipher key: */
Nr = rijndaelKeySetupEnc(rk, cipherKey, keyBits);
Nr = wpa_rijndaelKeySetupEnc(rk, cipherKey, keyBits);
if (Nr < 0)
return Nr;
/* invert the order of the round keys: */
@ -67,14 +67,14 @@ static int rijndaelKeySetupDec(u32 rk[], const u8 cipherKey[], int keyBits)
return Nr;
}
void * aes_decrypt_init(const u8 *key, size_t len)
void * wpa_aes_decrypt_init(const u8 *key, size_t len)
{
u32 *rk;
int res;
rk = os_malloc(AES_PRIV_SIZE);
if (rk == NULL)
return NULL;
res = rijndaelKeySetupDec(rk, key, len * 8);
res = wpa_rijndaelKeySetupDec(rk, key, len * 8);
if (res < 0) {
os_free(rk);
return NULL;
@ -83,7 +83,7 @@ void * aes_decrypt_init(const u8 *key, size_t len)
return rk;
}
static void rijndaelDecrypt(const u32 rk[/*44*/], int Nr, const u8 ct[16],
static void wpa_rijndaelDecrypt(const u32 rk[/*44*/], int Nr, const u8 ct[16],
u8 pt[16])
{
u32 s0, s1, s2, s3, t0, t1, t2, t3;
@ -158,14 +158,14 @@ d##3 = TD0(s##3) ^ TD1(s##2) ^ TD2(s##1) ^ TD3(s##0) ^ rk[4 * i + 3]
PUTU32(pt + 12, s3);
}
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
void wpa_aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
{
u32 *rk = ctx;
rijndaelDecrypt(ctx, rk[AES_PRIV_NR_POS], crypt, plain);
wpa_rijndaelDecrypt(ctx, rk[AES_PRIV_NR_POS], crypt, plain);
}
void aes_decrypt_deinit(void *ctx)
void wpa_aes_decrypt_deinit(void *ctx)
{
os_memset(ctx, 0, AES_PRIV_SIZE);
os_free(ctx);

View File

@ -28,7 +28,7 @@
#include "os.h"
void rijndaelEncrypt(const u32 rk[], int Nr, const u8 pt[16], u8 ct[16])
void wpa_rijndaelEncrypt(const u32 rk[], int Nr, const u8 pt[16], u8 ct[16])
{
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
@ -103,14 +103,14 @@ d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[4 * i + 3]
}
void * aes_encrypt_init(const u8 *key, size_t len)
void * wpa_aes_encrypt_init(const u8 *key, size_t len)
{
u32 *rk;
int res;
rk = os_malloc(AES_PRIV_SIZE);
if (rk == NULL)
return NULL;
res = rijndaelKeySetupEnc(rk, key, len * 8);
res = wpa_rijndaelKeySetupEnc(rk, key, len * 8);
if (res < 0) {
os_free(rk);
return NULL;
@ -120,14 +120,14 @@ void * aes_encrypt_init(const u8 *key, size_t len)
}
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
void wpa_aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
{
u32 *rk = ctx;
rijndaelEncrypt(ctx, rk[AES_PRIV_NR_POS], plain, crypt);
wpa_rijndaelEncrypt(ctx, rk[AES_PRIV_NR_POS], plain, crypt);
}
void aes_encrypt_deinit(void *ctx)
void wpa_aes_encrypt_deinit(void *ctx)
{
os_memset(ctx, 0, AES_PRIV_SIZE);
os_free(ctx);

View File

@ -785,7 +785,7 @@ const u8 rcons[] /* ICACHE_RODATA_ATTR */ = {
*
* @return the number of rounds for the given cipher key size.
*/
int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits)
int wpa_rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits)
{
int i;
u32 temp;

View File

@ -29,7 +29,7 @@
* Returns: 0 on success, -1 on failure (e.g., integrity verification failed)
*/
int
aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
wpa_aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
{
u8 a[8], *r, b[16];
int i, j;
@ -40,7 +40,7 @@ aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
r = plain;
os_memcpy(r, cipher + 8, 8 * n);
ctx = aes_decrypt_init(kek, 16);
ctx = wpa_aes_decrypt_init(kek, 16);
if (ctx == NULL)
return -1;
@ -58,13 +58,13 @@ aes_unwrap(const u8 *kek, int n, const u8 *cipher, u8 *plain)
b[7] ^= n * j + i;
os_memcpy(b + 8, r, 8);
aes_decrypt(ctx, b, b);
wpa_aes_decrypt(ctx, b, b);
os_memcpy(a, b, 8);
os_memcpy(r, b + 8, 8);
r -= 8;
}
}
aes_decrypt_deinit(ctx);
wpa_aes_decrypt_deinit(ctx);
/* 3) Output results.
*

View File

@ -22,7 +22,7 @@
* @cipher: Wrapped key, (n + 1) * 64 bits
* Returns: 0 on success, -1 on failure
*/
int aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
int wpa_aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
{
u8 *a, *r, b[16];
int i, j;
@ -35,7 +35,7 @@ int aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
os_memset(a, 0xa6, 8);
os_memcpy(r, plain, 8 * n);
ctx = aes_encrypt_init(kek, 16);
ctx = wpa_aes_encrypt_init(kek, 16);
if (ctx == NULL)
return -1;
@ -51,14 +51,14 @@ int aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
for (i = 1; i <= n; i++) {
os_memcpy(b, a, 8);
os_memcpy(b + 8, r, 8);
aes_encrypt(ctx, b, b);
wpa_aes_encrypt(ctx, b, b);
os_memcpy(a, b, 8);
a[7] ^= n * j + i;
os_memcpy(r, b + 8, 8);
r += 8;
}
}
aes_encrypt_deinit(ctx);
wpa_aes_encrypt_deinit(ctx);
/* 3) Output the results.
*

View File

@ -73,14 +73,14 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
os_memcpy(ctx->u.rc4.key, key, key_len);
break;
case CRYPTO_CIPHER_ALG_AES:
ctx->u.aes.ctx_enc = aes_encrypt_init(key, key_len);
ctx->u.aes.ctx_enc = wpa_aes_encrypt_init(key, key_len);
if (ctx->u.aes.ctx_enc == NULL) {
os_free(ctx);
return NULL;
}
ctx->u.aes.ctx_dec = aes_decrypt_init(key, key_len);
ctx->u.aes.ctx_dec = wpa_aes_decrypt_init(key, key_len);
if (ctx->u.aes.ctx_dec == NULL) {
aes_encrypt_deinit(ctx->u.aes.ctx_enc);
wpa_aes_encrypt_deinit(ctx->u.aes.ctx_enc);
os_free(ctx);
return NULL;
}
@ -92,7 +92,7 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
os_free(ctx);
return NULL;
}
des3_key_setup(key, &ctx->u.des3.key);
wpa_des3_key_setup(key, &ctx->u.des3.key);
os_memcpy(ctx->u.des3.cbc, iv, 8);
break;
#endif
@ -102,7 +102,7 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
os_free(ctx);
return NULL;
}
des_key_setup(key, ctx->u.des.ek, ctx->u.des.dk);
wpa_des_key_setup(key, ctx->u.des.ek, ctx->u.des.dk);
os_memcpy(ctx->u.des.cbc, iv, 8);
break;
#endif
@ -124,7 +124,7 @@ int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
case CRYPTO_CIPHER_ALG_RC4:
if (plain != crypt)
os_memcpy(crypt, plain, len);
rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
wpa_rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
ctx->u.rc4.used_bytes, crypt, len);
ctx->u.rc4.used_bytes += len;
break;
@ -135,7 +135,7 @@ int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
for (i = 0; i < blocks; i++) {
for (j = 0; j < AES_BLOCK_SIZE; j++)
ctx->u.aes.cbc[j] ^= plain[j];
aes_encrypt(ctx->u.aes.ctx_enc, ctx->u.aes.cbc,
wpa_aes_encrypt(ctx->u.aes.ctx_enc, ctx->u.aes.cbc,
ctx->u.aes.cbc);
os_memcpy(crypt, ctx->u.aes.cbc, AES_BLOCK_SIZE);
plain += AES_BLOCK_SIZE;
@ -150,7 +150,7 @@ int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
for (i = 0; i < blocks; i++) {
for (j = 0; j < 8; j++)
ctx->u.des3.cbc[j] ^= plain[j];
des3_encrypt(ctx->u.des3.cbc, &ctx->u.des3.key,
wpa_des3_encrypt(ctx->u.des3.cbc, &ctx->u.des3.key,
ctx->u.des3.cbc);
os_memcpy(crypt, ctx->u.des3.cbc, 8);
plain += 8;
@ -166,7 +166,7 @@ int crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain,
for (i = 0; i < blocks; i++) {
for (j = 0; j < 8; j++)
ctx->u.des3.cbc[j] ^= plain[j];
des_block_encrypt(ctx->u.des.cbc, ctx->u.des.ek,
wpa_des_block_encrypt(ctx->u.des.cbc, ctx->u.des.ek,
ctx->u.des.cbc);
os_memcpy(crypt, ctx->u.des.cbc, 8);
plain += 8;
@ -192,7 +192,7 @@ int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
case CRYPTO_CIPHER_ALG_RC4:
if (plain != crypt)
os_memcpy(plain, crypt, len);
rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
wpa_rc4_skip(ctx->u.rc4.key, ctx->u.rc4.keylen,
ctx->u.rc4.used_bytes, plain, len);
ctx->u.rc4.used_bytes += len;
break;
@ -202,7 +202,7 @@ int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
blocks = len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
os_memcpy(tmp, crypt, AES_BLOCK_SIZE);
aes_decrypt(ctx->u.aes.ctx_dec, crypt, plain);
wpa_aes_decrypt(ctx->u.aes.ctx_dec, crypt, plain);
for (j = 0; j < AES_BLOCK_SIZE; j++)
plain[j] ^= ctx->u.aes.cbc[j];
os_memcpy(ctx->u.aes.cbc, tmp, AES_BLOCK_SIZE);
@ -217,7 +217,7 @@ int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
blocks = len / 8;
for (i = 0; i < blocks; i++) {
os_memcpy(tmp, crypt, 8);
des3_decrypt(crypt, &ctx->u.des3.key, plain);
wpa_des3_decrypt(crypt, &ctx->u.des3.key, plain);
for (j = 0; j < 8; j++)
plain[j] ^= ctx->u.des3.cbc[j];
os_memcpy(ctx->u.des3.cbc, tmp, 8);
@ -233,7 +233,7 @@ int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
blocks = len / 8;
for (i = 0; i < blocks; i++) {
os_memcpy(tmp, crypt, 8);
des_block_decrypt(crypt, ctx->u.des.dk, plain);
wpa_des_block_decrypt(crypt, ctx->u.des.dk, plain);
for (j = 0; j < 8; j++)
plain[j] ^= ctx->u.des.cbc[j];
os_memcpy(ctx->u.des.cbc, tmp, 8);
@ -254,8 +254,8 @@ void crypto_cipher_deinit(struct crypto_cipher *ctx)
{
switch (ctx->alg) {
case CRYPTO_CIPHER_ALG_AES:
aes_encrypt_deinit(ctx->u.aes.ctx_enc);
aes_decrypt_deinit(ctx->u.aes.ctx_dec);
wpa_aes_encrypt_deinit(ctx->u.aes.ctx_enc);
wpa_aes_decrypt_deinit(ctx->u.aes.ctx_dec);
break;
#ifdef CONFIG_DES3
case CRYPTO_CIPHER_ALG_3DES:

View File

@ -49,21 +49,21 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
switch (alg) {
case CRYPTO_HASH_ALG_MD5:
MD5Init(&ctx->u.md5);
wpa_MD5Init(&ctx->u.md5);
break;
case CRYPTO_HASH_ALG_SHA1:
SHA1Init(&ctx->u.sha1);
wpa_SHA1Init(&ctx->u.sha1);
break;
#ifdef CONFIG_SHA256
case CRYPTO_HASH_ALG_SHA256:
sha256_init(&ctx->u.sha256);
wpa_sha256_init(&ctx->u.sha256);
break;
#endif /* CONFIG_SHA256 */
case CRYPTO_HASH_ALG_HMAC_MD5:
if (key_len > sizeof(k_pad)) {
MD5Init(&ctx->u.md5);
MD5Update(&ctx->u.md5, key, key_len);
MD5Final(tk, &ctx->u.md5);
wpa_MD5Init(&ctx->u.md5);
wpa_MD5Update(&ctx->u.md5, key, key_len);
wpa_MD5Final(tk, &ctx->u.md5);
key = tk;
key_len = 16;
}
@ -75,14 +75,14 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
os_memset(k_pad + key_len, 0, sizeof(k_pad) - key_len);
for (i = 0; i < sizeof(k_pad); i++)
k_pad[i] ^= 0x36;
MD5Init(&ctx->u.md5);
MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad));
wpa_MD5Init(&ctx->u.md5);
wpa_MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad));
break;
case CRYPTO_HASH_ALG_HMAC_SHA1:
if (key_len > sizeof(k_pad)) {
SHA1Init(&ctx->u.sha1);
SHA1Update(&ctx->u.sha1, key, key_len);
SHA1Final(tk, &ctx->u.sha1);
wpa_SHA1Init(&ctx->u.sha1);
wpa_SHA1Update(&ctx->u.sha1, key, key_len);
wpa_SHA1Final(tk, &ctx->u.sha1);
key = tk;
key_len = 20;
}
@ -94,15 +94,15 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
os_memset(k_pad + key_len, 0, sizeof(k_pad) - key_len);
for (i = 0; i < sizeof(k_pad); i++)
k_pad[i] ^= 0x36;
SHA1Init(&ctx->u.sha1);
SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad));
wpa_SHA1Init(&ctx->u.sha1);
wpa_SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad));
break;
#ifdef CONFIG_SHA256
case CRYPTO_HASH_ALG_HMAC_SHA256:
if (key_len > sizeof(k_pad)) {
sha256_init(&ctx->u.sha256);
sha256_process(&ctx->u.sha256, key, key_len);
sha256_done(&ctx->u.sha256, tk);
wpa_sha256_init(&ctx->u.sha256);
wpa_sha256_process(&ctx->u.sha256, key, key_len);
wpa_sha256_done(&ctx->u.sha256, tk);
key = tk;
key_len = 32;
}
@ -114,8 +114,8 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
os_memset(k_pad + key_len, 0, sizeof(k_pad) - key_len);
for (i = 0; i < sizeof(k_pad); i++)
k_pad[i] ^= 0x36;
sha256_init(&ctx->u.sha256);
sha256_process(&ctx->u.sha256, k_pad, sizeof(k_pad));
wpa_sha256_init(&ctx->u.sha256);
wpa_sha256_process(&ctx->u.sha256, k_pad, sizeof(k_pad));
break;
#endif /* CONFIG_SHA256 */
default:
@ -135,16 +135,16 @@ void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len)
switch (ctx->alg) {
case CRYPTO_HASH_ALG_MD5:
case CRYPTO_HASH_ALG_HMAC_MD5:
MD5Update(&ctx->u.md5, data, len);
wpa_MD5Update(&ctx->u.md5, data, len);
break;
case CRYPTO_HASH_ALG_SHA1:
case CRYPTO_HASH_ALG_HMAC_SHA1:
SHA1Update(&ctx->u.sha1, data, len);
wpa_SHA1Update(&ctx->u.sha1, data, len);
break;
#ifdef CONFIG_SHA256
case CRYPTO_HASH_ALG_SHA256:
case CRYPTO_HASH_ALG_HMAC_SHA256:
sha256_process(&ctx->u.sha256, data, len);
wpa_sha256_process(&ctx->u.sha256, data, len);
break;
#endif /* CONFIG_SHA256 */
default:
@ -174,7 +174,7 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
return -1;
}
*len = 16;
MD5Final(mac, &ctx->u.md5);
wpa_MD5Final(mac, &ctx->u.md5);
break;
case CRYPTO_HASH_ALG_SHA1:
if (*len < 20) {
@ -183,7 +183,7 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
return -1;
}
*len = 20;
SHA1Final(mac, &ctx->u.sha1);
wpa_SHA1Final(mac, &ctx->u.sha1);
break;
#ifdef CONFIG_SHA256
case CRYPTO_HASH_ALG_SHA256:
@ -193,7 +193,7 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
return -1;
}
*len = 32;
sha256_done(&ctx->u.sha256, mac);
wpa_sha256_done(&ctx->u.sha256, mac);
break;
#endif /* CONFIG_SHA256 */
case CRYPTO_HASH_ALG_HMAC_MD5:
@ -204,17 +204,17 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
}
*len = 16;
MD5Final(mac, &ctx->u.md5);
wpa_MD5Final(mac, &ctx->u.md5);
os_memcpy(k_pad, ctx->key, ctx->key_len);
os_memset(k_pad + ctx->key_len, 0,
sizeof(k_pad) - ctx->key_len);
for (i = 0; i < sizeof(k_pad); i++)
k_pad[i] ^= 0x5c;
MD5Init(&ctx->u.md5);
MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad));
MD5Update(&ctx->u.md5, mac, 16);
MD5Final(mac, &ctx->u.md5);
wpa_MD5Init(&ctx->u.md5);
wpa_MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad));
wpa_MD5Update(&ctx->u.md5, mac, 16);
wpa_MD5Final(mac, &ctx->u.md5);
break;
case CRYPTO_HASH_ALG_HMAC_SHA1:
if (*len < 20) {
@ -224,17 +224,17 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
}
*len = 20;
SHA1Final(mac, &ctx->u.sha1);
wpa_SHA1Final(mac, &ctx->u.sha1);
os_memcpy(k_pad, ctx->key, ctx->key_len);
os_memset(k_pad + ctx->key_len, 0,
sizeof(k_pad) - ctx->key_len);
for (i = 0; i < sizeof(k_pad); i++)
k_pad[i] ^= 0x5c;
SHA1Init(&ctx->u.sha1);
SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad));
SHA1Update(&ctx->u.sha1, mac, 20);
SHA1Final(mac, &ctx->u.sha1);
wpa_SHA1Init(&ctx->u.sha1);
wpa_SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad));
wpa_SHA1Update(&ctx->u.sha1, mac, 20);
wpa_SHA1Final(mac, &ctx->u.sha1);
break;
#ifdef CONFIG_SHA256
case CRYPTO_HASH_ALG_HMAC_SHA256:
@ -245,17 +245,17 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
}
*len = 32;
sha256_done(&ctx->u.sha256, mac);
wpa_sha256_done(&ctx->u.sha256, mac);
os_memcpy(k_pad, ctx->key, ctx->key_len);
os_memset(k_pad + ctx->key_len, 0,
sizeof(k_pad) - ctx->key_len);
for (i = 0; i < sizeof(k_pad); i++)
k_pad[i] ^= 0x5c;
sha256_init(&ctx->u.sha256);
sha256_process(&ctx->u.sha256, k_pad, sizeof(k_pad));
sha256_process(&ctx->u.sha256, mac, 32);
sha256_done(&ctx->u.sha256, mac);
wpa_sha256_init(&ctx->u.sha256);
wpa_sha256_process(&ctx->u.sha256, k_pad, sizeof(k_pad));
wpa_sha256_process(&ctx->u.sha256, mac, 32);
wpa_sha256_done(&ctx->u.sha256, mac);
break;
#endif /* CONFIG_SHA256 */
default:

View File

@ -396,7 +396,7 @@ static void desfunc(u32 *block, const u32 *keys)
/* wpa_supplicant/hostapd specific wrapper */
void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
void wpa_des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
{
u8 pkey[8], next, tmp;
int i;
@ -424,14 +424,14 @@ void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
}
/*
void des_key_setup(const u8 *key, u32 *ek, u32 *dk)
void wpa_des_key_setup(const u8 *key, u32 *ek, u32 *dk)
{
deskey(key, 0, ek);
deskey(key, 1, dk);
}
void des_block_encrypt(const u8 *plain, const u32 *ek, u8 *crypt)
void wpa_des_block_encrypt(const u8 *plain, const u32 *ek, u8 *crypt)
{
u32 work[2];
work[0] = WPA_GET_BE32(plain);
@ -442,7 +442,7 @@ void des_block_encrypt(const u8 *plain, const u32 *ek, u8 *crypt)
}
void des_block_decrypt(const u8 *crypt, const u32 *dk, u8 *plain)
void wpa_des_block_decrypt(const u8 *crypt, const u32 *dk, u8 *plain)
{
u32 work[2];
work[0] = WPA_GET_BE32(crypt);
@ -453,7 +453,7 @@ void des_block_decrypt(const u8 *crypt, const u32 *dk, u8 *plain)
}
void des3_key_setup(const u8 *key, struct des3_key_s *dkey)
void wpa_des3_key_setup(const u8 *key, struct des3_key_s *dkey)
{
deskey(key, 0, dkey->ek[0]);
deskey(key + 8, 1, dkey->ek[1]);
@ -465,7 +465,7 @@ void des3_key_setup(const u8 *key, struct des3_key_s *dkey)
}
void des3_encrypt(const u8 *plain, const struct des3_key_s *key, u8 *crypt)
void wpa_des3_encrypt(const u8 *plain, const struct des3_key_s *key, u8 *crypt)
{
u32 work[2];
@ -479,7 +479,7 @@ void des3_encrypt(const u8 *plain, const struct des3_key_s *key, u8 *crypt)
}
void des3_decrypt(const u8 *crypt, const struct des3_key_s *key, u8 *plain)
void wpa_des3_decrypt(const u8 *crypt, const struct des3_key_s *key, u8 *plain)
{
u32 work[2];

View File

@ -20,9 +20,9 @@
void *
dh5_init(struct wpabuf **priv, struct wpabuf **publ)
wpa_dh5_init(struct wpabuf **priv, struct wpabuf **publ)
{
*publ = dh_init(dh_groups_get(5), priv);
*publ = wpa_dh_init(wpa_dh_groups_get(5), priv);
if (*publ == 0)
return NULL;
return (void *) 1;
@ -30,14 +30,14 @@ dh5_init(struct wpabuf **priv, struct wpabuf **publ)
struct wpabuf *
dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
wpa_dh5_derive_shared(void *ctx, const struct wpabuf *peer_public,
const struct wpabuf *own_private)
{
return dh_derive_shared(peer_public, own_private, dh_groups_get(5));
return wpa_dh_derive_shared(peer_public, own_private, wpa_dh_groups_get(5));
}
void
dh5_free(void *ctx)
wpa_dh5_free(void *ctx)
{
}

View File

@ -17,25 +17,25 @@ typedef struct MD4Context {
u8 buffer[MD4_BLOCK_LENGTH];
} MD4_CTX;
static void MD4Init(MD4_CTX *ctx);
static void MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len);
static void MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx);
static void wpa_MD4Init(MD4_CTX *ctx);
static void wpa_MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len);
static void wpa_MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx);
int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
int wpa_md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
MD4_CTX ctx;
size_t i;
MD4Init(&ctx);
wpa_MD4Init(&ctx);
for (i = 0; i < num_elem; i++)
MD4Update(&ctx, addr[i], len[i]);
MD4Final(mac, &ctx);
wpa_MD4Update(&ctx, addr[i], len[i]);
wpa_MD4Final(mac, &ctx);
return 0;
}
#define MD4_DIGEST_STRING_LENGTH (MD4_DIGEST_LENGTH * 2 + 1)
static void MD4Transform(u32 state[4], const u8 block[MD4_BLOCK_LENGTH]);
static void wpa_MD4Transform(u32 state[4], const u8 block[MD4_BLOCK_LENGTH]);
#define PUT_64BIT_LE(cp, value) do { \
(cp)[7] = (value) >> 56; \
@ -60,7 +60,7 @@ static u8 PADDING[MD4_BLOCK_LENGTH] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static void MD4Init(MD4_CTX *ctx)
static void wpa_MD4Init(MD4_CTX *ctx)
{
ctx->count = 0;
ctx->state[0] = 0x67452301;
@ -69,7 +69,7 @@ static void MD4Init(MD4_CTX *ctx)
ctx->state[3] = 0x10325476;
}
static void MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len)
static void wpa_MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len)
{
size_t have, need;
@ -81,14 +81,14 @@ static void MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len)
if (len >= need) {
if (have != 0) {
os_memcpy(ctx->buffer + have, input, need);
MD4Transform(ctx->state, ctx->buffer);
wpa_MD4Transform(ctx->state, ctx->buffer);
input += need;
len -= need;
have = 0;
}
while (len >= MD4_BLOCK_LENGTH) {
MD4Transform(ctx->state, input);
wpa_MD4Transform(ctx->state, input);
input += MD4_BLOCK_LENGTH;
len -= MD4_BLOCK_LENGTH;
}
@ -98,7 +98,7 @@ static void MD4Update(MD4_CTX *ctx, const unsigned char *input, size_t len)
os_memcpy(ctx->buffer + have, input, len);
}
static void MD4Pad(MD4_CTX *ctx)
static void wpa_MD4Pad(MD4_CTX *ctx)
{
u8 count[8];
size_t padlen;
@ -109,15 +109,15 @@ static void MD4Pad(MD4_CTX *ctx)
((ctx->count >> 3) & (MD4_BLOCK_LENGTH - 1));
if (padlen < 1 + 8)
padlen += MD4_BLOCK_LENGTH;
MD4Update(ctx, PADDING, padlen - 8);
MD4Update(ctx, count, 8);
wpa_MD4Update(ctx, PADDING, padlen - 8);
wpa_MD4Update(ctx, count, 8);
}
static void MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx)
static void wpa_MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx)
{
int i;
MD4Pad(ctx);
wpa_MD4Pad(ctx);
if (digest != NULL) {
for (i = 0; i < 4; i ++)
PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
@ -132,7 +132,7 @@ static void MD4Final(unsigned char digest[MD4_DIGEST_LENGTH], MD4_CTX *ctx)
#define MD4SETP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s) )
static void MD4Transform(u32 state[4], const u8 block[MD4_BLOCK_LENGTH])
static void wpa_MD4Transform(u32 state[4], const u8 block[MD4_BLOCK_LENGTH])
{
u32 a, b, c, d, in[MD4_BLOCK_LENGTH / 4];

View File

@ -20,7 +20,7 @@
#include "crypto/crypto.h"
static void MD5Transform(u32 buf[4], u32 const in[16]);
static void wpa_MD5Transform(u32 buf[4], u32 const in[16]);
typedef struct MD5Context MD5_CTX;
@ -35,15 +35,15 @@ typedef struct MD5Context MD5_CTX;
* Returns: 0 on success, -1 of failure
*/
int
md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
wpa_md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
MD5_CTX ctx;
size_t i;
MD5Init(&ctx);
wpa_MD5Init(&ctx);
for (i = 0; i < num_elem; i++)
MD5Update(&ctx, addr[i], len[i]);
MD5Final(mac, &ctx);
wpa_MD5Update(&ctx, addr[i], len[i]);
wpa_MD5Final(mac, &ctx);
return 0;
}
@ -89,7 +89,7 @@ static void byteReverse(unsigned char *buf, unsigned longs)
* initialization constants.
*/
void
MD5Init(struct MD5Context *ctx)
wpa_MD5Init(struct MD5Context *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
@ -105,7 +105,7 @@ MD5Init(struct MD5Context *ctx)
* of bytes.
*/
void
MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
wpa_MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
u32 t;
@ -130,7 +130,7 @@ MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
}
os_memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (u32 *) ctx->in);
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
buf += t;
len -= t;
}
@ -139,7 +139,7 @@ MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
while (len >= 64) {
os_memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (u32 *) ctx->in);
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
buf += 64;
len -= 64;
}
@ -154,7 +154,7 @@ MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void
MD5Final(unsigned char digest[16], struct MD5Context *ctx)
wpa_MD5Final(unsigned char digest[16], struct MD5Context *ctx)
{
unsigned count;
unsigned char *p;
@ -175,7 +175,7 @@ MD5Final(unsigned char digest[16], struct MD5Context *ctx)
/* Two lots of padding: Pad the first block to 64 bytes */
os_memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (u32 *) ctx->in);
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
/* Now fill the next block with 56 bytes */
os_memset(ctx->in, 0, 56);
@ -189,7 +189,7 @@ MD5Final(unsigned char digest[16], struct MD5Context *ctx)
((u32 *) ctx->in)[14] = ctx->bits[0];
((u32 *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (u32 *) ctx->in);
wpa_MD5Transform(ctx->buf, (u32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
os_memcpy(digest, ctx->buf, 16);
os_memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
@ -213,7 +213,7 @@ MD5Final(unsigned char digest[16], struct MD5Context *ctx)
* the data and converts bytes into longwords for this routine.
*/
static void
MD5Transform(u32 buf[4], u32 const in[16])
wpa_MD5Transform(u32 buf[4], u32 const in[16])
{
register u32 a, b, c, d;

View File

@ -30,7 +30,7 @@
* Returns: 0 on success, -1 on failure
*/
int
hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
wpa_hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
const u8 *addr[], const size_t *len, u8 *mac)
{
u8 k_pad[64]; /* padding - key XORd with ipad/opad */
@ -48,7 +48,7 @@ hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
/* if key is longer than 64 bytes reset it to key = MD5(key) */
if (key_len > 64) {
if (md5_vector(1, &key, &key_len, tk))
if (wpa_md5_vector(1, &key, &key_len, tk))
return -1;
key = tk;
key_len = 16;
@ -78,7 +78,7 @@ hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
_addr[i + 1] = addr[i];
_len[i + 1] = len[i];
}
if (md5_vector(1 + num_elem, _addr, _len, mac))
if (wpa_md5_vector(1 + num_elem, _addr, _len, mac))
return -1;
os_memset(k_pad, 0, sizeof(k_pad));
@ -92,7 +92,7 @@ hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
_len[0] = 64;
_addr[1] = mac;
_len[1] = MD5_MAC_LEN;
return md5_vector(2, _addr, _len, mac);
return wpa_md5_vector(2, _addr, _len, mac);
}
@ -106,8 +106,8 @@ hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
* Returns: 0 on success, -1 on failure
*/
int
hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
wpa_hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
u8 *mac)
{
return hmac_md5_vector(key, key_len, 1, &data, &data_len, mac);
return wpa_hmac_md5_vector(key, key_len, 1, &data, &data_len, mac);
}

View File

@ -93,7 +93,7 @@ static int challenge_hash(const u8 *peer_challenge, const u8 *auth_challenge,
addr[2] = username;
len[2] = username_len;
if (sha1_vector(3, addr, len, hash))
if (wpa_sha1_vector(3, addr, len, hash))
return -1;
os_memcpy(challenge, hash, 8);
return 0;
@ -119,7 +119,7 @@ int nt_password_hash(const u8 *password, size_t password_len,
len *= 2;
pos = buf;
return md4_vector(1, (const u8 **) &pos, &len, password_hash);
return wpa_md4_vector(1, (const u8 **) &pos, &len, password_hash);
}
@ -132,7 +132,7 @@ int nt_password_hash(const u8 *password, size_t password_len,
int hash_nt_password_hash(const u8 *password_hash, u8 *password_hash_hash)
{
size_t len = 16;
return md4_vector(1, &password_hash, &len, password_hash_hash);
return wpa_md4_vector(1, &password_hash, &len, password_hash_hash);
}
@ -146,12 +146,12 @@ void challenge_response(const u8 *challenge, const u8 *password_hash,
u8 *response)
{
u8 zpwd[7];
des_encrypt(challenge, password_hash, response);
des_encrypt(challenge, password_hash + 7, response + 8);
wpa_des_encrypt(challenge, password_hash, response);
wpa_des_encrypt(challenge, password_hash + 7, response + 8);
zpwd[0] = password_hash[14];
zpwd[1] = password_hash[15];
os_memset(zpwd + 2, 0, 5);
des_encrypt(challenge, zpwd, response + 16);
wpa_des_encrypt(challenge, zpwd, response + 16);
}
@ -259,13 +259,13 @@ int generate_authenticator_response_pwhash(
if (hash_nt_password_hash(password_hash, password_hash_hash))
return -1;
if (sha1_vector(3, addr1, len1, response))
if (wpa_sha1_vector(3, addr1, len1, response))
return -1;
if (challenge_hash(peer_challenge, auth_challenge, username,
username_len, challenge))
return -1;
return sha1_vector(3, addr2, len2, response);
return wpa_sha1_vector(3, addr2, len2, response);
}
@ -339,7 +339,7 @@ int get_master_key(const u8 *password_hash_hash, const u8 *nt_response,
addr[1] = nt_response;
addr[2] = magic1;
if (sha1_vector(3, addr, len, hash))
if (wpa_sha1_vector(3, addr, len, hash))
return -1;
os_memcpy(master_key, hash, 16);
return 0;
@ -407,7 +407,7 @@ int get_asymetric_start_key(const u8 *master_key, u8 *session_key,
}
addr[3] = shs_pad2;
if (sha1_vector(4, addr, len, digest))
if (wpa_sha1_vector(4, addr, len, digest))
return -1;
if (session_key_len > SHA1_MAC_LEN)
@ -454,7 +454,7 @@ int encrypt_pw_block_with_password_hash(
*/
pos = &pw_block[2 * 256];
WPA_PUT_LE16(pos, password_len * 2);
rc4_skip(password_hash, 16, 0, pw_block, PWBLOCK_LEN);
wpa_rc4_skip(password_hash, 16, 0, pw_block, PWBLOCK_LEN);
return 0;
}
@ -494,8 +494,8 @@ int new_password_encrypted_with_old_nt_password_hash(
void nt_password_hash_encrypted_with_block(const u8 *password_hash,
const u8 *block, u8 *cypher)
{
des_encrypt(password_hash, block, cypher);
des_encrypt(password_hash + 8, block + 7, cypher + 8);
wpa_des_encrypt(password_hash, block, cypher);
wpa_des_encrypt(password_hash + 8, block + 7, cypher + 8);
}

View File

@ -20,7 +20,7 @@
#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
int
rc4_skip(const u8 *key, size_t keylen, size_t skip,
wpa_rc4_skip(const u8 *key, size_t keylen, size_t skip,
u8 *data, size_t data_len)
{
u32 i, j, k;

View File

@ -22,7 +22,7 @@
typedef struct SHA1Context SHA1_CTX;
void SHA1Transform(u32 state[5], const unsigned char buffer[64]);
void wpa_SHA1Transform(u32 state[5], const unsigned char buffer[64]);
/**
@ -34,15 +34,15 @@ void SHA1Transform(u32 state[5], const unsigned char buffer[64]);
* Returns: 0 on success, -1 of failure
*/
int
sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
wpa_sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
{
SHA1_CTX ctx;
size_t i;
SHA1Init(&ctx);
wpa_SHA1Init(&ctx);
for (i = 0; i < num_elem; i++)
SHA1Update(&ctx, addr[i], len[i]);
SHA1Final(mac, &ctx);
wpa_SHA1Update(&ctx, addr[i], len[i]);
wpa_SHA1Final(mac, &ctx);
return 0;
}
@ -160,7 +160,7 @@ A million repetitions of "a"
#ifdef VERBOSE /* SAK */
void SHAPrintContext(SHA1_CTX *context, char *msg)
void wpa_SHAPrintContext(SHA1_CTX *context, char *msg)
{
printf("%s (%d,%d) %x %x %x %x %x\n",
msg,
@ -176,7 +176,7 @@ void SHAPrintContext(SHA1_CTX *context, char *msg)
/* Hash a single 512-bit block. This is the core of the algorithm. */
void
SHA1Transform(u32 state[5], const unsigned char buffer[64])
wpa_SHA1Transform(u32 state[5], const unsigned char buffer[64])
{
u32 a, b, c, d, e;
typedef union {
@ -235,7 +235,7 @@ SHA1Transform(u32 state[5], const unsigned char buffer[64])
/* SHA1Init - Initialize new context */
void
SHA1Init(SHA1_CTX* context)
wpa_SHA1Init(SHA1_CTX* context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
@ -250,13 +250,13 @@ SHA1Init(SHA1_CTX* context)
/* Run your data through this. */
void
SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
wpa_SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
{
u32 i, j;
const unsigned char *data = _data;
#ifdef VERBOSE
SHAPrintContext(context, "before");
wpa_SHAPrintContext(context, "before");
#endif
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += len << 3) < (len << 3))
@ -264,16 +264,16 @@ SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
context->count[1] += (len >> 29);
if ((j + len) > 63) {
os_memcpy(&context->buffer[j], data, (i = 64-j));
SHA1Transform(context->state, context->buffer);
wpa_SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
SHA1Transform(context->state, &data[i]);
wpa_SHA1Transform(context->state, &data[i]);
}
j = 0;
}
else i = 0;
os_memcpy(&context->buffer[j], &data[i], len - i);
#ifdef VERBOSE
SHAPrintContext(context, "after ");
wpa_SHAPrintContext(context, "after ");
#endif
}
@ -281,7 +281,7 @@ SHA1Update(SHA1_CTX* context, const void *_data, u32 len)
/* Add padding and return the message digest. */
void
SHA1Final(unsigned char digest[20], SHA1_CTX* context)
wpa_SHA1Final(unsigned char digest[20], SHA1_CTX* context)
{
u32 i;
unsigned char finalcount[8];
@ -291,11 +291,11 @@ SHA1Final(unsigned char digest[20], SHA1_CTX* context)
((context->count[(i >= 4 ? 0 : 1)] >>
((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
SHA1Update(context, (unsigned char *) "\200", 1);
wpa_SHA1Update(context, (unsigned char *) "\200", 1);
while ((context->count[0] & 504) != 448) {
SHA1Update(context, (unsigned char *) "\0", 1);
wpa_SHA1Update(context, (unsigned char *) "\0", 1);
}
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform()
wpa_SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform()
*/
for (i = 0; i < 20; i++) {
digest[i] = (unsigned char)

View File

@ -19,7 +19,7 @@
#include "crypto/crypto.h"
static int
pbkdf2_sha1_f(const char *passphrase, const char *ssid,
wpa_pbkdf2_sha1_f(const char *passphrase, const char *ssid,
size_t ssid_len, int iterations, unsigned int count,
u8 *digest)
{
@ -45,13 +45,13 @@ pbkdf2_sha1_f(const char *passphrase, const char *ssid,
count_buf[1] = (count >> 16) & 0xff;
count_buf[2] = (count >> 8) & 0xff;
count_buf[3] = count & 0xff;
if (hmac_sha1_vector((u8 *) passphrase, passphrase_len, 2, addr, len,
if (wpa_hmac_sha1_vector((u8 *) passphrase, passphrase_len, 2, addr, len,
tmp))
return -1;
os_memcpy(digest, tmp, SHA1_MAC_LEN);
for (i = 1; i < iterations; i++) {
if (hmac_sha1((u8 *) passphrase, passphrase_len, tmp,
if (wpa_hmac_sha1((u8 *) passphrase, passphrase_len, tmp,
SHA1_MAC_LEN, tmp2))
return -1;
os_memcpy(tmp, tmp2, SHA1_MAC_LEN);
@ -78,7 +78,7 @@ pbkdf2_sha1_f(const char *passphrase, const char *ssid,
* IEEE Std 802.11-2004, Clause H.4. The main construction is from PKCS#5 v2.0.
*/
int
pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
wpa_pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
int iterations, u8 *buf, size_t buflen)
{
unsigned int count = 0;
@ -88,7 +88,7 @@ pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
while (left > 0) {
count++;
if (pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations,
if (wpa_pbkdf2_sha1_f(passphrase, ssid, ssid_len, iterations,
count, digest))
return -1;
plen = left > SHA1_MAC_LEN ? SHA1_MAC_LEN : left;

View File

@ -30,7 +30,7 @@
* Returns: 0 on success, -1 on failure
*/
int
hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
wpa_hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
const u8 *addr[], const size_t *len, u8 *mac)
{
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
@ -48,7 +48,7 @@ hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
/* if key is longer than 64 bytes reset it to key = SHA1(key) */
if (key_len > 64) {
if (sha1_vector(1, &key, &key_len, tk))
if (wpa_sha1_vector(1, &key, &key_len, tk))
return -1;
key = tk;
key_len = 20;
@ -77,7 +77,7 @@ hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
_addr[i + 1] = addr[i];
_len[i + 1] = len[i];
}
if (sha1_vector(1 + num_elem, _addr, _len, mac))
if (wpa_sha1_vector(1 + num_elem, _addr, _len, mac))
return -1;
os_memset(k_pad, 0, sizeof(k_pad));
@ -91,7 +91,7 @@ hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
_len[0] = 64;
_addr[1] = mac;
_len[1] = SHA1_MAC_LEN;
return sha1_vector(2, _addr, _len, mac);
return wpa_sha1_vector(2, _addr, _len, mac);
}
@ -105,10 +105,10 @@ hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
* Returns: 0 on success, -1 of failure
*/
int
hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
wpa_hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
u8 *mac)
{
return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
return wpa_hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
}
/**
@ -126,7 +126,7 @@ hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
* given key (e.g., PMK in IEEE 802.11i).
*/
int
sha1_prf(const u8 *key, size_t key_len, const char *label,
wpa_sha1_prf(const u8 *key, size_t key_len, const char *label,
const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
{
u8 counter = 0;
@ -147,12 +147,12 @@ sha1_prf(const u8 *key, size_t key_len, const char *label,
while (pos < buf_len) {
plen = buf_len - pos;
if (plen >= SHA1_MAC_LEN) {
if (hmac_sha1_vector(key, key_len, 3, addr, len,
if (wpa_hmac_sha1_vector(key, key_len, 3, addr, len,
&buf[pos]))
return -1;
pos += SHA1_MAC_LEN;
} else {
if (hmac_sha1_vector(key, key_len, 3, addr, len,
if (wpa_hmac_sha1_vector(key, key_len, 3, addr, len,
hash))
return -1;
os_memcpy(&buf[pos], hash, plen);

View File

@ -26,10 +26,10 @@ struct sha256_state {
u8 buf[SHA256_BLOCK_SIZE];
};
static void sha256_init(struct sha256_state *md);
static int sha256_process(struct sha256_state *md, const unsigned char *in,
static void wpa_sha256_init(struct sha256_state *md);
static int wpa_sha256_process(struct sha256_state *md, const unsigned char *in,
unsigned long inlen);
static int sha256_done(struct sha256_state *md, unsigned char *out);
static int wpa_sha256_done(struct sha256_state *md, unsigned char *out);
/**
@ -41,17 +41,17 @@ static int sha256_done(struct sha256_state *md, unsigned char *out);
* Returns: 0 on success, -1 of failure
*/
int
sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
wpa_sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
u8 *mac)
{
struct sha256_state ctx;
size_t i;
sha256_init(&ctx);
wpa_sha256_init(&ctx);
for (i = 0; i < num_elem; i++)
if (sha256_process(&ctx, addr[i], len[i]))
if (wpa_sha256_process(&ctx, addr[i], len[i]))
return -1;
if (sha256_done(&ctx, mac))
if (wpa_sha256_done(&ctx, mac))
return -1;
return 0;
}
@ -98,7 +98,7 @@ static const unsigned long K[64] = {
/* compress 512-bits */
static int
sha256_compress(struct sha256_state *md, unsigned char *buf)
wpa_sha256_compress(struct sha256_state *md, unsigned char *buf)
{
u32 S[8], W[64], t0, t1;
u32 t;
@ -142,7 +142,7 @@ sha256_compress(struct sha256_state *md, unsigned char *buf)
/* Initialize the hash state */
static void
sha256_init(struct sha256_state *md)
wpa_sha256_init(struct sha256_state *md)
{
md->curlen = 0;
md->length = 0;
@ -164,7 +164,7 @@ sha256_init(struct sha256_state *md)
@return CRYPT_OK if successful
*/
static int
sha256_process(struct sha256_state *md, const unsigned char *in,
wpa_sha256_process(struct sha256_state *md, const unsigned char *in,
unsigned long inlen)
{
unsigned long n;
@ -174,7 +174,7 @@ sha256_process(struct sha256_state *md, const unsigned char *in,
while (inlen > 0) {
if (md->curlen == 0 && inlen >= SHA256_BLOCK_SIZE) {
if (sha256_compress(md, (unsigned char *) in) < 0)
if (wpa_sha256_compress(md, (unsigned char *) in) < 0)
return -1;
md->length += SHA256_BLOCK_SIZE * 8;
in += SHA256_BLOCK_SIZE;
@ -186,7 +186,7 @@ sha256_process(struct sha256_state *md, const unsigned char *in,
in += n;
inlen -= n;
if (md->curlen == SHA256_BLOCK_SIZE) {
if (sha256_compress(md, md->buf) < 0)
if (wpa_sha256_compress(md, md->buf) < 0)
return -1;
md->length += 8 * SHA256_BLOCK_SIZE;
md->curlen = 0;
@ -205,7 +205,7 @@ sha256_process(struct sha256_state *md, const unsigned char *in,
@return CRYPT_OK if successful
*/
static int
sha256_done(struct sha256_state *md, unsigned char *out)
wpa_sha256_done(struct sha256_state *md, unsigned char *out)
{
int i;
@ -226,7 +226,7 @@ sha256_done(struct sha256_state *md, unsigned char *out)
while (md->curlen < SHA256_BLOCK_SIZE) {
md->buf[md->curlen++] = (unsigned char) 0;
}
sha256_compress(md, md->buf);
wpa_sha256_compress(md, md->buf);
md->curlen = 0;
}
@ -237,7 +237,7 @@ sha256_done(struct sha256_state *md, unsigned char *out)
/* store length */
WPA_PUT_BE64(md->buf + 56, md->length);
sha256_compress(md, md->buf);
wpa_sha256_compress(md, md->buf);
/* copy output */
for (i = 0; i < 8; i++)

View File

@ -29,7 +29,7 @@
* @mac: Buffer for the hash (32 bytes)
*/
void
hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
wpa_hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
const u8 *addr[], const size_t *len, u8 *mac)
{
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
@ -47,7 +47,7 @@ hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
/* if key is longer than 64 bytes reset it to key = SHA256(key) */
if (key_len > 64) {
sha256_vector(1, &key, &key_len, tk);
wpa_sha256_vector(1, &key, &key_len, tk);
key = tk;
key_len = 32;
}
@ -75,7 +75,7 @@ hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
_addr[i + 1] = addr[i];
_len[i + 1] = len[i];
}
sha256_vector(1 + num_elem, _addr, _len, mac);
wpa_sha256_vector(1 + num_elem, _addr, _len, mac);
os_memset(k_pad, 0, sizeof(k_pad));
os_memcpy(k_pad, key, key_len);
@ -88,7 +88,7 @@ hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
_len[0] = 64;
_addr[1] = mac;
_len[1] = SHA256_MAC_LEN;
sha256_vector(2, _addr, _len, mac);
wpa_sha256_vector(2, _addr, _len, mac);
}
@ -101,10 +101,10 @@ hmac_sha256_vector(const u8 *key, size_t key_len, size_t num_elem,
* @mac: Buffer for the hash (20 bytes)
*/
void
hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
wpa_hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
size_t data_len, u8 *mac)
{
hmac_sha256_vector(key, key_len, 1, &data, &data_len, mac);
wpa_hmac_sha256_vector(key, key_len, 1, &data, &data_len, mac);
}
@ -122,7 +122,7 @@ hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
* given key.
*/
void
sha256_prf(const u8 *key, size_t key_len, const char *label,
wpa_sha256_prf(const u8 *key, size_t key_len, const char *label,
const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
{
u16 counter = 1;
@ -147,11 +147,11 @@ sha256_prf(const u8 *key, size_t key_len, const char *label,
plen = buf_len - pos;
WPA_PUT_LE16(counter_le, counter);
if (plen >= SHA256_MAC_LEN) {
hmac_sha256_vector(key, key_len, 4, addr, len,
wpa_hmac_sha256_vector(key, key_len, 4, addr, len,
&buf[pos]);
pos += SHA256_MAC_LEN;
} else {
hmac_sha256_vector(key, key_len, 4, addr, len, hash);
wpa_hmac_sha256_vector(key, key_len, 4, addr, len, hash);
os_memcpy(&buf[pos], hash, plen);
break;
}