Relicense some modules under LGPLv2+.
[gnulib/ericb.git] / tests / test-gc-des.c
blobf85f3a16bea799a2147f6a3319a1a1dad539b9d2
1 /*
2 * Copyright (C) 2005, 2010-2017 Free Software Foundation, Inc.
3 * Written by Simon Josefsson
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.
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.
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/>. */
18 #include <config.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include "gc.h"
24 int
25 main (int argc, char *argv[])
27 gc_cipher_handle ctx;
28 Gc_rc rc;
30 rc = gc_init ();
31 if (rc != GC_OK)
33 printf ("gc_init() failed\n");
34 return 1;
38 * DES Maintenance Test
41 int i;
42 char key[8] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
43 char input[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
44 char result[8] = { 0x24, 0x6e, 0x9d, 0xb9, 0xc5, 0x50, 0x38, 0x1a };
45 char temp1[8], temp2[8], temp3[8];
47 for (i = 0; i < 64; ++i)
50 rc = gc_cipher_open (GC_DES, GC_ECB, &ctx);
51 if (rc != GC_OK)
52 return 1;
54 rc = gc_cipher_setkey (ctx, 8, key);
55 if (rc != GC_OK)
56 return 1;
58 memcpy (temp1, input, 8);
59 rc = gc_cipher_encrypt_inline (ctx, 8, temp1);
60 if (rc != GC_OK)
61 return 1;
63 memcpy (temp2, temp1, 8);
64 rc = gc_cipher_encrypt_inline (ctx, 8, temp2);
65 if (rc != GC_OK)
66 return 1;
68 rc = gc_cipher_setkey (ctx, 8, temp2);
69 if (rc != GC_OK)
70 return 1;
72 memcpy (temp3, temp1, 8);
73 rc = gc_cipher_decrypt_inline (ctx, 8, temp3);
74 if (rc != GC_OK)
75 return 1;
77 memcpy (key, temp3, 8);
78 memcpy (input, temp1, 8);
80 if (memcmp (temp3, result, 8))
81 return 1;
84 gc_done ();
86 return 0;