pty: Activate the signature wrapper of forkpty.
[gnulib.git] / tests / test-arcfour.c
1 /*
2  * Copyright (C) 2005, 2010-2013 Free Software Foundation, Inc.
3  * Written by Simon Josefsson
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #include <config.h>
19
20 #include <stdio.h>
21 #include <string.h>
22 #include "arcfour.h"
23
24 int
25 main (int argc, char *argv[])
26 {
27   arcfour_context ctx;
28   /* Test vector from Cryptlib via Libgcrypt labeled there: "from the
29      State/Commerce Department". */
30   static char key_1[] = { 0x61, 0x8A, 0x63, 0xD2, 0xFB };
31   static char plaintext_1[] = { 0xDC, 0xEE, 0x4C, 0xF9, 0x2C };
32   static const char ciphertext_1[] = { 0xF1, 0x38, 0x29, 0xC9, 0xDE };
33   char scratch[16];
34
35   arcfour_setkey (&ctx, key_1, sizeof (key_1));
36   arcfour_stream (&ctx, plaintext_1, scratch, sizeof (plaintext_1));
37   if (memcmp (scratch, ciphertext_1, sizeof (ciphertext_1)))
38     {
39       size_t i;
40       printf ("expected:\n");
41       for (i = 0; i < 5; i++)
42         printf ("%02x ", scratch[i] & 0xFF);
43       printf ("\ncomputed:\n");
44       for (i = 0; i < 5; i++)
45         printf ("%02x ", ciphertext_1[i] & 0xFF);
46       printf ("\n");
47       return 1;
48     }
49
50   /* decrypt */
51
52   arcfour_setkey (&ctx, key_1, sizeof (key_1));
53   arcfour_stream (&ctx, scratch, scratch, sizeof (plaintext_1));
54   if (memcmp (scratch, plaintext_1, sizeof (plaintext_1)))
55     {
56       size_t i;
57       printf ("expected:\n");
58       for (i = 0; i < 5; i++)
59         printf ("%02x ", plaintext_1[i] & 0xFF);
60       printf ("\ncomputed:\n");
61       for (i = 0; i < 5; i++)
62         printf ("%02x ", scratch[i] & 0xFF);
63       printf ("\n");
64       return 1;
65     }
66
67
68   return 0;
69 }