1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
<!-- gcryptref-digest.sgml - libgcrypt reference (digests)
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GnuPG.
GnuPG is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GnuPG is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-->
<!--**********************************************
*********** md_open, close, enable ************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_open</refname>
<refname>gcry_md_enable</refname>
<refname>gcry_md_close</refname>
<refpurpose>create and destroy a message digest context</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>GCRY_MD_HD <function>gcry_md_open</function></funcdef>
<paramdef>int <parameter>algo</parameter></paramdef>
<paramdef>unsigned int <parameter>flags</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>gcry_md_enable</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
<paramdef>int <parameter>algo</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>gcry_md_close</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_open</secondary>
</indexterm>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_enable</secondary>
</indexterm>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_close</secondary>
</indexterm>
<function>gcry_md_open</function> creates the context required for
the message digest functions. The hash algorithm may optionally be
specified.
<function>gcry_md_close</function> releases all resources associated
with the context.
<function>gcry_md_enable</function> may be used to enable hash
algorithms. This function may be used multiple times to create
a hash context for multiple algorithms. Adding an already enabled algorithm
has no effect. A algorithm must be enabled prios to calculate hash
algorithms.
</para>
</refentry>
<!--**********************************************
*********** md_copy *****************************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_copy</refname>
<refpurpose>create and copy of a message digest context</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>GCRY_MD_HD <function>gcry_md_copy</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_copy</secondary>
</indexterm>
<function>gcry_md_copy</function> creates an excat copy of the given context.
This is useful to calculate hashes with a common initial part of the
plaintext.
</para>
</refentry>
<!--**********************************************
*********** md_reset ***************************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_reset</refname>
<refpurpose>reset a message digest context</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>void <function>gcry_md_reset</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_reset</secondary>
</indexterm>
<function>gcry_md_reset</function> is used to reuse a message context
without the overhead of an open and close operation.
</para>
</refentry>
<!--**********************************************
*********** md_ctl *****************************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_ctl</refname>
<refname>gcry_md_final</refname>
<refpurpose>perform special operations on a digest context</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>gcry_md_ctl</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
<paramdef>int <parameter>cmd</parameter></paramdef>
<paramdef>unsigned char * <parameter>buffer</parameter></paramdef>
<paramdef>size_t <parameter>buflen</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_ctl</secondary>
</indexterm>
<function>gcry_md_ctl</function> is a multi-purpose function
to control the behaviour of all gcry_md functions or one instance
of it.
</para>
<para>
Currently defined values for <parameter>cmd</> are:
<literal>GCRYCTL_FINALIZE</> and the conevnience macro
<function>gcry_md_final(a)</>
</para>
</refentry>
<!--**********************************************
*********** md_write, putc *********************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_write</refname>
<refname>gcry_md_putc</refname>
<refpurpose>calculate the message digest of a buffer</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>gcry_md_write</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
<paramdef>unsigned char * <parameter>buffer</parameter></paramdef>
<paramdef>size_t <parameter>buflen</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>gcry_md_putc</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
<paramdef>int <parameter>c</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_write</secondary></indexterm>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_putc</secondary></indexterm>
<function>gcry_md_write</function> is used to actually calulate the message
digest of a buffer. This function updates the internal state of the message
digest.
</para>
<para>
<function>gcry_md_putc</function> is a macro which is used to update
the message digest by one byte. this is the preferred way to calculate
a digest if only a few bytes at a time are available.
</para>
</refentry>
<!--**********************************************
*********** md_read *****************************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_read</refname>
<refpurpose>read out the message digest</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>unsigned char * <function>gcry_md_read</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
<paramdef>int <parameter>algo</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_read</secondary>
</indexterm>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_putc</secondary>
</indexterm>
<function>gcry_md_read</function> returns the message digest after finalizing
the calculation. This function may be used as often as required but it
will alwas return the same value for one handle. The returned message
digest is allocated within the message context and therefore valid until
the conext is released. <parameter>algo</> may be given as 0 to return the
only enbaled message digest or it may specify one of the enabled algorithms.
The function will return NULL if the algorithm has not been enabled.
</para>
</refentry>
<!--**********************************************
*********** md_info ****************************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_info</refname>
<refpurpose>get information about a handle</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>gcry_md_info</function></funcdef>
<paramdef>GCRY_MD_HD <parameter>h</parameter></paramdef>
<paramdef>int <parameter>what</parameter></paramdef>
<paramdef>void * <parameter>buffer</parameter></paramdef>
<paramdef>size_t <parameter>buflen</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_info</secondary>
</indexterm>
<function>gcry_md_info</function> returns some information about the
handle or an global parameter.
</para>
<para>
The only defined value for <parameter>what</> is
<literal>GCRYCTL_IS_SECURE</literal> to return whether the handle
has been allocated in secure memory. Buffer and buflen are not needed
in this cases. The convenience macro <function>gcry_md_is_secure(a)</>
may be also used for this purpose.
</para>
</refentry>
<!--**********************************************
*********** md_algo_info ***********************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_algo_info</refname>
<refname>gcry_md_test_algo</refname>
<refname>gcry_md_get_algo_dlen</refname>
<refpurpose>get information about an algorithm</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>gcry_md_algo_info</function></funcdef>
<paramdef>int <parameter>algo</parameter></paramdef>
<paramdef>int <parameter>what</parameter></paramdef>
<paramdef>void * <parameter>buffer</parameter></paramdef>
<paramdef>size_t <parameter>buflen</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>unsigned int <function>gcry_md_get_algo_dlen</function></funcdef>
<paramdef>int <parameter>algo</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_algo_info</secondary>
</indexterm>
<function>gcry_md_algo_info</function> returns some information about an
algorithm. On error the value -1 is return and a more detailed error
description is available with <function>gcry_errno</>.
</para>
<para>
The defined values for <parameter>what</> are
<literal>GCRYCTL_TEST_ALGO</literal> to return whether the algorithm
is supported. Buffer and buflen are not needed
in this cases. The convenience macro <function>gcry_md_test_algo(a)</>
may be used for this purpose.
</para>
<para>
<literal>GCRYCTL_GET_ASNOID</literal> to return whether the ASN.1
object identifier. IF buffer is specified as NULL, only the required
length for the buffer is returned.
</para>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_get_algo_dlen</secondary>
</indexterm>
<function>gcry_md_get_algo_dlen</function> returns the length of the
digest for a given algorithm in bytes.
</para>
</refentry>
<!--**********************************************
*********** md_algo_name, map_name *************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_algo_name</refname>
<refname>gcry_md_map_name</refname>
<refpurpose>map algorithm to string</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>const char * <function>gcry_md_algo_name</function></funcdef>
<paramdef>int <parameter>algo</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>gcry_md_map_name</function></funcdef>
<paramdef>const char*<parameter>name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_algo_name</secondary>
</indexterm>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_map_name</secondary>
</indexterm>
These both functions are used to map a string with the algorithm name to
the internal algorithm identifier value and vice versa.
</para>
<para>
<function>gcry_md_algo_name</> never returns NULL even in cases where the
algorithm string is not available. Instead a string consisting of a
single question mark is returned. Do not use this function to test
for the existence of an algorithm.
</para>
<para>
<function>gcry_md_map_name</> returns 0 if the algorithm is not known
to &libgcrypt;.
</para>
</refentry>
<!--**********************************************
*********** md_hash_buffer *********************
***********************************************-->
<refentry>
<refnamediv>
<refname>gcry_md_hash_buffer</refname>
<refpurpose>fast message calculation</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>
#include <gcrypt.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>gcry_md_hash_buffer</function></funcdef>
<paramdef>int <parameter>algo</parameter></paramdef>
<paramdef>char * <parameter>digest</parameter></paramdef>
<paramdef>const char * <parameter>buffer</parameter></paramdef>
<paramdef>size_t <parameter>buflen</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<indexterm><primary>hash functions</primary>
<secondary>gcry_md_hash_buffer</secondary>
</indexterm>
<function>gcry_md_hash_buffer</function> is a shortcut function
to calculate a message digest of a buffer. This function does not require
a context and immediatley returns the message digest.
<parameter>digest</> must be string large enough to hold the digest
given by algo. This length may be obtained by using the function
<function>gcry_md_get_algo_dlen</> but in most cases it will be a statically
allocated buffer.
</para>
</refentry>
|