gc.h

Go to the documentation of this file.
00001 /* gc.h --- Header file for implementation agnostic crypto wrapper API.
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2007  Simon Josefsson
00003  *
00004  * This file is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as published
00006  * by the Free Software Foundation; either version 2.1, or (at your
00007  * option) any later version.
00008  *
00009  * This file is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this file; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  */
00020 
00021 #ifndef GC_H
00022 #define GC_H
00023 
00024 /* Get size_t. */
00025 # include <stddef.h>
00026 
00027 enum Gc_rc
00028 {
00029   GC_OK = 0,
00030   GC_MALLOC_ERROR,
00031   GC_INIT_ERROR,
00032   GC_RANDOM_ERROR,
00033   GC_INVALID_CIPHER,
00034   GC_INVALID_HASH,
00035   GC_PKCS5_INVALID_ITERATION_COUNT,
00036   GC_PKCS5_INVALID_DERIVED_KEY_LENGTH,
00037   GC_PKCS5_DERIVED_KEY_TOO_LONG
00038 };
00039 typedef enum Gc_rc Gc_rc;
00040 
00041 /* Hash types. */
00042 enum Gc_hash
00043 {
00044   GC_MD4,
00045   GC_MD5,
00046   GC_SHA1,
00047   GC_MD2,
00048   GC_RMD160,
00049   GC_SHA256,
00050   GC_SHA384,
00051   GC_SHA512
00052 };
00053 typedef enum Gc_hash Gc_hash;
00054 
00055 enum Gc_hash_mode
00056 {
00057   GC_HMAC = 1
00058 };
00059 typedef enum Gc_hash_mode Gc_hash_mode;
00060 
00061 typedef void *MHD_gc_hash_handle;
00062 
00063 #define GC_MD2_DIGEST_SIZE 16
00064 #define GC_MD4_DIGEST_SIZE 16
00065 #define GC_MD5_DIGEST_SIZE 16
00066 #define GC_RMD160_DIGEST_SIZE 20
00067 #define GC_SHA1_DIGEST_SIZE 20
00068 #define GC_SHA256_DIGEST_SIZE 32
00069 #define GC_SHA384_DIGEST_SIZE 48
00070 #define GC_SHA512_DIGEST_SIZE 64
00071 
00072 /* Cipher types. */
00073 enum Gc_cipher
00074 {
00075   GC_AES128,
00076   GC_AES192,
00077   GC_AES256,
00078   GC_3DES,
00079   GC_DES,
00080   GC_ARCFOUR128,
00081   GC_ARCFOUR40,
00082   GC_ARCTWO40,
00083   GC_CAMELLIA128,
00084   GC_CAMELLIA256
00085 };
00086 typedef enum Gc_cipher Gc_cipher;
00087 
00088 enum Gc_cipher_mode
00089 {
00090   GC_ECB,
00091   GC_CBC,
00092   GC_STREAM
00093 };
00094 typedef enum Gc_cipher_mode Gc_cipher_mode;
00095 
00096 typedef void *MHD_gc_cipher_handle;
00097 
00098 /* Call before respectively after any other functions. */
00099 Gc_rc MHD_gc_init (void);
00100 void MHD_gc_done (void);
00101 
00102 /* Memory allocation (avoid). */
00103 typedef void *(*MHD_gc_malloc_t) (size_t n);
00104 typedef int (*MHD_gc_secure_check_t) (const void *);
00105 typedef void *(*MHD_gc_realloc_t) (void *p, size_t n);
00106 typedef void (*MHD_gc_free_t) (void *);
00107 /* Randomness. */
00108 Gc_rc MHD_gc_nonce (char *data, size_t datalen);
00109 Gc_rc MHD_gc_pseudo_random (char *data, size_t datalen);
00110 
00111 /* Ciphers. */
00112 Gc_rc MHD_gc_cipher_open (Gc_cipher cipher,
00113                           Gc_cipher_mode mode,
00114                           MHD_gc_cipher_handle * outhandle);
00115 Gc_rc MHD_gc_cipher_setkey (MHD_gc_cipher_handle handle, size_t keylen,
00116                             const char *key);
00117 Gc_rc MHD_gc_cipher_setiv (MHD_gc_cipher_handle handle, size_t ivlen,
00118                            const char *iv);
00119 Gc_rc MHD_gc_cipher_encrypt_inline (MHD_gc_cipher_handle handle, size_t len,
00120                                     char *data);
00121 Gc_rc MHD_gc_cipher_decrypt_inline (MHD_gc_cipher_handle handle, size_t len,
00122                                     char *data);
00123 Gc_rc MHD_gc_cipher_close (MHD_gc_cipher_handle handle);
00124 
00125 /* Hashes. */
00126 
00127 Gc_rc MHD_gc_hash_open (Gc_hash hash,
00128                         Gc_hash_mode mode, MHD_gc_hash_handle * outhandle);
00129 Gc_rc MHD_gc_hash_clone (MHD_gc_hash_handle handle,
00130                          MHD_gc_hash_handle * outhandle);
00131 size_t MHD_gc_hash_digest_length (Gc_hash hash);
00132 void MHD_gc_hash_MHD_hmac_setkey (MHD_gc_hash_handle handle, size_t len,
00133                                   const char *key);
00134 void MHD_gc_hash_write (MHD_gc_hash_handle handle, size_t len,
00135                         const char *data);
00136 const char *MHD_gc_hash_read (MHD_gc_hash_handle handle);
00137 void MHD_gc_hash_close (MHD_gc_hash_handle handle);
00138 
00139 /* Compute a hash value over buffer IN of INLEN bytes size using the
00140  algorithm HASH, placing the result in the pre-allocated buffer OUT.
00141  The required size of OUT depends on HASH, and is generally
00142  GC_<HASH>_DIGEST_SIZE.  For example, for GC_MD5 the output buffer
00143  must be 16 bytes.  The return value is 0 (GC_OK) on success, or
00144  another Gc_rc error code. */
00145 Gc_rc MHD_gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen,
00146                           char *out);
00147 
00148 /* One-call interface. */
00149 Gc_rc MHD_gc_md2 (const void *in, size_t inlen, void *resbuf);
00150 Gc_rc MHD_gc_md4 (const void *in, size_t inlen, void *resbuf);
00151 Gc_rc MHD_gc_md5 (const void *in, size_t inlen, void *resbuf);
00152 Gc_rc MHD_gc_sha1 (const void *in, size_t inlen, void *resbuf);
00153 Gc_rc MHD_gc_MHD_hmac_md5 (const void *key,
00154                            size_t keylen, const void *in, size_t inlen,
00155                            char *resbuf);
00156 Gc_rc MHD_gc_MHD_hmac_sha1 (const void *key, size_t keylen, const void *in,
00157                             size_t inlen, char *resbuf);
00158 
00159 /* Derive cryptographic keys from a password P of length PLEN, with
00160  salt S of length SLEN, placing the result in pre-allocated buffer
00161  DK of length DKLEN.  An iteration count is specified in C, where a
00162  larger value means this function take more time (typical iteration
00163  counts are 1000-20000).  This function "stretches" the key to be
00164  exactly dkLen bytes long.  GC_OK is returned on success, otherwise
00165  an Gc_rc error code is returned.  */
00166 Gc_rc MHD_gc_pbkdf2_sha1 (const char *P,
00167                           size_t Plen,
00168                           const char *S,
00169                           size_t Slen, unsigned int c, char *DK,
00170                           size_t dkLen);
00171 
00172 #endif /* GC_H */

Generated on Tue May 19 23:21:07 2009 for GNU libmicrohttpd by  doxygen 1.5.8