3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 09:39:25 +01:00

arc4: Add arc4_skip

This commit is contained in:
Denis Kenzior 2015-02-17 15:54:58 -06:00
parent 6e6783fc11
commit dd56283b11
3 changed files with 82 additions and 0 deletions

View File

@ -46,6 +46,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \
src/netdev.h src/netdev.c \
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/sha256.h src/sha256.c \

54
src/arc4.c Normal file
View File

@ -0,0 +1,54 @@
/*
*
* 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
#define _GNU_SOURCE
#include <ell/ell.h>
#include "src/arc4.h"
bool arc4_skip(const uint8_t *key, size_t key_len, size_t skip,
const uint8_t *in, size_t len, uint8_t *out)
{
char skip_buf[1024];
struct l_cipher *cipher;
cipher = l_cipher_new(L_CIPHER_ARC4, key, key_len);
if (!cipher)
return false;
while (skip > 0) {
size_t to_skip =
skip > sizeof(skip_buf) ? sizeof(skip_buf) : skip;
l_cipher_decrypt(cipher, skip_buf, skip_buf, to_skip);
skip -= to_skip;
}
l_cipher_decrypt(cipher, in, out, len);
l_cipher_free(cipher);
return true;
}

27
src/arc4.h Normal file
View File

@ -0,0 +1,27 @@
/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2013-2015 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>
#include <stdint.h>
bool arc4_skip(const uint8_t *key, size_t key_len, size_t skip,
const uint8_t *in, size_t len, uint8_t *out);