~ubuntu-branches/ubuntu/natty/libgcrypt11/natty-proposed

« back to all changes in this revision

Viewing changes to src/gcrypt.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2008-04-26 11:38:29 UTC
  • mto: (1.1.5 upstream) (2.1.2 lenny)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080426113829-1b2w4syxd8gzaj7d
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gcrypt.h -  GNU cryptographic library interface
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
3
 
 *               2004  Free Software Foundation, Inc.
4
 
 *
5
 
 * This file is part of Libgcrypt.
6
 
 *
7
 
 * Libgcrypt is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU Lesser General Public License as
9
 
 * published by the Free Software Foundation; either version 2.1 of
10
 
 * the License, or (at your option) any later version.
11
 
 *
12
 
 * Libgcrypt is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU Lesser General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20
 
 */
 
1
/* gcrypt.h -  GNU Cryptographic Library Interface              -*- c -*-
 
2
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
 
3
                 2007  Free Software Foundation, Inc.
 
4
  
 
5
   This file is part of Libgcrypt.
 
6
  
 
7
   Libgcrypt is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU Lesser General Public License as
 
9
   published by the Free Software Foundation; either version 2.1 of
 
10
   the License, or (at your option) any later version.
 
11
  
 
12
   Libgcrypt is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU Lesser General Public License for more details.
 
16
  
 
17
   You should have received a copy of the GNU Lesser General Public
 
18
   License along with this program; if not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
   File: src/gcrypt.h.  Generated from gcrypt.h.in by configure. */
21
21
 
22
22
#ifndef _GCRYPT_H
23
23
#define _GCRYPT_H
24
24
 
 
25
#include <stdlib.h>
25
26
#include <stdarg.h>
26
27
#include <string.h>
27
28
 
28
29
#include <gpg-error.h>
29
30
 
30
31
#include <sys/types.h>
31
 
#ifndef _WIN32
32
 
#include <sys/socket.h>
 
32
 
 
33
#if defined _WIN32 || defined __WIN32__
 
34
# include <winsock2.h>
 
35
# include <ws2tcpip.h>
 
36
#else
 
37
# include <sys/socket.h>
33
38
#endif /*!_WIN32*/
 
39
 
 
40
typedef socklen_t gcry_socklen_t;
 
41
 
34
42
#include <sys/time.h>
35
43
 
36
44
/* This is required for error code compatibility. */
47
55
   should not be used by a program because gcry_check_version() should
48
56
   return the same version.  The purpose of this macro is to let
49
57
   autoconf (using the AM_PATH_GCRYPT macro) check that this header
50
 
   matches the installed library.  Note: Do not edit the next line as
51
 
   configure may fix the string here.  */
52
 
#define GCRYPT_VERSION "1.2.3"
 
58
   matches the installed library.  */
 
59
#define GCRYPT_VERSION "1.4.1"
53
60
 
54
61
/* Internal: We can't use the convenience macros for the multi
55
62
   precision integer functions when building this library. */
76
83
#define _GCRY_GCC_ATTR_PURE  __attribute__ ((__pure__))
77
84
#endif
78
85
 
79
 
#if _GCRY_GCC_VERSION >= 300200
 
86
#if _GCRY_GCC_VERSION >= 30200
80
87
#define _GCRY_GCC_ATTR_MALLOC  __attribute__ ((__malloc__))
81
88
#endif
82
89
 
92
99
#define _GCRY_GCC_ATTR_MALLOC
93
100
#endif
94
101
 
 
102
/* Some members in a public type should only be used internally.
 
103
   There is no "internal" attribute, so we abuse the deprecated
 
104
   attribute to discourage external use.  */
 
105
#ifdef _GCRYPT_IN_LIBGCRYPT
 
106
#define _GCRY_ATTR_INTERNAL
 
107
#else
 
108
#define _GCRY_ATTR_INTERNAL     _GCRY_GCC_ATTR_DEPRECATED
 
109
#endif
 
110
 
95
111
/* Wrappers for the libgpg-error library.  */
96
112
 
97
113
typedef gpg_error_t gcry_error_t;
162
178
    GCRY_THREAD_OPTION_PTHREAD = 3
163
179
  };
164
180
 
165
 
/* Do avoid inclusing of too much W32 stuff, we redefine some types.  */
166
 
#ifdef _WIN32
167
 
#define _GCRY_PTH_FD_SET    void
168
 
#define _GCRY_PTH_SOCKADDR  void
169
 
#define _GCRY_PTH_SOCKLEN_T int
170
 
#define _GCRY_PTH_MSGHDR    void
171
 
#else
172
 
#define _GCRY_PTH_FD_SET    fd_set
173
 
#define _GCRY_PTH_SOCKADDR  struct sockaddr
174
 
#define _GCRY_PTH_SOCKLEN_T socklen_t
175
 
#define _GCRY_PTH_MSGHDR    struct msghdr
176
 
#endif
177
 
 
178
181
/* Wrapper for struct ath_ops.  */
179
182
struct gcry_thread_cbs
180
183
{
186
189
  int (*mutex_unlock) (void **priv);
187
190
  ssize_t (*read) (int fd, void *buf, size_t nbytes);
188
191
  ssize_t (*write) (int fd, const void *buf, size_t nbytes);
189
 
  ssize_t (*select) (int nfd, _GCRY_PTH_FD_SET *rset, _GCRY_PTH_FD_SET *wset,
190
 
                     _GCRY_PTH_FD_SET *eset, struct timeval *timeout);
191
 
  ssize_t (*waitpid) (pid_t pid, int *status, int options);
192
 
  int (*accept) (int s, _GCRY_PTH_SOCKADDR *addr,
193
 
                 _GCRY_PTH_SOCKLEN_T *length_ptr);
194
 
  int (*connect) (int s, _GCRY_PTH_SOCKADDR *addr,
195
 
                  _GCRY_PTH_SOCKLEN_T length);
196
 
  int (*sendmsg) (int s, const _GCRY_PTH_MSGHDR *msg, int flags);
197
 
  int (*recvmsg) (int s, _GCRY_PTH_MSGHDR *msg, int flags);
 
192
#ifdef _WIN32
 
193
  ssize_t (*select) (int nfd, void *rset, void *wset, void *eset,
 
194
                     struct timeval *timeout);
 
195
  ssize_t (*waitpid) (pid_t pid, int *status, int options);
 
196
  int (*accept) (int s, void  *addr, int *length_ptr);
 
197
  int (*connect) (int s, void *addr, gcry_socklen_t length);
 
198
  int (*sendmsg) (int s, const void *msg, int flags);
 
199
  int (*recvmsg) (int s, void *msg, int flags);
 
200
#else
 
201
  ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
 
202
                     struct timeval *timeout);
 
