3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

sha256: Remove and move to src/crypto.c

This commit is contained in:
Denis Kenzior 2015-02-18 20:45:52 -06:00
parent 57c51a2e12
commit 02d101e3d7
5 changed files with 21 additions and 117 deletions

View File

@ -49,7 +49,6 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \
src/arc4.h src/arc4.c \ src/arc4.h src/arc4.c \
src/md5.h src/md5.c \ src/md5.h src/md5.c \
src/sha1.h src/sha1.c \ src/sha1.h src/sha1.c \
src/sha256.h src/sha256.c \
src/ie.h src/ie.c \ src/ie.h src/ie.c \
src/dbus.h src/dbus.c \ src/dbus.h src/dbus.c \
src/manager.h src/manager.c \ src/manager.h src/manager.c \
@ -111,7 +110,8 @@ unit_test_hmac_sha1_SOURCES = unit/test-hmac-sha1.c \
unit_test_hmac_sha1_LDADD = ell/libell-internal.la unit_test_hmac_sha1_LDADD = ell/libell-internal.la
unit_test_hmac_sha256_SOURCES = unit/test-hmac-sha256.c \ unit_test_hmac_sha256_SOURCES = unit/test-hmac-sha256.c \
src/sha256.h src/sha256.c src/sha1.h src/sha1.c \
src/crypto.h src/crypto.c
unit_test_hmac_sha256_LDADD = ell/libell-internal.la unit_test_hmac_sha256_LDADD = ell/libell-internal.la
unit_test_pbkdf2_sha1_SOURCES = unit/test-pbkdf2-sha1.c \ unit_test_pbkdf2_sha1_SOURCES = unit/test-pbkdf2-sha1.c \

View File

@ -34,6 +34,22 @@
#include "sha1.h" #include "sha1.h"
#include "crypto.h" #include "crypto.h"
bool hmac_sha256(const void *key, size_t key_len,
const void *data, size_t data_len, void *output, size_t size)
{
struct l_checksum *hmac;
hmac = l_checksum_new_hmac(L_CHECKSUM_SHA256, key, key_len);
if (!hmac)
return false;
l_checksum_update(hmac, data, data_len);
l_checksum_get_digest(hmac, output, size);
l_checksum_free(hmac);
return true;
}
/* 802.11, Section 11.6.2, Table 11-4 */ /* 802.11, Section 11.6.2, Table 11-4 */
int crypto_cipher_key_len(enum crypto_cipher cipher) int crypto_cipher_key_len(enum crypto_cipher cipher)
{ {

View File

@ -37,6 +37,9 @@ struct crypto_ptk {
uint8_t tk[0]; uint8_t tk[0];
} __attribute__ ((packed)); } __attribute__ ((packed));
bool hmac_sha256(const void *key, size_t key_len,
const void *data, size_t data_len, void *output, size_t size);
int crypto_cipher_key_len(enum crypto_cipher cipher); int crypto_cipher_key_len(enum crypto_cipher cipher);
int crypto_cipher_tk_bits(enum crypto_cipher cipher); int crypto_cipher_tk_bits(enum crypto_cipher cipher);

View File

@ -1,89 +0,0 @@
/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <ell/ell.h>
#include "src/sha256.h"
#define SHA256_MAC_LEN 32
static void __hmac_sha256(struct l_checksum *checksum,
const void *key, size_t key_len,
const void *data, size_t data_len,
void *output, size_t size)
{
unsigned char ipad[64];
unsigned char opad[64];
unsigned char digest[SHA256_MAC_LEN];
int i;
/* if key is longer than 64 bytes reset it to key=SHA256(key) */
if (key_len > 64) {
l_checksum_update(checksum, key, key_len);
l_checksum_get_digest(checksum, digest, SHA256_MAC_LEN);
key = digest;
key_len = SHA256_MAC_LEN;
}
/* start out by storing key in pads */
memset(ipad, 0, sizeof(ipad));
memset(opad, 0, sizeof(opad));
memcpy(ipad, key, key_len);
memcpy(opad, key, key_len);
/* XOR key with ipad and opad values */
for (i = 0; i < 64; i++) {
ipad[i] ^= 0x36;
opad[i] ^= 0x5c;
}
/* perform inner SHA256 */
l_checksum_update(checksum, ipad, sizeof(ipad));
l_checksum_update(checksum, data, data_len);
l_checksum_get_digest(checksum, digest, SHA256_MAC_LEN);
/* perform outer SHA256 */
l_checksum_update(checksum, opad, sizeof(opad));
l_checksum_update(checksum, digest, SHA256_MAC_LEN);
l_checksum_get_digest(checksum, output,
size > SHA256_MAC_LEN ? SHA256_MAC_LEN : size);
}
bool hmac_sha256(const void *key, size_t key_len,
const void *data, size_t data_len, void *output, size_t size)
{
struct l_checksum *checksum;
checksum = l_checksum_new(L_CHECKSUM_SHA256);
__hmac_sha256(checksum, key, key_len, data, data_len, output, size);
l_checksum_free(checksum);
return true;
}

View File

@ -1,26 +0,0 @@
/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdbool.h>
bool hmac_sha256(const void *key, size_t key_len,
const void *data, size_t data_len, void *output, size_t size);