gnupload: Support option -h as alias of --help.
[gnulib.git] / tests / test-gc-des.c
blob8b52784bda9b9c3fb1d1990e5fd84004f73e11ec
1 /*
2 * Copyright (C) 2005, 2010-2018 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 <https://www.gnu.org/licenses/>. */
18 #include <config.h>
20 #include "gc.h"
22 #include <stdio.h>
23 #include <string.h>
25 int
26 main (int argc, char *argv[])
28 gc_cipher_handle ctx;
29 Gc_rc rc;
31 rc = gc_init ();
32 if (rc != GC_OK)
34 printf ("gc_init() failed\n");
35 return 1;
39 * DES Maintenance Test
42 int i;
43 char key[8] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
44 char input[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
45 char result[8] = { 0x24, 0x6e, 0x9d, 0xb9, 0xc5, 0x50, 0x38, 0x1a };
46 char temp1[8], temp2[8], temp3[8];
48 for (i = 0; i < 64; ++i)
51 rc = gc_cipher_open (GC_DES, GC_ECB, &ctx);
52 if (rc != GC_OK)
53 return 1;
55 rc = gc_cipher_setkey (ctx, 8, key);
56 if (rc != GC_OK)
57 return 1;
59 memcpy (temp1, input, 8);
60 rc = gc_cipher_encrypt_inline (ctx, 8, temp1);
61 if (rc != GC_OK)
62 return 1;
64 memcpy (temp2, temp1, 8);
65 rc = gc_cipher_encrypt_inline (ctx, 8, temp2);
66 if (rc != GC_OK)
67 return 1;
69 rc = gc_cipher_setkey (ctx, 8, temp2);
70 if (rc != GC_OK)
71 return 1;
73 memcpy (temp3, temp1, 8);
74 rc = gc_cipher_decrypt_inline (ctx, 8, temp3);
75 if (rc != GC_OK)
76 return 1;
78 memcpy (key, temp3, 8);
79 memcpy (input, temp1, 8);
81 if (memcmp (temp3, result, 8))
82 return 1;
85 gc_done ();
87 return 0;