203
  ssize_t (*waitpid) (pid_t pid, int *status, int options);
 
204
  int (*accept) (int s, struct sockaddr *addr, gcry_socklen_t *length_ptr);
 
205
  int (*connect) (int s, struct sockaddr *addr, gcry_socklen_t length);
 
206
  int (*sendmsg) (int s, const struct msghdr *msg, int flags);
 
207
  int (*recvmsg) (int s, struct msghdr *msg, int flags);
 
208
#endif
198
209
};
199
210
 
 
211
#ifdef _WIN32
 
212
# define _GCRY_THREAD_OPTION_PTH_IMPL_NET                                     \
 
213
static ssize_t gcry_pth_select (int nfd, void *rset, void *wset,              \
 
214
                                void *eset, struct timeval *timeout)          \
 
215
  { return pth_select (nfd, rset, wset, eset, timeout); }                     \
 
216
static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options)         \
 
217
  { return pth_waitpid (pid, status, options); }                              \
 
218
static int gcry_pth_accept (int s, void *addr,                                \
 
219
                            gcry_socklen_t *length_ptr)                       \
 
220
  { return pth_accept (s, addr, length_ptr); }                                \
 
221
static int gcry_pth_connect (int s, void *addr,                               \
 
222
                             gcry_socklen_t length)                           \
 
223
  { return pth_connect (s, addr, length); }
 
224
#else /*!_WIN32*/
 
225
# define _GCRY_THREAD_OPTION_PTH_IMPL_NET                                     \
 
226
static ssize_t gcry_pth_select (int nfd, fd_set *rset, fd_set *wset,          \
 
227
                                fd_set *eset, struct timeval *timeout)        \
 
228
  { return pth_select (nfd, rset, wset, eset, timeout); }                     \
 
229
static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options)         \
 
230
  { return pth_waitpid (pid, status, options); }                              \
 
231
static int gcry_pth_accept (int s, struct sockaddr *addr,                     \
 
232
                            gcry_socklen_t *length_ptr)                       \
 
233
  { return pth_accept (s, addr, length_ptr); }                                \
 
234
static int gcry_pth_connect (int s, struct sockaddr *addr,                    \
 
235
                             gcry_socklen_t length)                           \
 
236
  { return pth_connect (s, addr, length); }
 
237
#endif /*!_WIN32*/
 
238
 
 
239
 
 
240
 
200
241
#define GCRY_THREAD_OPTION_PTH_IMPL                                           \
201
242
static int gcry_pth_init (void)                                               \
202
243
{ return (pth_init () == FALSE) ? errno : 0; }                                \
233
274
  { return pth_read (fd, buf, nbytes); }                                      \
234
275
static ssize_t gcry_pth_write (int fd, const void *buf, size_t nbytes)        \
235
276
  { return pth_write (fd, buf, nbytes); }                                     \
236
 
static ssize_t gcry_pth_select (int nfd, _GCRY_PTH_FD_SET *rset,              \
237
 
                                _GCRY_PTH_FD_SET *wset,                       \
238
 
                                _GCRY_PTH_FD_SET *eset,                       \
239
 
                                struct timeval *timeout)                      \
240
 
  { return pth_select (nfd, rset, wset, eset, timeout); }                     \
241
 
static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options)         \
242
 
  { return pth_waitpid (pid, status, options); }                              \
243
 
static int gcry_pth_accept (int s, _GCRY_PTH_SOCKADDR *addr,                  \
244
 
                            _GCRY_PTH_SOCKLEN_T *length_ptr)                  \
245
 
  { return pth_accept (s, addr, length_ptr); }                                \
246
 
static int gcry_pth_connect (int s, _GCRY_PTH_SOCKADDR *addr,                 \
247
 
                             _GCRY_PTH_SOCKLEN_T length)                      \
248
 
  { return pth_connect (s, addr, length); }                                   \
 
277
_GCRY_THREAD_OPTION_PTH_IMPL_NET                                              \
249
278
                                                                              \
250
279
/* FIXME: GNU Pth is missing pth_sendmsg and pth_recvmsg.  */                 \
251
280
static struct gcry_thread_cbs gcry_threads_pth = { GCRY_THREAD_OPTION_PTH,    \
252
281
  gcry_pth_init, gcry_pth_mutex_init, gcry_pth_mutex_destroy,                 \
253
282
  gcry_pth_mutex_lock, gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write,  \
254
 
  gcry_pth_select, gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect }
 
283
  gcry_pth_select, gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect,       \
 
284
  NULL, NULL }
 
285
 
255
286
 
256
287
#define GCRY_THREAD_OPTION_PTHREAD_IMPL                                       \
257
288
static int gcry_pthread_mutex_init (void **priv)                              \
258
289
{                                                                             \
259
290
  int err = 0;                                                                \
260
 
  pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));                  \
 
291
  pthread_mutex_t *lock = (pthread_mutex_t*)malloc (sizeof (pthread_mutex_t));\
261
292
                                                                              \
262
293
  if (!lock)                                                                  \
263
294
    err = ENOMEM;                                                             \
272
303
  return err;                                                                 \
273
304
}                                                                             \
274
305
static int gcry_pthread_mutex_destroy (void **lock)                           \
275
 
  { int err = pthread_mutex_destroy (*lock);  free (*lock); return err; }     \
 
306
  { int err = pthread_mutex_destroy ((pthread_mutex_t*)*lock);                \
 
307
    free (*lock); return err; }                                               \
276
308
static int gcry_pthread_mutex_lock (void **lock)                              \
277
 
  { return pthread_mutex_lock (*lock); }                                      \
 
309
  { return pthread_mutex_lock ((pthread_mutex_t*)*lock); }                    \
278
310
static int gcry_pthread_mutex_unlock (void **lock)                            \
279
 
  { return pthread_mutex_unlock (*lock); }                                    \
 
311
  { return pthread_mutex_unlock ((pthread_mutex_t*)*lock); }                  \
280
312
                                                                              \
281
313
static struct gcry_thread_cbs gcry_threads_pthread =                          \
282
314
{ GCRY_THREAD_OPTION_PTHREAD, NULL,                                           \
283
315
  gcry_pthread_mutex_init, gcry_pthread_mutex_destroy,                        \
284
 
  gcry_pthread_mutex_lock, gcry_pthread_mutex_unlock }
 
