mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-25 16:42:37 +01:00
md5: Remove and move to src/crypto.c
This commit is contained in:
parent
cefff31273
commit
260ef5bb9d
@ -47,7 +47,6 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \
|
||||
src/wiphy.h src/wiphy.c \
|
||||
src/aes.h src/aes.c \
|
||||
src/arc4.h src/arc4.c \
|
||||
src/md5.h src/md5.c \
|
||||
src/sha1.h src/sha1.c \
|
||||
src/ie.h src/ie.c \
|
||||
src/dbus.h src/dbus.c \
|
||||
@ -72,9 +71,9 @@ monitor_iwmon_SOURCES = monitor/main.c linux/nl80211.h \
|
||||
src/mpdu.h src/mpdu.c \
|
||||
src/util.h src/util.c \
|
||||
src/sha1.h src/sha1.c \
|
||||
src/md5.h src/md5.c \
|
||||
src/aes.h src/aes.c \
|
||||
src/arc4.h src/arc4.c \
|
||||
src/crypto.h src/crypto.c \
|
||||
src/eapol.h src/eapol.c
|
||||
monitor_iwmon_LDADD = ell/libell-internal.la
|
||||
|
||||
@ -102,7 +101,8 @@ unit_test_arc4_SOURCES = unit/test-arc4.c \
|
||||
unit_test_arc4_LDADD = ell/libell-internal.la
|
||||
|
||||
unit_test_hmac_md5_SOURCES = unit/test-hmac-md5.c \
|
||||
src/md5.h src/md5.c
|
||||
src/sha1.h src/sha1.c \
|
||||
src/crypto.h src/crypto.c
|
||||
unit_test_hmac_md5_LDADD = ell/libell-internal.la
|
||||
|
||||
unit_test_hmac_sha1_SOURCES = unit/test-hmac-sha1.c \
|
||||
@ -136,7 +136,6 @@ unit_test_mpdu_LDADD = ell/libell-internal.la
|
||||
|
||||
unit_test_eapol_SOURCES = unit/test-eapol.c \
|
||||
src/sha1.h src/sha1.c \
|
||||
src/md5.h src/md5.c \
|
||||
src/aes.h src/aes.c \
|
||||
src/arc4.h src/arc4.c \
|
||||
src/crypto.h src/crypto.c \
|
||||
|
19
src/crypto.c
19
src/crypto.c
@ -34,12 +34,13 @@
|
||||
#include "sha1.h"
|
||||
#include "crypto.h"
|
||||
|
||||
bool hmac_sha256(const void *key, size_t key_len,
|
||||
static bool hmac_common(enum l_checksum_type type,
|
||||
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);
|
||||
hmac = l_checksum_new_hmac(type, key, key_len);
|
||||
if (!hmac)
|
||||
return false;
|
||||
|
||||
@ -50,6 +51,20 @@ bool hmac_sha256(const void *key, size_t key_len,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hmac_md5(const void *key, size_t key_len,
|
||||
const void *data, size_t data_len, void *output, size_t size)
|
||||
{
|
||||
return hmac_common(L_CHECKSUM_MD5, key, key_len, data, data_len,
|
||||
output, size);
|
||||
}
|
||||
|
||||
bool hmac_sha256(const void *key, size_t key_len,
|
||||
const void *data, size_t data_len, void *output, size_t size)
|
||||
{
|
||||
return hmac_common(L_CHECKSUM_SHA256, key, key_len, data, data_len,
|
||||
output, size);
|
||||
}
|
||||
|
||||
/* 802.11, Section 11.6.2, Table 11-4 */
|
||||
int crypto_cipher_key_len(enum crypto_cipher cipher)
|
||||
{
|
||||
|
@ -37,6 +37,8 @@ struct crypto_ptk {
|
||||
uint8_t tk[0];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
bool hmac_md5(const void *key, size_t key_len,
|
||||
const void *data, size_t data_len, void *output, size_t size);
|
||||
bool hmac_sha256(const void *key, size_t key_len,
|
||||
const void *data, size_t data_len, void *output, size_t size);
|
||||
|
||||
|
@ -28,9 +28,9 @@
|
||||
#include <ell/ell.h>
|
||||
|
||||
#include "sha1.h"
|
||||
#include "md5.h"
|
||||
#include "aes.h"
|
||||
#include "arc4.h"
|
||||
#include "crypto.h"
|
||||
#include "eapol.h"
|
||||
|
||||
#define VERIFY_IS_ZERO(field) \
|
||||
|
95
src/md5.c
95
src/md5.c
@ -1,95 +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/md5.h"
|
||||
|
||||
#define MD5_MAC_LEN 16
|
||||
|
||||
static void __hmac_md5(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[MD5_MAC_LEN];
|
||||
int i;
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key=MD5(key) */
|
||||
if (key_len > 64) {
|
||||
l_checksum_update(checksum, key, key_len);
|
||||
l_checksum_get_digest(checksum, digest, MD5_MAC_LEN);
|
||||
|
||||
l_checksum_reset(checksum);
|
||||
|
||||
key = digest;
|
||||
key_len = MD5_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 MD5 */
|
||||
l_checksum_update(checksum, ipad, sizeof(ipad));
|
||||
l_checksum_update(checksum, data, data_len);
|
||||
l_checksum_get_digest(checksum, digest, MD5_MAC_LEN);
|
||||
|
||||
l_checksum_reset(checksum);
|
||||
|
||||
/* perform outer MD5 */
|
||||
l_checksum_update(checksum, opad, sizeof(opad));
|
||||
l_checksum_update(checksum, digest, MD5_MAC_LEN);
|
||||
l_checksum_get_digest(checksum, output,
|
||||
size > MD5_MAC_LEN ? MD5_MAC_LEN : size);
|
||||
|
||||
l_checksum_reset(checksum);
|
||||
}
|
||||
|
||||
bool hmac_md5(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_MD5);
|
||||
|
||||
__hmac_md5(checksum, key, key_len, data, data_len, output, size);
|
||||
|
||||
l_checksum_free(checksum);
|
||||
|
||||
return true;
|
||||
}
|
26
src/md5.h
26
src/md5.h
@ -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_md5(const void *key, size_t key_len,
|
||||
const void *data, size_t data_len, void *output, size_t size);
|
Loading…
Reference in New Issue
Block a user