From dd56283b114a0aa2242db03b432cb619f96ae2ed Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Tue, 17 Feb 2015 15:54:58 -0600 Subject: [PATCH] arc4: Add arc4_skip --- Makefile.am | 1 + src/arc4.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/arc4.h | 27 +++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/arc4.c create mode 100644 src/arc4.h diff --git a/Makefile.am b/Makefile.am index 548811bd..94ee6787 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/arc4.c b/src/arc4.c new file mode 100644 index 00000000..d3a7fb3d --- /dev/null +++ b/src/arc4.c @@ -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 +#endif + +#define _GNU_SOURCE +#include + +#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; +} diff --git a/src/arc4.h b/src/arc4.h new file mode 100644 index 00000000..5c84368a --- /dev/null +++ b/src/arc4.h @@ -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 +#include + +bool arc4_skip(const uint8_t *key, size_t key_len, size_t skip, + const uint8_t *in, size_t len, uint8_t *out);