316
  gcry_pthread_mutex_lock, gcry_pthread_mutex_unlock,                         \
 
317
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
285
318
 
286
319
 
287
320
/* The data object used to hold a multi precision integer.  */
288
321
struct gcry_mpi;
289
322
typedef struct gcry_mpi *gcry_mpi_t;
290
323
 
 
324
#ifndef GCRYPT_NO_DEPRECATED
291
325
typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED;
292
326
typedef struct gcry_mpi *GcryMPI _GCRY_GCC_ATTR_DEPRECATED;
 
327
#endif
293
328
 
294
329
 
295
330
 
347
382
    GCRYCTL_SET_RANDOM_SEED_FILE = 45,
348
383
    GCRYCTL_UPDATE_RANDOM_SEED_FILE = 46,
349
384
    GCRYCTL_SET_THREAD_CBS = 47,
350
 
    GCRYCTL_FAST_POLL = 48
 
385
    GCRYCTL_FAST_POLL = 48,
 
386
    GCRYCTL_SET_RANDOM_DAEMON_SOCKET = 49,
 
387
    GCRYCTL_USE_RANDOM_DAEMON = 50,
 
388
    GCRYCTL_FAKED_RANDOM_P = 51,
 
389
    GCRYCTL_SET_RNDEGD_SOCKET = 52,
 
390
    GCRYCTL_PRINT_CONFIG = 53
351
391
  };
352
392
 
353
393
/* Perform various operations defined by CMD. */
361
401
struct gcry_sexp;
362
402
typedef struct gcry_sexp *gcry_sexp_t;
363
403
 
 
404
#ifndef GCRYPT_NO_DEPRECATED
364
405
typedef struct gcry_sexp *GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED;
365
406
typedef struct gcry_sexp *GcrySexp _GCRY_GCC_ATTR_DEPRECATED;
 
407
#endif
366
408
 
367
409
/* The possible values for the S-expression format. */
368
410
enum gcry_sexp_format
399
441
/* Like gcry_sexp_build, but uses an array instead of variable
400
442
   function arguments.  */
401
443
gcry_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
402
 
                                   const char *format, void **arg_list);
 
444
                                    const char *format, void **arg_list);
403
445
 
404
446
/* Release the S-expression object SEXP */
405
447
void gcry_sexp_release (gcry_sexp_t sexp);
464
506
const char *gcry_sexp_nth_data (const gcry_sexp_t list, int number,
465
507
                                size_t *datalen);
466
508
 
 
509
/* This function is used to get and convert data from a LIST.  The
 
510
   data is assumed to be a Nul terminated string.  The caller must
 
511
   release the returned value using `gcry_free'.  If there is no data
 
512
   at the given index, the index represents a list or the value can't
 
513
   be converted to a string, `NULL' is returned.  */
 
514
char *gcry_sexp_nth_string (gcry_sexp_t list, int number);
 
515
 
467
516
/* This function is used to get and convert data from a LIST. This
468
517
   data is assumed to be an MPI stored in the format described by
469
518
   MPIFMT and returned as a standard Libgcrypt MPI.  The caller must
720
769
struct gcry_cipher_handle;
721
770
typedef struct gcry_cipher_handle *gcry_cipher_hd_t;
722
771
 
 
772
#ifndef GCRYPT_NO_DEPRECATED
723
773
typedef struct gcry_cipher_handle *GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED;
724
774
typedef struct gcry_cipher_handle *GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED;
 
775
#endif
725
776
 
726
777
/* All symmetric encryption algorithms are identified by their IDs.
727
778
   More IDs may be registered at runtime. */
747
798
    GCRY_CIPHER_SERPENT192  = 305,
748
799
    GCRY_CIPHER_SERPENT256  = 306,
749
800
    GCRY_CIPHER_RFC2268_40  = 307,  /* Ron's Cipher 2 (40 bit). */
750
 
    GCRY_CIPHER_RFC2268_128 = 308   /* Ron's Cipher 2 (128 bit). */
 
801
    GCRY_CIPHER_RFC2268_128 = 308,  /* Ron's Cipher 2 (128 bit). */
 
802
    GCRY_CIPHER_SEED        = 309,  /* 128 bit cipher described in RFC4269. */
 
803
    GCRY_CIPHER_CAMELLIA128 = 310,
 
804
    GCRY_CIPHER_CAMELLIA192 = 311,
 
805
    GCRY_CIPHER_CAMELLIA256 = 312
751
806
  };
752
807
 
753
808
/* The Rijndael algorithm is basically AES, so provide some macros. */
800
855
gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer,
801
856
                                   size_t *nbytes);
802
857
 
803
 
/* Map the cipher algorithm id ALGO to a string representation of that
804
 
   algorithm name.  For unknown algorithms this functions returns an
805
 
   empty string. */
806
 
const char *gcry_cipher_algo_name (int algo) _GCRY_GCC_ATTR_PURE;
 
858
/* Map the cipher algorithm whose ID is contained in ALGORITHM to a
 
859
   string representation of the algorithm name.  For unknown algorithm
 
860
   IDs this function returns "?".  */
 
861
const char *gcry_cipher_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
807
862
 
808
863
/* Map the algorithm name NAME to an cipher algorithm ID.  Return 0 if
809
864
   the algorithm name is not known. */
887
942
    GCRY_PK_RSA_S = 3,      /* deprecated */
888
943
    GCRY_PK_ELG_E = 16,     /* use only for OpenPGP */
889
944
    GCRY_PK_DSA   = 17,
890
 
    GCRY_PK_ELG   = 20
 
945
    GCRY_PK_ELG   = 20,
 
946
    GCRY_PK_ECDSA = 301     /* Experimental implementation; not for
 
947
                               production. */
891
948
  };
892
949
 
893
950
/* Flags describing usage capabilities of a PK algorithm. */
894
 
#define GCRY_PK_USAGE_SIGN 1
895
 
#define GCRY_PK_USAGE_ENCR 2
 
951
#define GCRY_PK_USAGE_SIGN 1   /* Good for signatures. */            
 
952
#define GCRY_PK_USAGE_ENCR 2   /* Good for encryption. */            
 
953
#define GCRY_PK_USAGE_CERT 4   /* Good to certify other keys. */
 
