From 628ed5ba0ef4b1f04b5a77e29e4bc49a1fe13c07 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 2 Oct 2013 13:53:07 +0200 Subject: [PATCH] Remove last remains of the former module system. * src/gcrypt-module.h, src/module.c: Remove. * src/visibility.h: Do not include gcrypt-module.h. * src/g10lib.h: Remove all prototypes from module.c (gcry_module): Remove. * cipher/cipher-internal.h (gcry_cipher_handle): Remove unused field. Signed-off-by: Werner Koch --- cipher/cipher-internal.h | 1 - src/Makefile.am | 4 +- src/g10lib.h | 47 +---------- src/gcrypt-module.h | 57 ------------- src/module.c | 212 ----------------------------------------------- src/visibility.h | 1 - 6 files changed, 3 insertions(+), 319 deletions(-) delete mode 100644 src/gcrypt-module.h delete mode 100644 src/module.c diff --git a/cipher/cipher-internal.h b/cipher/cipher-internal.h index cabcd1f9..b60ef386 100644 --- a/cipher/cipher-internal.h +++ b/cipher/cipher-internal.h @@ -61,7 +61,6 @@ struct gcry_cipher_handle size_t actual_handle_size; /* Allocated size of this handle. */ size_t handle_offset; /* Offset to the malloced block. */ gcry_cipher_spec_t *spec; - gcry_module_t module; /* The algorithm id. This is a hack required because the module interface does not easily allow to retrieve this value. */ diff --git a/src/Makefile.am b/src/Makefile.am index 3bc27c89..c0202395 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,10 +56,10 @@ endif libgcrypt_la_CFLAGS = $(GPG_ERROR_CFLAGS) libgcrypt_la_SOURCES = \ gcrypt-int.h g10lib.h visibility.c visibility.h types.h \ - cipher.h cipher-proto.h gcrypt-module.h \ + cipher.h cipher-proto.h \ misc.c global.c sexp.c hwfeatures.c hwf-common.h \ stdmem.c stdmem.h secmem.c secmem.h \ - mpi.h missing-string.c module.c fips.c \ + mpi.h missing-string.c fips.c \ hmac256.c hmac256.h context.c context.h \ ec-context.h \ ath.h ath.c diff --git a/src/g10lib.h b/src/g10lib.h index ff7f4b3a..43281ad3 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -351,52 +351,7 @@ void _gcry_burn_stack (unsigned int bytes); || (*(a) >= 'A' && *(a) <= 'F') \ || (*(a) >= 'a' && *(a) <= 'f')) -/* Management for ciphers/digests/pubkey-ciphers. */ - -/* Structure for each registered `module'. */ -struct gcry_module -{ - struct gcry_module *next; /* List pointers. */ - struct gcry_module **prevp; - void *spec; /* Pointer to the subsystem-specific - specification structure. */ - void *extraspec; /* Pointer to the subsystem-specific - extra specification structure. */ - int flags; /* Associated flags. */ - int counter; /* Use counter. */ - unsigned int mod_id; /* ID of this module. */ -}; - -/* Flags for the `flags' member of gcry_module_t. */ -#define FLAG_MODULE_DISABLED (1 << 0) - -gcry_err_code_t _gcry_module_add (gcry_module_t *entries, - unsigned int id, - void *spec, - void *extraspec, - gcry_module_t *module); - -typedef int (*gcry_module_lookup_t) (void *spec, void *data); - -/* Lookup a module specification by it's ID. After a successful - lookup, the module has it's resource counter incremented. */ -gcry_module_t _gcry_module_lookup_id (gcry_module_t entries, - unsigned int id); - -/* Internal function. Lookup a module specification. */ -gcry_module_t _gcry_module_lookup (gcry_module_t entries, void *data, - gcry_module_lookup_t func); - -/* Release a module. In case the use-counter reaches zero, destroy - the module. */ -void _gcry_module_release (gcry_module_t entry); - -/* Add a reference to a module. */ -void _gcry_module_use (gcry_module_t module); - -/* Return a list of module IDs. */ -gcry_err_code_t _gcry_module_list (gcry_module_t modules, - int *list, int *list_length); +/* Init functions. */ gcry_err_code_t _gcry_cipher_init (void); gcry_err_code_t _gcry_md_init (void); diff --git a/src/gcrypt-module.h b/src/gcrypt-module.h deleted file mode 100644 index 35a928c7..00000000 --- a/src/gcrypt-module.h +++ /dev/null @@ -1,57 +0,0 @@ -/* gcrypt-module.h - GNU Cryptographic Library Interface - Copyright (C) 2003, 2007 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, see . - */ - -/* - This file contains the necessary declarations/definitions for - working with Libgcrypt modules. Since 1.6 this is an internal - interface and will eventually be merged into another header or - entirely removed. - */ - -#ifndef GCRYPT_MODULE_H -#define GCRYPT_MODULE_H - -#ifdef __cplusplus -extern "C" { -#if 0 /* keep Emacsens's auto-indent happy */ -} -#endif -#endif - -/* The interfaces using the module system reserve a certain range of - IDs for application use. These IDs are not valid within Libgcrypt - but Libgcrypt makes sure never to allocate such a module ID. */ -#define GCRY_MODULE_ID_USER 1024 -#define GCRY_MODULE_ID_USER_LAST 4095 - - -/* This type represents a `module'. */ -typedef struct gcry_module *gcry_module_t; - - -/* ********************** */ - - -#if 0 /* keep Emacsens's auto-indent happy */ -{ -#endif -#ifdef __cplusplus -} -#endif -#endif /*GCRYPT_MODULE_H*/ diff --git a/src/module.c b/src/module.c deleted file mode 100644 index 32f668de..00000000 --- a/src/module.c +++ /dev/null @@ -1,212 +0,0 @@ -/* module.c - Module management for libgcrypt. - * Copyright (C) 2003, 2008 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, see . - */ - -#include -#include -#include "g10lib.h" - -/* Please match these numbers with the allocated algorithm - numbers. */ -#define MODULE_ID_MIN 600 -#define MODULE_ID_LAST 65500 -#define MODULE_ID_USER GCRY_MODULE_ID_USER -#define MODULE_ID_USER_LAST GCRY_MODULE_ID_USER_LAST - -#if MODULE_ID_MIN >= MODULE_ID_USER -#error Need to implement a different search strategy -#endif - -/* Internal function. Generate a new, unique module ID for a module - that should be inserted into the module chain starting at - MODULES. */ -static gcry_err_code_t -_gcry_module_id_new (gcry_module_t modules, unsigned int *id_new) -{ - unsigned int mod_id; - gcry_err_code_t err = GPG_ERR_NO_ERROR; - gcry_module_t module; - - /* Search for unused ID. */ - for (mod_id = MODULE_ID_MIN; mod_id < MODULE_ID_LAST; mod_id++) - { - if (mod_id == MODULE_ID_USER) - { - mod_id = MODULE_ID_USER_LAST; - continue; - } - - /* Search for a module with the current ID. */ - for (module = modules; module; module = module->next) - if (mod_id == module->mod_id) - break; - - if (! module) - /* None found -> the ID is available for use. */ - break; - } - - if (mod_id < MODULE_ID_LAST) - /* Done. */ - *id_new = mod_id; - else - /* No free ID found. */ - err = GPG_ERR_INTERNAL; - - return err; -} - -/* Add a module specification to the list ENTRIES. The new module has - it's use-counter set to one. */ -gcry_err_code_t -_gcry_module_add (gcry_module_t *entries, unsigned int mod_id, - void *spec, void *extraspec, gcry_module_t *module) -{ - gcry_err_code_t err = 0; - gcry_module_t entry; - - if (! mod_id) - err = _gcry_module_id_new (*entries, &mod_id); - - if (! err) - { - entry = gcry_malloc (sizeof (struct gcry_module)); - if (! entry) - err = gpg_err_code_from_errno (errno); - } - - if (! err) - { - /* Fill new module entry. */ - entry->flags = 0; - entry->counter = 1; - entry->spec = spec; - entry->extraspec = extraspec; - entry->mod_id = mod_id; - - /* Link it into the list. */ - entry->next = *entries; - entry->prevp = entries; - if (*entries) - (*entries)->prevp = &entry->next; - *entries = entry; - - /* And give it to the caller. */ - if (module) - *module = entry; - } - return err; -} - -/* Internal function. Unlink CIPHER_ENTRY from the list of registered - ciphers and destroy it. */ -static void -_gcry_module_drop (gcry_module_t entry) -{ - *entry->prevp = entry->next; - if (entry->next) - entry->next->prevp = entry->prevp; - - gcry_free (entry); -} - -/* Lookup a module specification by it's ID. After a successful - lookup, the module has it's resource counter incremented. */ -gcry_module_t -_gcry_module_lookup_id (gcry_module_t entries, unsigned int mod_id) -{ - gcry_module_t entry; - - for (entry = entries; entry; entry = entry->next) - if (entry->mod_id == mod_id) - { - entry->counter++; - break; - } - - return entry; -} - -/* Lookup a module specification. After a successful lookup, the - module has it's resource counter incremented. FUNC is a function - provided by the caller, which is responsible for identifying the - wanted module. */ -gcry_module_t -_gcry_module_lookup (gcry_module_t entries, void *data, - gcry_module_lookup_t func) -{ - gcry_module_t entry; - - for (entry = entries; entry; entry = entry->next) - if ((*func) (entry->spec, data)) - { - entry->counter++; - break; - } - - return entry; -} - -/* Release a module. In case the use-counter reaches zero, destroy - the module. Passing MODULE as NULL is a dummy operation (similar - to free()). */ -void -_gcry_module_release (gcry_module_t module) -{ - if (module && ! --module->counter) - _gcry_module_drop (module); -} - -/* Add a reference to a module. */ -void -_gcry_module_use (gcry_module_t module) -{ - ++module->counter; -} - -/* If LIST is zero, write the number of modules identified by MODULES - to LIST_LENGTH and return. If LIST is non-zero, the first - *LIST_LENGTH algorithm IDs are stored in LIST, which must be of - according size. In case there are less cipher modules than - *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */ -gcry_err_code_t -_gcry_module_list (gcry_module_t modules, - int *list, int *list_length) -{ - gcry_err_code_t err = GPG_ERR_NO_ERROR; - gcry_module_t module; - int length, i; - - for (module = modules, length = 0; module; module = module->next, length++); - - if (list) - { - if (length > *list_length) - length = *list_length; - - for (module = modules, i = 0; i < length; module = module->next, i++) - list[i] = module->mod_id; - - if (length < *list_length) - *list_length = length; - } - else - *list_length = length; - - return err; -} diff --git a/src/visibility.h b/src/visibility.h index 7e7793bc..cd2a60fb 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -208,7 +208,6 @@ #else # include "gcrypt-int.h" #endif -#include "gcrypt-module.h" /* Prototypes of functions exported but not ready for use. */ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, -- 2.11.0