home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / gcrypt-module.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-04-11  |  6.7 KB  |  227 lines

  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
  29. extern "C" {
  30. #if 0 /* keep Emacsens's auto-indent happy */
  31. }
  32. #endif
  33. #endif
  34.  
  35. /* This type represents a `module'.  */
  36. typedef struct gcry_module *gcry_module_t;
  37.  
  38. /* Check that the library fulfills the version requirement.  */
  39.  
  40. /* Type for the cipher_setkey function.  */
  41. typedef gcry_err_code_t (*gcry_cipher_setkey_t) (void *c,
  42.                          const unsigned char *key,
  43.                          unsigned keylen);
  44.  
  45. /* Type for the cipher_encrypt function.  */
  46. typedef void (*gcry_cipher_encrypt_t) (void *c,
  47.                        unsigned char *outbuf,
  48.                        const unsigned char *inbuf);
  49.  
  50. /* Type for the cipher_decrypt function.  */
  51. typedef void (*gcry_cipher_decrypt_t) (void *c,
  52.                        unsigned char *outbuf,
  53.                        const unsigned char *inbuf);
  54.  
  55. /* Type for the cipher_stencrypt function.  */
  56. typedef void (*gcry_cipher_stencrypt_t) (void *c,
  57.                      unsigned char *outbuf,
  58.                      const unsigned char *inbuf,
  59.                      unsigned int n);
  60.  
  61. /* Type for the cipher_stdecrypt function.  */
  62. typedef void (*gcry_cipher_stdecrypt_t) (void *c,
  63.                      unsigned char *outbuf,
  64.                      const unsigned char *inbuf,
  65.                      unsigned int n);
  66.  
  67. typedef struct gcry_cipher_oid_spec
  68. {
  69.   const char *oid;
  70.   int mode;
  71. } gcry_cipher_oid_spec_t;
  72.  
  73. /* Module specification structure for ciphers.  */
  74. typedef struct gcry_cipher_spec
  75. {
  76.   const char *name;
  77.   const char **aliases;
  78.   gcry_cipher_oid_spec_t *oids;
  79.   size_t blocksize;
  80.   size_t keylen;
  81.   size_t contextsize;
  82.   gcry_cipher_setkey_t setkey;
  83.   gcry_cipher_encrypt_t encrypt;
  84.   gcry_cipher_decrypt_t decrypt;
  85.   gcry_cipher_stencrypt_t stencrypt;
  86.   gcry_cipher_stdecrypt_t stdecrypt;
  87. } gcry_cipher_spec_t;
  88.  
  89. /* Register a new cipher module whose specification can be found in
  90.    CIPHER.  On success, a new algorithm ID is stored in ALGORITHM_ID
  91.    and a pointer representhing this module is stored in MODULE.  */
  92. gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *cipher,
  93.                    int *algorithm_id,
  94.                    gcry_module_t *module);
  95.  
  96. /* Unregister the cipher identified by MODULE, which must have been
  97.    registered with gcry_cipher_register.  */
  98. void gcry_cipher_unregister (gcry_module_t module);
  99.  
  100. /* ********************** */
  101.  
  102. /* Type for the pk_generate function.  */
  103. typedef gcry_err_code_t (*gcry_pk_generate_t) (int algo,
  104.                            unsigned int nbits,
  105.                            unsigned long use_e,
  106.                            gcry_mpi_t *skey,
  107.                            gcry_mpi_t **retfactors);
  108.  
  109. /* Type for the pk_check_secret_key function.  */
  110. typedef gcry_err_code_t (*gcry_pk_check_secret_key_t) (int algo,
  111.                                gcry_mpi_t *skey);
  112.  
  113. /* Type for the pk_encrypt function.  */
  114. typedef gcry_err_code_t (*gcry_pk_encrypt_t) (int algo,
  115.                           gcry_mpi_t *resarr,
  116.                           gcry_mpi_t data,
  117.                           gcry_mpi_t *pkey,
  118.                           int flags);
  119.  
  120. /* Type for the pk_decrypt function.  */
  121. typedef gcry_err_code_t (*gcry_pk_decrypt_t) (int algo,
  122.                           gcry_mpi_t *result,
  123.                           gcry_mpi_t *data,
  124.                           gcry_mpi_t *skey,
  125.                           int flags);
  126.  
  127. /* Type for the pk_sign function.  */
  128. typedef gcry_err_code_t (*gcry_pk_sign_t) (int algo,
  129.                        gcry_mpi_t *resarr,
  130.                        gcry_mpi_t data,
  131.                        gcry_mpi_t *skey);
  132.  
  133. /* Type for the pk_verify function.  */
  134. typedef gcry_err_code_t (*gcry_pk_verify_t) (int algo,
  135.                          gcry_mpi_t hash,
  136.                          gcry_mpi_t *data,
  137.                          gcry_mpi_t *pkey,
  138.                          int (*cmp) (void *, gcry_mpi_t),
  139.                          void *opaquev);
  140.  
  141. /* Type for the pk_get_nbits function.  */
  142. typedef unsigned (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey);
  143.  
  144. /* Module specification structure for message digests.  */
  145. typedef struct gcry_pk_spec
  146. {
  147.   const char *name;
  148.   const char **aliases;
  149.   const char *elements_pkey;
  150.   const char *elements_skey;
  151.   const char *elements_enc;
  152.   const char *elements_sig;
  153.   const char *elements_grip;
  154.   int use;
  155.   gcry_pk_generate_t generate;
  156.   gcry_pk_check_secret_key_t check_secret_key;
  157.   gcry_pk_encrypt_t encrypt;
  158.   gcry_pk_decrypt_t decrypt;
  159.   gcry_pk_sign_t sign;
  160.   gcry_pk_verify_t verify;
  161.   gcry_pk_get_nbits_t get_nbits;
  162. } gcry_pk_spec_t;
  163.  
  164. /* Register a new pubkey module whose specification can be found in
  165.    PUBKEY.  On success, a new algorithm ID is stored in ALGORITHM_ID
  166.    and a pointer representhing this module is stored in MODULE.  */
  167. gcry_error_t gcry_pk_register (gcry_pk_spec_t *pubkey,
  168.                    unsigned int *algorithm_id,
  169.                    gcry_module_t *module);
  170.  
  171. /* Unregister the pubkey identified by ID, which must have been
  172.    registered with gcry_pk_register.  */
  173. void gcry_pk_unregister (gcry_module_t module);
  174.  
  175. /* ********************** */
  176.  
  177. /* Type for the md_init function.  */
  178. typedef void (*gcry_md_init_t) (void *c);
  179.  
  180. /* Type for the md_write function.  */
  181. typedef void (*gcry_md_write_t) (void *c, const void *buf, size_t nbytes);
  182.  
  183. /* Type for the md_final function.  */
  184. typedef void (*gcry_md_final_t) (void *c);
  185.  
  186. /* Type for the md_read function.  */
  187. typedef unsigned char *(*gcry_md_read_t) (void *c);
  188.  
  189. typedef struct gcry_md_oid_spec
  190. {
  191.   const char *oidstring;
  192. } gcry_md_oid_spec_t;
  193.  
  194. /* Module specification structure for message digests.  */
  195. typedef struct gcry_md_spec
  196. {
  197.   const char *name;
  198.   unsigned char *asnoid;
  199.   int asnlen;
  200.   gcry_md_oid_spec_t *oids;
  201.   int mdlen;
  202.   gcry_md_init_t init;
  203.   gcry_md_write_t write;
  204.   gcry_md_final_t final;
  205.   gcry_md_read_t read;
  206.   size_t contextsize; /* allocate this amount of context */
  207. } gcry_md_spec_t;
  208.  
  209. /* Register a new digest module whose specification can be found in
  210.    DIGEST.  On success, a new algorithm ID is stored in ALGORITHM_ID
  211.    and a pointer representhing this module is stored in MODULE.  */
  212. gcry_error_t gcry_md_register (gcry_md_spec_t *digest,
  213.                    unsigned int *algorithm_id,
  214.                    gcry_module_t *module);
  215.  
  216. /* Unregister the digest identified by ID, which must have been
  217.    registered with gcry_digest_register.  */
  218. void gcry_md_unregister (gcry_module_t module);
  219.  
  220. #if 0 /* keep Emacsens's auto-indent happy */
  221. {
  222. #endif
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif
  227.