954
#define GCRY_PK_USAGE_AUTH 8   /* Good for authentication. */        
 
955
#define GCRY_PK_USAGE_UNKN 128 /* Unknown usage flag. */          
896
956
 
897
957
/* Encrypt the DATA using the public key PKEY and store the result as
898
958
   a newly created S-expression at RESULT. */
928
988
gcry_error_t gcry_pk_algo_info (int algo, int what,
929
989
                                void *buffer, size_t *nbytes);
930
990
 
931
 
/* Map the public key algorithm id ALGO to a string representation of the
932
 
   algorithm name.  For unknown algorithms this functions returns an
933
 
   empty string. */
934
 
const char *gcry_pk_algo_name (int algo) _GCRY_GCC_ATTR_PURE;
 
991
/* Map the public key algorithm whose ID is contained in ALGORITHM to
 
992
   a string representation of the algorithm name.  For unknown
 
993
   algorithm IDs this functions returns "?". */
 
994
const char *gcry_pk_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
935
995
 
936
996
/* Map the algorithm NAME to a public key algorithm Id.  Return 0 if
937
997
   the algorithm name is not known. */
957
1017
   *LIST_LENGTH, *LIST_LENGTH is updated to the correct number.  */
958
1018
gcry_error_t gcry_pk_list (int *list, int *list_length);
959
1019
 
 
1020
 
 
1021
 
 
1022
/************************************
 
1023
 *                                  *
 
1024
 *   cryptograhic hash functions    *
 
1025
 *                                  *
 
1026
 ************************************/
 
1027
 
 
1028
/* Algorithm IDs for the hash functions we know about. Not all of them
 
1029
   are implemnted. */
 
1030
enum gcry_md_algos
 
1031
  {
 
1032
    GCRY_MD_NONE    = 0,  
 
1033
    GCRY_MD_MD5     = 1,
 
1034
    GCRY_MD_SHA1    = 2,
 
1035
    GCRY_MD_RMD160  = 3,
 
1036
    GCRY_MD_MD2     = 5,
 
1037
    GCRY_MD_TIGER   = 6,   /* TIGER/192. */
 
1038
    GCRY_MD_HAVAL   = 7,   /* HAVAL, 5 pass, 160 bit. */
 
1039
    GCRY_MD_SHA256  = 8,
 
1040
    GCRY_MD_SHA384  = 9,
 
1041
    GCRY_MD_SHA512  = 10,
 
1042
    GCRY_MD_SHA224  = 11,
 
1043
    GCRY_MD_MD4     = 301,
 
1044
    GCRY_MD_CRC32               = 302,
 
1045
    GCRY_MD_CRC32_RFC1510       = 303,
 
1046
    GCRY_MD_CRC24_RFC2440       = 304,
 
1047
    GCRY_MD_WHIRLPOOL = 305
 
1048
  };
 
1049
 
 
1050
/* Flags used with the open function.  */
 
1051
enum gcry_md_flags
 
1052
  {
 
1053
    GCRY_MD_FLAG_SECURE = 1,  /* Allocate all buffers in "secure"
 
1054
                                 memory.  */
 
1055
    GCRY_MD_FLAG_HMAC   = 2   /* Make an HMAC out of this
 
1056
                                 algorithm.  */
 
1057
  };
 
1058
 
 
1059
/* Forward declaration.  */
 
1060
struct gcry_md_context;
 
1061
 
 
1062
/* This object is used to hold a handle to a message digest object.
 
1063
   This structure is private - only to be used by the public gcry_md_*
 
1064
   macros.  */
 
1065
typedef struct gcry_md_handle 
 
1066
{
 
1067
  /* Actual context.  */
 
1068
  struct gcry_md_context *ctx;
 
1069
  
 
1070
  /* Buffer management.  */
 
1071
  int  bufpos;
 
1072
  int  bufsize;
 
1073
  unsigned char buf[1];
 
1074
} *gcry_md_hd_t;
 
1075
 
 
1076
/* Compatibility types, do not use them.  */
 
1077
#ifndef GCRYPT_NO_DEPRECATED
 
1078
typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED;
 
1079
typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED;
 
1080
#endif
 
1081
 
 
1082
/* Create a message digest object for algorithm ALGO.  FLAGS may be
 
1083
   given as an bitwise OR of the gcry_md_flags values.  ALGO may be
 
1084
   given as 0 if the algorithms to be used are later set using
 
1085
   gcry_md_enable.  */
 
1086
gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags);
 
1087
 
 
1088
/* Release the message digest object HD.  */
 
1089
void gcry_md_close (gcry_md_hd_t hd);
 
1090
 
 
1091
/* Add the message digest algorithm ALGO to the digest object HD.  */
 
1092
gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo);
 
1093
 
 
1094
/* Create a new digest object as an exact copy of the object HD.  */
 
1095
gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd);
 
1096
 
 
1097
/* Reset the digest object HD to its initial state.  */
 
1098
void gcry_md_reset (gcry_md_hd_t hd);
 
1099
 
 
1100
/* Perform various operations on the digest object HD. */
 
1101
gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd,
 
1102
                          void *buffer, size_t buflen);
 
1103
 
 
1104
/* Pass LENGTH bytes of data in BUFFER to the digest object HD so that
 
1105
   it can update the digest values.  This is the actual hash
 
1106
   function. */
 
1107
void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length);
 
1108
 
 
1109
/* Read out the final digest from HD return the digest value for
 
1110
   algorithm ALGO. */
 
1111
unsigned char *gcry_md_read (gcry_md_hd_t hd, int algo);
 
1112
 
 
1113
/* Convenience function to calculate the hash from the data in BUFFER
 
1114
   of size LENGTH using the algorithm ALGO avoiding the creating of a
 
1115
   hash object.  The hash is returned in the caller provided buffer
 
1116
   DIGEST which must be large enough to hold the digest of the given
 
1117
   algorithm. */
 
1118
void gcry_md_hash_buffer (int algo, void *digest,
 
1119
                          const void *buffer, size_t length);
 
1120
 
 
1121
/* Retrieve the algorithm used with HD.  This does not work reliable
 
1122
   if more than one algorithm is enabled in HD. */
 
1123
int gcry_md_get_algo (gcry_md_hd_t hd);
 
1124
 
 
1125
/* Retrieve the length in bytes of the digest yielded by algorithm
 
1126
   ALGO. */
 
1127
unsigned int gcry_md_get_algo_dlen (int algo);
 
