1/* gcrypt-module.h - GNU Cryptographic Library Interface 2 Copyright (C) 2003, 2007 Free Software Foundation, Inc. 3 4 This file is part of Libgcrypt. 5 6 Libgcrypt is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as 8 published by the Free Software Foundation; either version 2.1 of 9 the License, or (at your option) any later version. 10 11 Libgcrypt is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this program; if not, see <http://www.gnu.org/licenses/>. 18 */ 19 20/* 21 This file contains the necessary declarations/definitions for 22 working with Libgcrypt modules. 23 */ 24 25#ifndef _GCRYPT_MODULE_H 26#define _GCRYPT_MODULE_H 27 28#ifdef __cplusplus 29extern "C" { 30#if 0 /* keep Emacsens's auto-indent happy */ 31} 32#endif 33#endif 34 35/* The interfaces using the module system reserve a certain range of 36 IDs for application use. These IDs are not valid within Libgcrypt 37 but Libgcrypt makes sure never to allocate such a module ID. */ 38#define GCRY_MODULE_ID_USER 1024 39#define GCRY_MODULE_ID_USER_LAST 4095 40 41 42/* This type represents a `module'. */ 43typedef struct gcry_module *gcry_module_t; 44 45/* Check that the library fulfills the version requirement. */ 46 47/* Type for the cipher_setkey function. */ 48typedef gcry_err_code_t (*gcry_cipher_setkey_t) (void *c, 49 const unsigned char *key, 50 unsigned keylen); 51 52/* Type for the cipher_encrypt function. */ 53typedef void (*gcry_cipher_encrypt_t) (void *c, 54 unsigned char *outbuf, 55 const unsigned char *inbuf); 56 57/* Type for the cipher_decrypt function. */ 58typedef void (*gcry_cipher_decrypt_t) (void *c, 59 unsigned char *outbuf, 60 const unsigned char *inbuf); 61 62/* Type for the cipher_stencrypt function. */ 63typedef void (*gcry_cipher_stencrypt_t) (void *c, 64 unsigned char *outbuf, 65 const unsigned char *inbuf, 66 unsigned int n); 67 68/* Type for the cipher_stdecrypt function. */ 69typedef void (*gcry_cipher_stdecrypt_t) (void *c, 70 unsigned char *outbuf, 71 const unsigned char *inbuf, 72 unsigned int n); 73 74typedef struct gcry_cipher_oid_spec 75{ 76 const char *oid; 77 int mode; 78} gcry_cipher_oid_spec_t; 79 80/* Module specification structure for ciphers. */ 81typedef struct gcry_cipher_spec 82{ 83 const char *name; 84 const char **aliases; 85 gcry_cipher_oid_spec_t *oids; 86 size_t blocksize; 87 size_t keylen; 88 size_t contextsize; 89 gcry_cipher_setkey_t setkey; 90 gcry_cipher_encrypt_t encrypt; 91 gcry_cipher_decrypt_t decrypt; 92 gcry_cipher_stencrypt_t stencrypt; 93 gcry_cipher_stdecrypt_t stdecrypt; 94} gcry_cipher_spec_t; 95 96/* Register a new cipher module whose specification can be found in 97 CIPHER. On success, a new algorithm ID is stored in ALGORITHM_ID 98 and a pointer representing this module is stored in MODULE. */ 99gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *cipher, 100 int *algorithm_id, 101 gcry_module_t *module) 102 /* */ _GCRY_ATTR_INTERNAL; 103 104 105/* Unregister the cipher identified by MODULE, which must have been 106 registered with gcry_cipher_register. */ 107void gcry_cipher_unregister (gcry_module_t module) 108 /* */ _GCRY_ATTR_INTERNAL; 109 110/* ********************** */ 111 112/* Type for the pk_generate function. */ 113typedef gcry_err_code_t (*gcry_pk_generate_t) (int algo, 114 unsigned int nbits, 115 unsigned long use_e, 116 gcry_mpi_t *skey, 117 gcry_mpi_t **retfactors); 118 119/* Type for the pk_check_secret_key function. */ 120typedef gcry_err_code_t (*gcry_pk_check_secret_key_t) (int algo, 121 gcry_mpi_t *skey); 122 123/* Type for the pk_encrypt function. */ 124typedef gcry_err_code_t (*gcry_pk_encrypt_t) (int algo, 125 gcry_mpi_t *resarr, 126 gcry_mpi_t data, 127 gcry_mpi_t *pkey, 128 int flags); 129 130/* Type for the pk_decrypt function. */ 131typedef gcry_err_code_t (*gcry_pk_decrypt_t) (int algo, 132 gcry_mpi_t *result, 133 gcry_mpi_t *data, 134 gcry_mpi_t *skey, 135 int flags); 136 137/* Type for the pk_sign function. */ 138typedef gcry_err_code_t (*gcry_pk_sign_t) (int algo, 139 gcry_mpi_t *resarr, 140 gcry_mpi_t data, 141 gcry_mpi_t *skey); 142 143/* Type for the pk_verify function. */ 144typedef gcry_err_code_t (*gcry_pk_verify_t) (int algo, 145 gcry_mpi_t hash, 146 gcry_mpi_t *data, 147 gcry_mpi_t *pkey, 148 int (*cmp) (void *, gcry_mpi_t), 149 void *opaquev); 150 151/* Type for the pk_get_nbits function. */ 152typedef unsigned (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey); 153 154/* Module specification structure for message digests. */ 155typedef struct gcry_pk_spec 156{ 157 const char *name; 158 const char **aliases; 159 const char *elements_pkey; 160 const char *elements_skey; 161 const char *elements_enc; 162 const char *elements_sig; 163 const char *elements_grip; 164 int use; 165 gcry_pk_generate_t generate; 166 gcry_pk_check_secret_key_t check_secret_key; 167 gcry_pk_encrypt_t encrypt; 168 gcry_pk_decrypt_t decrypt; 169 gcry_pk_sign_t sign; 170 gcry_pk_verify_t verify; 171 gcry_pk_get_nbits_t get_nbits; 172} gcry_pk_spec_t; 173 174/* Register a new pubkey module whose specification can be found in 175 PUBKEY. On success, a new algorithm ID is stored in ALGORITHM_ID 176 and a pointer representhing this module is stored in MODULE. */ 177gcry_error_t gcry_pk_register (gcry_pk_spec_t *pubkey, 178 unsigned int *algorithm_id, 179 gcry_module_t *module) 180 /* */ _GCRY_ATTR_INTERNAL; 181 182/* Unregister the pubkey identified by ID, which must have been 183 registered with gcry_pk_register. */ 184void gcry_pk_unregister (gcry_module_t module) 185 /* */ _GCRY_ATTR_INTERNAL; 186 187/* ********************** */ 188 189/* Type for the md_init function. */ 190typedef void (*gcry_md_init_t) (void *c); 191 192/* Type for the md_write function. */ 193typedef void (*gcry_md_write_t) (void *c, const void *buf, size_t nbytes); 194 195/* Type for the md_final function. */ 196typedef void (*gcry_md_final_t) (void *c); 197 198/* Type for the md_read function. */ 199typedef unsigned char *(*gcry_md_read_t) (void *c); 200 201typedef struct gcry_md_oid_spec 202{ 203 const char *oidstring; 204} gcry_md_oid_spec_t; 205 206/* Module specification structure for message digests. */ 207typedef struct gcry_md_spec 208{ 209 const char *name; 210 unsigned char *asnoid; 211 int asnlen; 212 gcry_md_oid_spec_t *oids; 213 int mdlen; 214 gcry_md_init_t init; 215 gcry_md_write_t write; 216 gcry_md_final_t final; 217 gcry_md_read_t read; 218 size_t contextsize; /* allocate this amount of context */ 219} gcry_md_spec_t; 220 221/* Register a new digest module whose specification can be found in 222 DIGEST. On success, a new algorithm ID is stored in ALGORITHM_ID 223 and a pointer representhing this module is stored in MODULE. */ 224gcry_error_t gcry_md_register (gcry_md_spec_t *digest, 225 unsigned int *algorithm_id, 226 gcry_module_t *module) 227 /* */ _GCRY_ATTR_INTERNAL; 228 229/* Unregister the digest identified by ID, which must have been 230 registered with gcry_digest_register. */ 231void gcry_md_unregister (gcry_module_t module) 232 /* */ _GCRY_ATTR_INTERNAL; 233 234#if 0 /* keep Emacsens's auto-indent happy */ 235{ 236#endif 237#ifdef __cplusplus 238} 239#endif 240#endif 241