Debian Codegraph @

test/cryptounittest/test-cipher-arcfour.c

raw
1 /**
2 * \file test-cipher-arcfour.c
3 *
4 * \brief The ARCFOUR stream cipher unit-tests
5 *
6 * \warning ARCFOUR is considered a weak cipher and its use constitutes a
7 * security risk! We recommend considering stronger ciphers instead!
8 *
9 * \copyright 2022 Joseph Benden <[email protected]>
10 *
11 * \license GPL-2.0-OR-LATER
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <strings.h>
22 #include <stdlib.h>
23
24 #include "aircrack-ng/crypto/crypto.h"
25 #include "tests.h"
26
27 // clang-format off
28 /*
29 * ARC4 tests vectors as posted by Eric Rescorla in sep. 1994:
30 *
31 * http://groups.google.com/group/comp.security.misc/msg/10a300c9d21afca0
32 */
33 static const uint8_t arc4_test_key[3][8]
34 = {{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
35 {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
36 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
37
38 static const uint8_t arc4_test_pt[3][8]
39 = {{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
40 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
41 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
42
43 static const uint8_t arc4_test_ct[3][8]
44 = {{0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96},
45 {0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79},
46 {0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A}};
47 // clang-format on
48
49 int main(int argc, char ** argv)
50 {
51 int i, error = 0;
52 uint8_t ibuf[8];
53 uint8_t obuf[8];
54 Cipher_RC4_KEY ctx;
55
56 (void) argc;
57
58 for (i = 0; i < 3; i++)
59 {
60 memcpy(ibuf, arc4_test_pt[i], 8);
61 Cipher_RC4_set_key(&ctx, 8, arc4_test_key[i]);
62 Cipher_RC4(&ctx, 8, ibuf, obuf);
63 error |= test(obuf, (uint8_t *) arc4_test_ct[i], 8, argv[0]);
64 }
65
66 return error;
67 }