Mercurial > gnulib
annotate tests/test-gc-des.c @ 40224:5d9b82ca550a
tests: Free allocated memory.
Reported by <deltatau@protonmail.com> via Assaf Gordon.
* tests/test-astrxfrm.c (main): Free allocated memory.
* tests/test-bitset.c (compare, check_attributes): Free allocated
bitsets.
* tests/test-filenamecat.c (main): Free allocated memory.
* tests/test-freadahead.c (main): Free allocated memory and close stdin.
* tests/test-freadptr.c (main): Likewise.
* tests/test-freadptr2.c (main): Free allocated memory.
* tests/test-freadseek.c (main): Likewise.
* tests/test-gc-arcfour.c (main): Close allocated context.
* tests/test-gc-arctwo.c (main): Likewise.
* tests/test-gc-des.c (main): Close all allocated contexts.
* tests/test-pipe-filter-gi1.c (main): Free allocated memory.
* tests/test-pipe-filter-ii1.c (main): Likewise.
* tests/test-posix_spawn_file_actions_addchdir.c (main): Destroy the
allocated file actions.
* tests/test-posix_spawn_file_actions_addclose.c (main): Likewise.
* tests/test-posix_spawn_file_actions_adddup2.c (main): Likewise.
* tests/test-posix_spawn_file_actions_addopen.c (main): Likewise.
* tests/test-sameacls.c (main): Free allocated memory and ACLs.
* tests/test-strfmon_l.c (main): Free allocated locales.
* tests/test-striconveh.c (main): Free allocated iconv_t objects.
* tests/uniconv/test-u8-conv-to-enc.c (main): Free allocated memory.
* tests/uniconv/test-u16-conv-to-enc.c (main): Likewise.
* tests/uniconv/test-u32-conv-to-enc.c (main): Likewise.
* tests/unistr/test-chr.h (main): Free input32.
* tests/unistr/test-strchr.h (test_strchr): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 10 Mar 2019 14:05:09 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 * Copyright (C) 2005, 2010-2019 Free Software Foundation, Inc. |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
3 * Written by Simon Josefsson |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 * |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
12520
e84eea643139
tests: fix license on several tests
Eric Blake <ebb9@byu.net>
parents:
12421
diff
changeset
|
7 * the Free Software Foundation; either version 3, or (at your option) |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 * any later version. |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 * |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 * |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
19190 | 16 * along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
6404
diff
changeset
|
18 #include <config.h> |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 |
19260
8fc416080bd2
crypto/*: Verify that the header file is self-contained.
Bruno Haible <bruno@clisp.org>
parents:
19190
diff
changeset
|
20 #include "gc.h" |
8fc416080bd2
crypto/*: Verify that the header file is self-contained.
Bruno Haible <bruno@clisp.org>
parents:
19190
diff
changeset
|
21 |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
22 #include <stdio.h> |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
23 #include <string.h> |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
24 |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
25 int |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 main (int argc, char *argv[]) |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 { |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
28 Gc_rc rc; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
29 |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
30 rc = gc_init (); |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 if (rc != GC_OK) |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 { |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 printf ("gc_init() failed\n"); |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
34 return 1; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
35 } |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
36 |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 /* |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 * DES Maintenance Test |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 */ |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
40 { |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 int i; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
42 char key[8] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
43 char input[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 char result[8] = { 0x24, 0x6e, 0x9d, 0xb9, 0xc5, 0x50, 0x38, 0x1a }; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 char temp1[8], temp2[8], temp3[8]; |
40224
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
46 gc_cipher_handle ctx_array[64]; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
47 |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
48 for (i = 0; i < 64; ++i) |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 { |
40224
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
50 gc_cipher_handle ctx; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
51 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
52 rc = gc_cipher_open (GC_DES, GC_ECB, &ctx); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
53 if (rc != GC_OK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
54 return 1; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
55 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
56 rc = gc_cipher_setkey (ctx, 8, key); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
57 if (rc != GC_OK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
58 return 1; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
59 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
60 memcpy (temp1, input, 8); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
61 rc = gc_cipher_encrypt_inline (ctx, 8, temp1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
62 if (rc != GC_OK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
63 return 1; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
64 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
65 memcpy (temp2, temp1, 8); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
66 rc = gc_cipher_encrypt_inline (ctx, 8, temp2); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
67 if (rc != GC_OK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
68 return 1; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
69 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
70 rc = gc_cipher_setkey (ctx, 8, temp2); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
71 if (rc != GC_OK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
72 return 1; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
73 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
74 memcpy (temp3, temp1, 8); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
75 rc = gc_cipher_decrypt_inline (ctx, 8, temp3); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
76 if (rc != GC_OK) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
77 return 1; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
78 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
79 memcpy (key, temp3, 8); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
80 memcpy (input, temp1, 8); |
40224
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
81 |
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
82 ctx_array[i] = ctx; |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
83 } |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
84 if (memcmp (temp3, result, 8)) |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
85 return 1; |
40224
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
86 |
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
87 for (i = 0; i < 64; ++i) |
5d9b82ca550a
tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents:
40057
diff
changeset
|
88 gc_cipher_close (ctx_array[i]); |
6404
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
89 } |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
90 |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
91 gc_done (); |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
92 |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
93 return 0; |
d38a727f8479
Add des, des-tests, gc-des, gc-des-tests modules.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
94 } |