summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2011-09-15 18:08:55 +0200
committerWerner Koch <wk@gnupg.org>2011-09-15 18:08:55 +0200
commite0fe4a5c862a1646066044dfe8e99264e2331752 (patch)
tree1cf303ee9980a49105c2178096d150affcc138ba /tests
parentfc9eec3626fcb9a3d4043d779462c4fc39cd51ae (diff)
downloadlibgcrypt-e0fe4a5c862a1646066044dfe8e99264e2331752.tar.gz
Removed the module registration interface
The module registration interface is not widely used but complicates the internal operation of Libgcrypt a lot. It also does not allow for efficient implementation of new algorithm or cipher modes. Further the required locking of all access to internal module data or functions would make it hard to come up with a deadlock free pthread_atfork implementation. Thus we remove the entire subsystem. Note that the module system is still used internally but it is now possible to change it without breaking the ABI. In case a feature to add more algorithms demanded in the future, we may add one by dlopening modules at startup time from a dedicated directory.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog2
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/register.c187
3 files changed, 3 insertions, 188 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 03f001ea..8e968986 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,7 @@
2011-09-15 Werner Koch <wk@g10code.com>
+ * register.c: Remove.
+
* ac-data.c, ac-schemes.c, ac.c: Remove.
2011-06-13 Werner Koch <wk@g10code.com>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e20518f6..f1f9e6f3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,7 +18,7 @@
## Process this file with automake to produce Makefile.in
-TESTS = version t-mpi-bit prime register basic \
+TESTS = version t-mpi-bit prime basic \
mpitests tsexp keygen pubkey hmac keygrip fips186-dsa aeswrap \
curves t-kdf pkcs1v2
diff --git a/tests/register.c b/tests/register.c
deleted file mode 100644
index 4d8cebe8..00000000
--- a/tests/register.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* register.c - Test for registering of additional cipher modules.
- * Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
- *
- * This file is part of Libgcrypt.
- *
- * Libgcrypt is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * Libgcrypt is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "../src/gcrypt.h"
-
-static int verbose;
-static int in_fips_mode;
-
-static void
-die (const char *format, ...)
-{
- va_list arg_ptr ;
-
- va_start( arg_ptr, format ) ;
- vfprintf (stderr, format, arg_ptr );
- va_end(arg_ptr);
- exit (1);
-}
-
-gcry_err_code_t
-foo_setkey (void *c, const unsigned char *key, unsigned keylen)
-{
- (void)c;
- (void)key;
- (void)keylen;
-
- return 0;
-}
-
-#define FOO_BLOCKSIZE 16
-
-void
-foo_encrypt (void *c, unsigned char *outbuf, const unsigned char *inbuf)
-{
- int i;
-
- (void)c;
-
- for (i = 0; i < FOO_BLOCKSIZE; i++)
- outbuf[i] = inbuf[i] ^ 0x42;
-}
-
-void
-foo_decrypt (void *c, unsigned char *outbuf, const unsigned char *inbuf)
-{
- int i;
-
- (void)c;
-
- for (i = 0; i < FOO_BLOCKSIZE; i++)
- outbuf[i] = inbuf[i] ^ 0x42;
-}
-
-gcry_cipher_spec_t cipher_spec_foo =
- {
- "FOO", NULL, NULL, 16, 0, 0,
- foo_setkey, foo_encrypt, foo_decrypt,
- NULL, NULL,
- };
-
-int
-check_list (int algorithm)
-{
- gcry_error_t err = GPG_ERR_NO_ERROR;
- int *list, list_length;
- int i, ret = 0;
-
- err = gcry_cipher_list (NULL, &list_length);
- assert (! err);
- list = malloc (sizeof (int) * list_length);
- assert (list);
- err = gcry_cipher_list (list, &list_length);
-
- for (i = 0; i < list_length && (! ret); i++)
- if (list[i] == algorithm)
- ret = 1;
-
- return ret;
-}
-
-void
-check_run (void)
-{
- int err, algorithm;
- gcry_cipher_hd_t h;
- char plain[16] = "Heil Discordia!";
- char encrypted[16], decrypted[16];
- gcry_module_t module;
- int ret;
-
- err = gcry_cipher_register (&cipher_spec_foo, &algorithm, &module);
- if (in_fips_mode)
- {
- if (gpg_err_code (err) != GPG_ERR_NOT_SUPPORTED)
- die ("register cipher failed in fips mode: %s\n", gpg_strerror (err));
- return;
- }
- else
- {
- if (err)
- die ("register cipher failed: %s\n", gpg_strerror (err));
- }
-
- err = gcry_cipher_open (&h, algorithm, GCRY_CIPHER_MODE_CBC, 0);
- if (err)
- die ("gcry_cipher_open failed: %s\n", gpg_strerror (err));
-
- err = gcry_cipher_encrypt (h,
- (unsigned char *) encrypted, sizeof (encrypted),
- (unsigned char *) plain, sizeof (plain));
- assert (! err);
- assert (memcmp ((void *) plain, (void *) encrypted, sizeof (plain)));
-
- err = gcry_cipher_reset (h);
- assert (! err);
-
- err = gcry_cipher_decrypt (h,
- (unsigned char *) decrypted, sizeof (decrypted),
- (unsigned char *) encrypted, sizeof (encrypted));
- assert (! err);
- assert (! memcmp ((void *) plain, (void *) decrypted, sizeof (plain)));
-
- ret = check_list (algorithm);
- assert (ret);
-
- gcry_cipher_close (h);
-
- gcry_cipher_unregister (module);
-
- ret = check_list (algorithm);
- assert (! ret);
-}
-
-int
-main (int argc, char **argv)
-{
- int debug = 0;
- int i = 1;
-
- if (argc > 1 && !strcmp (argv[1], "--verbose"))
- verbose = 1;
- else if (argc > 1 && !strcmp (argv[1], "--debug"))
- verbose = debug = 1;
-
- gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
- if (!gcry_check_version (GCRYPT_VERSION))
- die ("version mismatch\n");
- gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
- if (debug)
- gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
-
- if ( gcry_control (GCRYCTL_FIPS_MODE_P, 0) )
- in_fips_mode = 1;
-
- for (; i > 0; i--)
- check_run ();
-
- /* In fips mode we let the Makefile skip this test because a PASS
- would not make much sense with all egistering disabled. */
- return in_fips_mode? 77:0;
-}