eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

test-arc4.c (3709B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2013-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <assert.h>
     28 #include <ell/ell.h>
     29 
     30 #include "src/crypto.h"
     31 
     32 struct arc4_skip_data {
     33 	const uint8_t key[16];
     34 	size_t offset;
     35 	uint8_t result[16];
     36 };
     37 
     38 static const struct arc4_skip_data test_0 = {
     39 	.key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
     40 			0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, },
     41 	.offset = 0,
     42 	.result = { 0x9a, 0xc7, 0xcc, 0x9a, 0x60, 0x9d, 0x1e, 0xf7,
     43 			0xb2, 0x93, 0x28, 0x99, 0xcd, 0xe4, 0x1b, 0x97 },
     44 };
     45 
     46 static const struct arc4_skip_data test_16 = {
     47 	.key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
     48 			0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, },
     49 	.offset = 16,
     50 	.result = { 0x52, 0x48, 0xc4, 0x95, 0x90, 0x14, 0x12, 0x6a,
     51 			0x6e, 0x8a, 0x84, 0xf1, 0x1d, 0x1a, 0x9e, 0x1c },
     52 };
     53 
     54 static const struct arc4_skip_data test_240 = {
     55 	.key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
     56 			0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, },
     57 	.offset = 240,
     58 	.result = { 0x06, 0x59, 0x02, 0xe4, 0xb6, 0x20, 0xf6, 0xcc,
     59 			0x36, 0xc8, 0x58, 0x9f, 0x66, 0x43, 0x2f, 0x2b },
     60 };
     61 
     62 static const struct arc4_skip_data test_256 = {
     63 	.key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
     64 			0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, },
     65 	.offset = 256,
     66 	.result = { 0xd3, 0x9d, 0x56, 0x6b, 0xc6, 0xbc, 0xe3, 0x01,
     67 			0x07, 0x68, 0x15, 0x15, 0x49, 0xf3, 0x87, 0x3f },
     68 };
     69 
     70 static const struct arc4_skip_data test_2032 = {
     71 	.key = { 0xeb, 0xb4, 0x62, 0x27, 0xc6, 0xcc, 0x8b, 0x37,
     72 			0x64, 0x19, 0x10, 0x83, 0x32, 0x22, 0x77, 0x2a, },
     73 	.offset = 2032,
     74 	.result = { 0x00, 0xa5, 0x42, 0xbb, 0xa0, 0x21, 0x11, 0xcc,
     75 			0x2c, 0x65, 0xb3, 0x8e, 0xbd, 0xba, 0x58, 0x7e },
     76 };
     77 
     78 static const struct arc4_skip_data test_2048 = {
     79 	.key = { 0xeb, 0xb4, 0x62, 0x27, 0xc6, 0xcc, 0x8b, 0x37,
     80 			0x64, 0x19, 0x10, 0x83, 0x32, 0x22, 0x77, 0x2a, },
     81 	.offset = 2048,
     82 	.result = { 0x58, 0x65, 0xfd, 0xbb, 0x5b, 0x48, 0x06, 0x41,
     83 			0x04, 0xe8, 0x30, 0xb3, 0x80, 0xf2, 0xae, 0xde },
     84 };
     85 
     86 static void arc4_skip_test(const void *data)
     87 {
     88 	const struct arc4_skip_data *test = data;
     89 	uint8_t buf[16];
     90 
     91 	memset(buf, 0, sizeof(buf));
     92 
     93 	assert(arc4_skip(test->key, 16, test->offset, buf, sizeof(buf), buf));
     94 	assert(!memcmp(buf, test->result, sizeof(buf)));
     95 	assert(arc4_skip(test->key, 16, test->offset, buf, sizeof(buf), buf));
     96 	assert(l_memeqzero(buf, 16));
     97 }
     98 
     99 int main(int argc, char *argv[])
    100 {
    101 	l_test_init(&argc, &argv);
    102 
    103 	l_test_add("/arc4_skip/Test offset 0", arc4_skip_test, &test_0);
    104 	l_test_add("/arc4_skip/Test offset 16", arc4_skip_test, &test_16);
    105 	l_test_add("/arc4_skip/Test offset 240", arc4_skip_test, &test_240);
    106 	l_test_add("/arc4_skip/Test offset 256", arc4_skip_test, &test_256);
    107 	l_test_add("/arc4_skip/Test offset 2032", arc4_skip_test, &test_2032);
    108 	l_test_add("/arc4_skip/Test offset 2048", arc4_skip_test, &test_2048);
    109 
    110 	return l_test_run();
    111 }