1128
 
 
1129
/* Return true if the the algorithm ALGO is enabled in the digest
 
1130
   object A. */
 
1131
int gcry_md_is_enabled (gcry_md_hd_t a, int algo);
 
1132
 
 
1133
/* Return true if the digest object A is allocated in "secure" memory. */
 
1134
int gcry_md_is_secure (gcry_md_hd_t a);
 
1135
 
 
1136
/* Retrieve various information about the object H.  */
 
1137
gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer,
 
1138
                          size_t *nbytes);
 
1139
 
 
1140
/* Retrieve various information about the algorithm ALGO.  */
 
1141
gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer,
 
1142
                               size_t *nbytes);
 
1143
 
 
1144
/* Map the digest algorithm id ALGO to a string representation of the
 
1145
   algorithm name.  For unknown algorithms this functions returns
 
1146
   "?". */
 
1147
const char *gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE;
 
1148
 
 
1149
/* Map the algorithm NAME to a digest algorithm Id.  Return 0 if
 
1150
   the algorithm name is not known. */
 
1151
int gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
 
1152
 
 
1153
/* For use with the HMAC feature, the set MAC key to the KEY of
 
1154
   KEYLEN. */
 
1155
gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen);
 
1156
 
 
1157
/* Start or stop debugging for digest handle HD; i.e. create a file
 
1158
   named dbgmd-<n>.<suffix> while hashing.  If SUFFIX is NULL,
 
1159
   debugging stops and the file will be closed. */
 
1160
void gcry_md_debug (gcry_md_hd_t hd, const char *suffix);
 
1161
 
 
1162
 
 
1163
/* Update the hash(s) of H with the character C.  This is a buffered
 
1164
   version of the gcry_md_write function. */
 
1165
#define gcry_md_putc(h,c)  \
 
1166
            do {                                          \
 
1167
                gcry_md_hd_t h__ = (h);                   \
 
1168
                if( (h__)->bufpos == (h__)->bufsize )     \
 
1169
                    gcry_md_write( (h__), NULL, 0 );      \
 
1170
                (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
 
1171
            } while(0)
 
1172
 
 
1173
/* Finalize the digest calculation.  This is not really needed because
 
1174
   gcry_md_read() does this implicitly. */
 
1175
#define gcry_md_final(a) \
 
1176
            gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0)
 
1177
 
 
1178
/* Return 0 if the algorithm A is available for use. */
 
1179
#define gcry_md_test_algo(a) \
 
1180
            gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
 
1181
 
 
1182
/* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N
 
1183
   must point to size_t variable with the available size of buffer B.
 
1184
   After return it will receive the actual size of the returned
 
1185
   OID. */
 
1186
#define gcry_md_get_asnoid(a,b,n) \
 
1187
            gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n))
 
1188
 
 
1189
/* Enable debugging for digest object A; i.e. create files named
 
1190
   dbgmd-<n>.<string> while hashing.  B is a string used as the suffix
 
1191
   for the filename.  This macro is deprecated, use gcry_md_debug. */
 
1192
#ifndef GCRYPT_NO_DEPRECATED
 
1193
#define gcry_md_start_debug(a,b) \
 
1194
            gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 )
 
1195
 
 
1196
/* Disable the debugging of A.  This macro is deprecated, use
 
1197
   gcry_md_debug.  */
 
1198
#define gcry_md_stop_debug(a,b) \
 
1199
            gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 )
 
1200
#endif
 
1201
 
 
1202
/* Get a list consisting of the IDs of the loaded message digest
 
1203
   modules.  If LIST is zero, write the number of loaded message
 
1204
   digest modules to LIST_LENGTH and return.  If LIST is non-zero, the
 
1205
   first *LIST_LENGTH algorithm IDs are stored in LIST, which must be
 
1206
   of according size.  In case there are less message digest modules
 
1207
   than *LIST_LENGTH, *LIST_LENGTH is updated to the correct
 
1208
   number.  */
 
1209
gcry_error_t gcry_md_list (int *list, int *list_length);
 
1210
 
 
1211
 
 
1212
 
960
1213
/* Alternative interface for asymetric cryptography.  */
961
1214
 
962
1215
/* The algorithm IDs. */
977
1230
  }
978
1231
gcry_ac_key_type_t;
979
1232
 
 
1233
/* Encoding methods.  */
 
1234
typedef enum gcry_ac_em
 
1235
  {
 
1236
    GCRY_AC_EME_PKCS_V1_5,
 
1237
    GCRY_AC_EMSA_PKCS_V1_5
 
1238
  }
 
1239
gcry_ac_em_t;
 
1240
 
 
1241
/* Encryption and Signature schemes.  */
 
1242
typedef enum gcry_ac_scheme
 
1243
  {
 
1244
    GCRY_AC_ES_PKCS_V1_5,
 
1245
    GCRY_AC_SSA_PKCS_V1_5
 
1246
  }
 
1247
gcry_ac_scheme_t;
 
1248
 
980
1249
/* AC data.  */
981
1250
#define GCRY_AC_FLAG_DEALLOC     (1 << 0)
982
1251
#define GCRY_AC_FLAG_COPY        (1 << 1)
997
1266
   performing cryptographic operations.  */
998
1267
typedef struct gcry_ac_handle *gcry_ac_handle_t;
999
1268
 
 
1269
typedef gpg_error_t (*gcry_ac_data_read_cb_t) (void *opaque,
 
1270
                                               unsigned char *buffer,
 
1271
                                               size_t *buffer_n);
 
1272
 
 
1273
typedef gpg_error_t (*gcry_ac_data_write_cb_t) (void *opaque,
 
1274
                                                unsigned char *buffer,
 
1275
                                                size_t buffer_n);
 
1276
 
 
1277
typedef enum
 
1278
  {
 
1279
    GCRY_AC_IO_READABLE,
 
1280
    GCRY_AC_IO_WRITABLE
 
1281
  }
 
1282
gcry_ac_io_mode_t;
 
1283
 
 
1284
typedef enum
 
1285
  {
 
1286
    GCRY_AC_IO_STRING,
 
1287
    GCRY_AC_IO_CALLBACK
 
1288
  }
 
1289
gcry_ac_io_type_t;
 
1290
 
 
1291
typedef struct gcry_ac_io
 
