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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 #include "crypt-mod.h"
21 /* A type an a variable to keep track of registered crypto modules. */
22 typedef struct crypt_module *crypt_module_t;
26 crypt_module_specs_t specs;
27 crypt_module_t next, *prevp;
30 static crypt_module_t modules;
32 /* Register a new crypto module. */
33 void crypto_module_register (crypt_module_specs_t specs)
35 crypt_module_t module_new = safe_malloc (sizeof (*module_new));
37 module_new->specs = specs;
38 module_new->next = modules;
40 modules->prevp = &module_new->next;
44 /* Return the crypto module specs for IDENTIFIER. This function is
45 usually used via the CRYPT_MOD_CALL[_CHECK] macros. */
46 crypt_module_specs_t crypto_module_lookup (int identifier)
48 crypt_module_t module = modules;
50 while (module && (module->specs->identifier != identifier))
51 module = module->next;
53 return module ? module->specs : NULL;