2 * Copyright (C) 2004 g10 Code GmbH
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "crypt-mod.h"
25 /* A type an a variable to keep track of registered crypto modules. */
26 typedef struct crypt_module *crypt_module_t;
30 crypt_module_specs_t specs;
31 crypt_module_t next, *prevp;
34 static crypt_module_t modules;
36 /* Register a new crypto module. */
37 void crypto_module_register (crypt_module_specs_t specs)
39 crypt_module_t module_new = safe_malloc (sizeof (*module_new));
41 module_new->specs = specs;
42 module_new->next = modules;
44 modules->prevp = &module_new->next;
48 /* Return the crypto module specs for IDENTIFIER. This function is
49 usually used via the CRYPT_MOD_CALL[_CHECK] macros. */
50 crypt_module_specs_t crypto_module_lookup (int identifier)
52 crypt_module_t module = modules;
54 while (module && (module->specs->identifier != identifier))
55 module = module->next;
57 return module ? module->specs : NULL;