1292
{
 
1293
  /* This is an INTERNAL structure, do NOT use manually.  */
 
1294
  gcry_ac_io_mode_t mode _GCRY_ATTR_INTERNAL;
 
1295
  gcry_ac_io_type_t type _GCRY_ATTR_INTERNAL;
 
1296
  union
 
1297
  {
 
1298
    union
 
1299
    {
 
1300
      struct
 
1301
      {
 
1302
        gcry_ac_data_read_cb_t cb;
 
1303
        void *opaque;
 
1304
      } callback;
 
1305
      struct
 
1306
      {
 
1307
        unsigned char *data;
 
1308
        size_t data_n;
 
1309
      } string;
 
1310
      void *opaque;
 
1311
    } readable;
 
1312
    union
 
1313
    {
 
1314
      struct
 
1315
      {
 
1316
        gcry_ac_data_write_cb_t cb;
 
1317
        void *opaque;
 
1318
      } callback;
 
1319
      struct
 
1320
      {
 
1321
        unsigned char **data;
 
1322
        size_t *data_n;
 
1323
      } string;
 
1324
      void *opaque;
 
1325
    } writable;
 
1326
  } io _GCRY_ATTR_INTERNAL;
 
1327
}
 
1328
gcry_ac_io_t;
 
1329
 
1000
1330
/* The caller of gcry_ac_key_pair_generate can provide one of these
1001
1331
   structures in order to influence the key generation process in an
1002
1332
   algorithm-specific way.  */
1005
1335
  gcry_mpi_t e;                 /* E to use.  */
1006
1336
} gcry_ac_key_spec_rsa_t;
1007
1337
 
 
1338
/* Structure used for passing data to the implementation of the
 
1339
   `EME-PKCS-V1_5' encoding method.  */
 
1340
typedef struct gcry_ac_eme_pkcs_v1_5
 
1341
{
 
1342
  size_t key_size;
 
1343
} gcry_ac_eme_pkcs_v1_5_t;
 
1344
 
 
1345
typedef enum gcry_md_algos gcry_md_algo_t;
 
1346
 
 
1347
/* Structure used for passing data to the implementation of the
 
1348
   `EMSA-PKCS-V1_5' encoding method.  */
 
1349
typedef struct gcry_ac_emsa_pkcs_v1_5
 
1350
{
 
1351
  gcry_md_algo_t md;
 
1352
  size_t em_n;
 
1353
} gcry_ac_emsa_pkcs_v1_5_t;
 
1354
 
 
1355
/* Structure used for passing data to the implementation of the
 
1356
   `SSA-PKCS-V1_5' signature scheme.  */
 
1357
typedef struct gcry_ac_ssa_pkcs_v1_5
 
1358
{
 
1359
  gcry_md_algo_t md;
 
1360
} gcry_ac_ssa_pkcs_v1_5_t;
 
1361
 
1008
1362
/* Returns a new, empty data set in DATA.  */
1009
1363
gcry_error_t gcry_ac_data_new (gcry_ac_data_t *data);
1010
1364
 
1044
1398
                                     unsigned int idx,
1045
1399
                                     const char **name, gcry_mpi_t *mpi);
1046
1400
 
 
1401
/* Convert the data set DATA into a new S-Expression, which is to be
 
1402
   stored in SEXP, according to the identifiers contained in
 
1403
   IDENTIFIERS.  */
 
1404
gcry_error_t gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp,
 
1405
                                   const char **identifiers);
 
1406
 
 
1407
/* Create a new data set, which is to be stored in DATA_SET, from the
 
1408
   S-Expression SEXP, according to the identifiers contained in
 
1409
   IDENTIFIERS.  */
 
1410
gcry_error_t gcry_ac_data_from_sexp (gcry_ac_data_t *data, gcry_sexp_t sexp,
 
1411
                                     const char **identifiers);
 
1412
 
 
1413
/* Initialize AC_IO according to MODE, TYPE and the variable list of
 
1414
   arguments.  The list of variable arguments to specify depends on
 
1415
   the given TYPE.  */
 
1416
void gcry_ac_io_init (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode,
 
1417
                      gcry_ac_io_type_t type, ...);
 
1418
 
 
1419
/* Initialize AC_IO according to MODE, TYPE and the variable list of
 
1420
   arguments AP.  The list of variable arguments to specify depends on
 
1421
   the given TYPE.  */
 
1422
void gcry_ac_io_init_va (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode,
 
1423
                         gcry_ac_io_type_t type, va_list ap);
 
1424
 
1047
1425
/* Create a new ac handle.  */
1048
1426
gcry_error_t gcry_ac_open (gcry_ac_handle_t *handle,
1049
1427
                           gcry_ac_id_t algorithm, unsigned int flags);
1090
1468
/* Destroy a key pair.  */
1091
1469
void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair);
1092
1470
 
 
1471
/* Encodes a message according to the encoding method METHOD.  OPTIONS
 
1472
   must be a pointer to a method-specific structure
 
1473
   (gcry_ac_em*_t).  */
 
1474
gcry_error_t gcry_ac_data_encode (gcry_ac_em_t method,
 
1475
                                  unsigned int flags, void *options,
 
1476
                                  gcry_ac_io_t *io_read,
 
1477
                                  gcry_ac_io_t *io_write);
 
1478
 
 
1479
/* Decodes a message according to the encoding method METHOD.  OPTIONS
 
1480
   must be a pointer to a method-specific structure
 
1481
   (gcry_ac_em*_t).  */
 
1482
gcry_error_t gcry_ac_data_decode (gcry_ac_em_t method,
 
1483
                                  unsigned int flags, void *options,
 
1484
                                  gcry_ac_io_t *io_read,
 
1485
                                  gcry_ac_io_t *io_write);
 
1486
 
1093
1487
/* Encrypt the plain text MPI value DATA_PLAIN with the key KEY under
1094
1488
   the control of the flags FLAGS and store the resulting data set
1095
1489
   into DATA_ENCRYPTED.  */
1123
1517
                                  gcry_mpi_t data,
1124
1518
                                  gcry_ac_data_t data_signature);
1125
1519
 
 
1520
/* Encrypts the plain text readable from IO_MESSAGE through HANDLE
 
1521
   with the public key KEY according to SCHEME, FLAGS and OPTS.  If
 
1522
   OPTS is not NULL, it has to be a pointer to a structure specific to
 
1523
   the chosen scheme (gcry_ac_es_*_t).  The encrypted message is
 
1524
   written to IO_CIPHER. */
 
