maint: normalize copyright notices
[gnulib.git] / tests / test-gc-des.c
1 /*
2  * Copyright (C) 2005, 2010 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, or (at your option)
8  * 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.  */
19
20 #include <config.h>
21
22 #include <stdio.h>
23 #include <string.h>
24 #include "gc.h"
25
26 int
27 main (int argc, char *argv[])
28 {
29   gc_cipher_handle ctx;
30   Gc_rc rc;
31
32   rc = gc_init ();
33   if (rc != GC_OK)
34     {
35       printf ("gc_init() failed\n");
36       return 1;
37     }
38
39   /*
40    * DES Maintenance Test
41    */
42   {
43     int i;
44     char key[8] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
45     char input[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
46     char result[8] = { 0x24, 0x6e, 0x9d, 0xb9, 0xc5, 0x50, 0x38, 0x1a };
47     char temp1[8], temp2[8], temp3[8];
48
49     for (i = 0; i < 64; ++i)
50       {
51
52         rc = gc_cipher_open (GC_DES, GC_ECB, &ctx);
53         if (rc != GC_OK)
54           return 1;
55
56         rc = gc_cipher_setkey (ctx, 8, key);
57         if (rc != GC_OK)
58           return 1;
59
60         memcpy (temp1, input, 8);
61         rc = gc_cipher_encrypt_inline (ctx, 8, temp1);
62         if (rc != GC_OK)
63           return 1;
64
65         memcpy (temp2, temp1, 8);
66         rc = gc_cipher_encrypt_inline (ctx, 8, temp2);
67         if (rc != GC_OK)
68           return 1;
69
70         rc = gc_cipher_setkey (ctx, 8, temp2);
71         if (rc != GC_OK)
72           return 1;
73
74         memcpy (temp3, temp1, 8);
75         rc = gc_cipher_decrypt_inline (ctx, 8, temp3);
76         if (rc != GC_OK)
77           return 1;
78
79         memcpy (key, temp3, 8);
80         memcpy (input, temp1, 8);
81       }
82     if (memcmp (temp3, result, 8))
83       return 1;
84   }
85
86   gc_done ();
87
88   return 0;
89 }