1525
gcry_error_t gcry_ac_data_encrypt_scheme (gcry_ac_handle_t handle,
 
1526
                                          gcry_ac_scheme_t scheme,
 
1527
                                          unsigned int flags, void *opts,
 
1528
                                          gcry_ac_key_t key,
 
1529
                                          gcry_ac_io_t *io_message,
 
1530
                                          gcry_ac_io_t *io_cipher);
 
1531
 
 
1532
/* Decrypts the cipher text readable from IO_CIPHER through HANDLE
 
1533
   with the secret key KEY according to SCHEME, @var{flags} and OPTS.
 
1534
   If OPTS is not NULL, it has to be a pointer to a structure specific
 
1535
   to the chosen scheme (gcry_ac_es_*_t).  The decrypted message is
 
1536
   written to IO_MESSAGE.  */
 
1537
gcry_error_t gcry_ac_data_decrypt_scheme (gcry_ac_handle_t handle,
 
1538
                                          gcry_ac_scheme_t scheme,
 
1539
                                          unsigned int flags, void *opts,
 
1540
                                          gcry_ac_key_t key,
 
1541
                                          gcry_ac_io_t *io_cipher,
 
1542
                                          gcry_ac_io_t *io_message);
 
1543
 
 
1544
/* Signs the message readable from IO_MESSAGE through HANDLE with the
 
1545
   secret key KEY according to SCHEME, FLAGS and OPTS.  If OPTS is not
 
1546
   NULL, it has to be a pointer to a structure specific to the chosen
 
1547
   scheme (gcry_ac_ssa_*_t).  The signature is written to
 
1548
   IO_SIGNATURE.  */
 
1549
gcry_error_t gcry_ac_data_sign_scheme (gcry_ac_handle_t handle,
 
1550
                                       gcry_ac_scheme_t scheme,
 
1551
                                       unsigned int flags, void *opts,
 
1552
                                       gcry_ac_key_t key,
 
1553
                                       gcry_ac_io_t *io_message,
 
1554
                                       gcry_ac_io_t *io_signature);
 
1555
 
 
1556
/* Verifies through HANDLE that the signature readable from
 
1557
   IO_SIGNATURE is indeed the result of signing the message readable
 
1558
   from IO_MESSAGE with the secret key belonging to the public key KEY
 
1559
   according to SCHEME and OPTS.  If OPTS is not NULL, it has to be an
 
1560
   anonymous structure (gcry_ac_ssa_*_t) specific to the chosen
 
1561
   scheme.  */
 
1562
gcry_error_t gcry_ac_data_verify_scheme (gcry_ac_handle_t handle,
 
1563
                                         gcry_ac_scheme_t scheme,
 
1564
                                         unsigned int flags, void *opts,
 
1565
                                         gcry_ac_key_t key,
 
1566
                                         gcry_ac_io_t *io_message,
 
1567
                                         gcry_ac_io_t *io_signature);
 
1568
 
1126
1569
/* Store the textual representation of the algorithm whose id is given
1127
 
   in ALGORITHM in NAME.  */
 
1570
   in ALGORITHM in NAME.  This function is deprecated; use
 
1571
   gcry_pk_algo_name. */
 
1572
#ifndef GCRYPT_NO_DEPRECATED
1128
1573
gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t algorithm,
1129
 
                                const char **name);
1130
 
 
 
1574
                                 const char **name) 
 
1575
     /* */                      _GCRY_GCC_ATTR_DEPRECATED;
1131
1576
/* Store the numeric ID of the algorithm whose textual representation
1132
 
   is contained in NAME in ALGORITHM.  */
 
1577
   is contained in NAME in ALGORITHM.  This function is deprecated;
 
1578
   use gcry_pk_map_name. */
1133
1579
gcry_error_t gcry_ac_name_to_id (const char *name,
1134
 
                                gcry_ac_id_t *algorithm);
1135
 
 
1136
 
 
1137
 
 
1138
 
/************************************
1139
 
 *                                  *
1140
 
 *   cryptograhic hash functions    *
1141
 
 *                                  *
1142
 
 ************************************/
1143
 
 
1144
 
/* Algorithm IDs for the hash functions we know about. Not all of them
1145
 
   are implemnted. */
1146
 
enum gcry_md_algos
1147
 
  {
1148
 
    GCRY_MD_NONE    = 0,  
1149
 
    GCRY_MD_MD5     = 1,
1150
 
    GCRY_MD_SHA1    = 2,
1151
 
    GCRY_MD_RMD160  = 3,
1152
 
    GCRY_MD_MD2     = 5,
1153
 
    GCRY_MD_TIGER   = 6,   /* TIGER/192. */
1154
 
    GCRY_MD_HAVAL   = 7,   /* HAVAL, 5 pass, 160 bit. */
1155
 
    GCRY_MD_SHA256  = 8,
1156
 
    GCRY_MD_SHA384  = 9,
1157
 
    GCRY_MD_SHA512  = 10,
1158
 
    GCRY_MD_MD4     = 301,
1159
 
    GCRY_MD_CRC32               = 302,
1160
 
    GCRY_MD_CRC32_RFC1510       = 303,
1161
 
    GCRY_MD_CRC24_RFC2440       = 304
1162
 
  };
1163
 
 
1164
 
/* Flags used with the open function.  */
1165
 
enum gcry_md_flags
1166
 
  {
1167
 
    GCRY_MD_FLAG_SECURE = 1,  /* Allocate all buffers in "secure"
1168
 
                                 memory.  */
1169
 
    GCRY_MD_FLAG_HMAC   = 2   /* Make an HMAC out of this
1170
 
                                 algorithm.  */
1171
 
  };
1172
 
 
1173
 
/* Forward declaration.  */
1174
 
struct gcry_md_context;
1175
 
 
1176
 
/* This object is used to hold a handle to a message digest object.
1177
 
   This structure is private - only to be used by the public gcry_md_*
1178
 
   macros.  */
1179
 
typedef struct gcry_md_handle 
1180
 
{
1181
 
  /* Actual context.  */
1182
 
  struct gcry_md_context *ctx;
1183
 
  
1184
 
  /* Buffer management.  */
1185
 
  int  bufpos;
1186
 
  int  bufsize;
1187
 
  unsigned char buf[1];
1188
 
} *gcry_md_hd_t;
1189
 
 
1190
 
/* Compatibility types, do not use them.  */
1191
 
typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED;
1192
 
typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED;
1193
 
 
1194
 
/* Create a message digest object for algorithm ALGO.  FLAGS may be
1195
 
   given as an bitwise OR of the gcry_md_flags values.  ALGO may be
1196
 
   given as 0 if the algorithms to be used are later set using
1197
 
   gcry_md_enable.  */
1198
 
gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags);
1199
 
 
1200
 
/* Release the message digest object HD.  */
1201
 
void gcry_md_close (gcry_md_hd_t hd);
1202
 
 
1203
 
/* Add the message digest algorithm ALGO to the digest object HD.  */
1204
 
gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo);
1205
 
 
1206
 
/* Create a new digest object as an exact copy of the object HD.  */
1207
 
gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd);
1208
 
 
1209
 
/* Reset the digest object HD to its initial state.  */
1210
 
void gcry_md_reset (gcry_md_hd_t hd);
1211
 
 
1212
 
/* Perform various operations on the digets object HD. */
1213
 
gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd,
1214
 
                          void *buffer, size_t buflen);
1215
 
 
1216
 
/* Pass LENGTH bytes of data in BUFFER to the digest object HD so that
1217
 
   it can update the digest values.  This is the actual hash
1218
 
   function. */
1219
 
void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length);
1220
 
 
1221
 
/* Read out the final digest from HD return the digest value for
1222
 
   algorithm ALGO. */
1223
 
unsigned char *gcry_md_read (gcry_md_hd_t hd, int algo);
1224
 
 
1225
 
/* Convenience function to calculate the hash from the data in BUFFER
1226
 
   of size LENGTH using the algorithm ALGO avoiding the creating of a
1227
 
   hash object.  The hash is returned in the caller provided buffer
1228
 
   DIGEST which must be large enough to hold the digest of the given
1229
 
   algorithm. */
1230
 
void gcry_md_hash_buffer (int algo, void *digest,
1231
 
                          const void *buffer, size_t length);
1232
 
 
1233
 
/* Retrieve the algorithm used with HD.  This does not work reliable
1234
 
   if more than one algorithm is enabled in HD. */
1235
 
int gcry_md_get_algo (gcry_md_hd_t hd);
1236
 
 
1237
 
/* Retrieve the length in bytes of the digest yielded by algorithm
1238
 
   ALGO. */
1239
 
unsigned int gcry_md_get_algo_dlen (int algo);
1240
 
 
1241
 
/* Return true if the the algorithm ALGO is enabled in the digest
1242
 
   object A. */
1243
 
int gcry_md_is_enabled (gcry_md_hd_t a, int algo);
1244
 
 
1245
 
/* Return true if the digest object A is allocated in "secure" memory. */
1246
 
int gcry_md_is_secure (gcry_md_hd_t a);
1247
 
 
1248
 
/* Retrieve various information about the object H.  */
1249
 
gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer,
1250
 
                          size_t *nbytes);
1251
 
 
1252
 
/* Retrieve various information about the algorithm ALGO.  */
1253
 
gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer,
1254
 
                               size_t *nbytes);
1255
 
 
1256
 
/* Map the digest algorithm id ALGO to a string representation of the
1257
 
   algorithm name.  For unknown algorithms this functions returns an
1258
 
   empty string. */
1259
 
const char *gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE;
1260
 
 
1261
 
/* Map the algorithm NAME to a digest algorithm Id.  Return 0 if
1262
 
   the algorithm name is not known. */
1263
 
int gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
1264
 
 
1265
 
/* For use with the HMAC feature, the set MAC key to the KEY of
1266
 
   KEYLEN. */
1267
 
gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen);
1268
 
 
1269
 
/* Update the hash(s) of H with the character C.  This is a buffered
1270
 
   version of the gcry_md_write function. */
1271
 
#define gcry_md_putc(h,c)  \
1272
 
            do {                                          \
1273
 
                gcry_md_hd_t h__ = (h);                   \
1274
 
                if( (h__)->bufpos == (h__)->bufsize )     \
1275
 
                    gcry_md_write( (h__), NULL, 0 );      \
1276
 
                (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
1277
 
            } while(0)
1278
 
 
1279
 
/* Finalize the digest calculation.  This is not really needed because
1280
 
   gcry_md_read() does this implicitly. */
1281
 
#define gcry_md_final(a) \
1282
 
            gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0)
1283
 
 
1284
 
/* Return 0 if the algorithm A is available for use. */
1285
 
#define gcry_md_test_algo(a) \
1286
 
            gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
1287
 
 
1288
 
/* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N
1289
 
   must point to size_t variable with the available size of buffer B.
1290
 
   After return it will receive the actual size of the returned
1291
 
   OID. */
1292
 
#define gcry_md_get_asnoid(a,b,n) \
1293
 
            gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n))
1294
 
 
1295
 
/* Enable debugging for digets object A; i.e. create files named
1296
 
   dbgmd-<n>.<string> while hashing.  B is a string used as the suffix
1297
 
   for the filename. */
1298
 
#define gcry_md_start_debug(a,b) \
1299
 
            gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 )
1300
 
 
1301
 
/* Disable the debugging of A. */
1302
 
#define gcry_md_stop_debug(a,b) \
1303
 
            gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 )
1304
 
 
1305
 
/* Get a list consisting of the IDs of the loaded message digest
1306
 
   modules.  If LIST is zero, write the number of loaded message
1307
 
   digest modules to LIST_LENGTH and return.  If LIST is non-zero, the
1308
 
   first *LIST_LENGTH algorithm IDs are stored in LIST, which must be
1309
 
   of according size.  In case there are less message digest modules
1310
 
   than *LIST_LENGTH, *LIST_LENGTH is updated to the correct
1311
 
   number.  */
1312
 
gcry_error_t gcry_md_list (int *list, int *list_length);
 
1580
                                 gcry_ac_id_t *algorithm)
 
1581
     /* */                      _GCRY_GCC_ATTR_DEPRECATED;
 
1582
#endif
1313
1583
 
1314
1584
 
1315
1585
/************************************
1339
1609
   pool. QUALITY should either be -1 for unknown or in the range of 0
1340
1610
   to 100 */
1341
1611
gcry_error_t gcry_random_add_bytes (const void *buffer, size_t length,
1342
 
                                   int quality);
 
1612
                                    int quality);
1343
1613
 
1344
1614
/* If random numbers are used in an application, this macro should be
1345
1615
   called from time to time so that new stuff gets added to the
1370
1640
 
1371
1641
 
1372
1642
 
 
1643
 
1373
1644
/* Prime interface.  */
1374
1645
 
1375
1646
/* Mode values passed to a gcry_prime_check_func_t. */