diff options
Diffstat (limited to 'linden/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi')
-rw-r--r--[-rwxr-xr-x] | linden/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi | 7512 |
1 files changed, 3756 insertions, 3756 deletions
diff --git a/linden/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi b/linden/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi index 76b5977..aece0af 100755..100644 --- a/linden/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi +++ b/linden/indra/libgcrypt/libgcrypt-1.2.2/doc/gcrypt.texi | |||
@@ -1,3756 +1,3756 @@ | |||
1 | \input texinfo @c -*- Texinfo -*- | 1 | \input texinfo @c -*- Texinfo -*- |
2 | @c %**start of header | 2 | @c %**start of header |
3 | @setfilename gcrypt.info | 3 | @setfilename gcrypt.info |
4 | @include version.texi | 4 | @include version.texi |
5 | @settitle The Libgcrypt Reference Manual | 5 | @settitle The Libgcrypt Reference Manual |
6 | @c Unify some of the indices. | 6 | @c Unify some of the indices. |
7 | @syncodeindex tp fn | 7 | @syncodeindex tp fn |
8 | @syncodeindex pg fn | 8 | @syncodeindex pg fn |
9 | @c %**end of header | 9 | @c %**end of header |
10 | @copying | 10 | @copying |
11 | This manual is for Libgcrypt | 11 | This manual is for Libgcrypt |
12 | (version @value{VERSION}, @value{UPDATED}), | 12 | (version @value{VERSION}, @value{UPDATED}), |
13 | which is GNU's library of cryptographic building blocks. | 13 | which is GNU's library of cryptographic building blocks. |
14 | 14 | ||
15 | Copyright @copyright{} 2000, 2002, 2003, 2004 Free Software Foundation, Inc. | 15 | Copyright @copyright{} 2000, 2002, 2003, 2004 Free Software Foundation, Inc. |
16 | 16 | ||
17 | @quotation | 17 | @quotation |
18 | Permission is granted to copy, distribute and/or modify this document | 18 | Permission is granted to copy, distribute and/or modify this document |
19 | under the terms of the GNU General Public License as published by the | 19 | under the terms of the GNU General Public License as published by the |
20 | Free Software Foundation; either version 2 of the License, or (at your | 20 | Free Software Foundation; either version 2 of the License, or (at your |
21 | option) any later version. The text of the license can be found in the | 21 | option) any later version. The text of the license can be found in the |
22 | section entitled ``Copying''. | 22 | section entitled ``Copying''. |
23 | @end quotation | 23 | @end quotation |
24 | @end copying | 24 | @end copying |
25 | 25 | ||
26 | @dircategory GNU Libraries | 26 | @dircategory GNU Libraries |
27 | @direntry | 27 | @direntry |
28 | * libgcrypt: (gcrypt). Cryptographic function library. | 28 | * libgcrypt: (gcrypt). Cryptographic function library. |
29 | @end direntry | 29 | @end direntry |
30 | 30 | ||
31 | 31 | ||
32 | 32 | ||
33 | @c | 33 | @c |
34 | @c Titlepage | 34 | @c Titlepage |
35 | @c | 35 | @c |
36 | @setchapternewpage odd | 36 | @setchapternewpage odd |
37 | @titlepage | 37 | @titlepage |
38 | @title The Libgcrypt Reference Manual | 38 | @title The Libgcrypt Reference Manual |
39 | @subtitle Version @value{VERSION} | 39 | @subtitle Version @value{VERSION} |
40 | @subtitle @value{UPDATED} | 40 | @subtitle @value{UPDATED} |
41 | @author Werner Koch (@email{wk@@gnupg.org}) | 41 | @author Werner Koch (@email{wk@@gnupg.org}) |
42 | @author Moritz Schulte (@email{mo@@g10code.com}) | 42 | @author Moritz Schulte (@email{mo@@g10code.com}) |
43 | 43 | ||
44 | @page | 44 | @page |
45 | @vskip 0pt plus 1filll | 45 | @vskip 0pt plus 1filll |
46 | @insertcopying | 46 | @insertcopying |
47 | @end titlepage | 47 | @end titlepage |
48 | 48 | ||
49 | 49 | ||
50 | @summarycontents | 50 | @summarycontents |
51 | @contents | 51 | @contents |
52 | @page | 52 | @page |
53 | 53 | ||
54 | 54 | ||
55 | @ifnottex | 55 | @ifnottex |
56 | @node Top | 56 | @node Top |
57 | @top The Libgcrypt Library | 57 | @top The Libgcrypt Library |
58 | @insertcopying | 58 | @insertcopying |
59 | @end ifnottex | 59 | @end ifnottex |
60 | 60 | ||
61 | 61 | ||
62 | @menu | 62 | @menu |
63 | * Introduction:: What is @acronym{Libgcrypt}. | 63 | * Introduction:: What is @acronym{Libgcrypt}. |
64 | * Preparation:: What you should do before using the library. | 64 | * Preparation:: What you should do before using the library. |
65 | * Generalities:: General library functions and data types. | 65 | * Generalities:: General library functions and data types. |
66 | * Handler Functions:: Working with handler functions. | 66 | * Handler Functions:: Working with handler functions. |
67 | * Symmetric cryptography:: How to use symmetric cryptography. | 67 | * Symmetric cryptography:: How to use symmetric cryptography. |
68 | * Hashing:: How to use hashing. | 68 | * Hashing:: How to use hashing. |
69 | * Public Key cryptography (I):: How to use public key cryptography. | 69 | * Public Key cryptography (I):: How to use public key cryptography. |
70 | * Public Key cryptography (II):: How to use public key cryptography, alternatively. | 70 | * Public Key cryptography (II):: How to use public key cryptography, alternatively. |
71 | * Random Numbers:: How to work with random numbers. | 71 | * Random Numbers:: How to work with random numbers. |
72 | * S-expressions:: How to manage S-expressions. | 72 | * S-expressions:: How to manage S-expressions. |
73 | * MPI library:: How to work with multi-precision-integers. | 73 | * MPI library:: How to work with multi-precision-integers. |
74 | * Utilities:: Utility functions. | 74 | * Utilities:: Utility functions. |
75 | 75 | ||
76 | Appendices | 76 | Appendices |
77 | 77 | ||
78 | * Library Copying:: The GNU Lesser General Public License | 78 | * Library Copying:: The GNU Lesser General Public License |
79 | says how you can copy and share `Libgcrypt'. | 79 | says how you can copy and share `Libgcrypt'. |
80 | * Copying:: The GNU General Public License says how you | 80 | * Copying:: The GNU General Public License says how you |
81 | can copy and share some parts of `Libgcrypt'. | 81 | can copy and share some parts of `Libgcrypt'. |
82 | 82 | ||
83 | Indices | 83 | Indices |
84 | 84 | ||
85 | * Concept Index:: Index of concepts and programs. | 85 | * Concept Index:: Index of concepts and programs. |
86 | * Function and Data Index:: Index of functions, variables and data types. | 86 | * Function and Data Index:: Index of functions, variables and data types. |
87 | 87 | ||
88 | @detailmenu | 88 | @detailmenu |
89 | --- The Detailed Node Listing --- | 89 | --- The Detailed Node Listing --- |
90 | 90 | ||
91 | Introduction | 91 | Introduction |
92 | * Getting Started:: How to use this manual. | 92 | * Getting Started:: How to use this manual. |
93 | * Features:: A glance at @acronym{Libgcrypt}'s features. | 93 | * Features:: A glance at @acronym{Libgcrypt}'s features. |
94 | * Overview:: Overview about the library. | 94 | * Overview:: Overview about the library. |
95 | 95 | ||
96 | Preparation | 96 | Preparation |
97 | * Header:: What header file you need to include. | 97 | * Header:: What header file you need to include. |
98 | * Building sources:: How to build sources using the library. | 98 | * Building sources:: How to build sources using the library. |
99 | * Building sources using Automake:: How to build sources with the help of Automake. | 99 | * Building sources using Automake:: How to build sources with the help of Automake. |
100 | * Initializing the library:: How to initialize the library. | 100 | * Initializing the library:: How to initialize the library. |
101 | * Multi Threading:: How @acronym{Libgcrypt} can be used in a MT environment. | 101 | * Multi Threading:: How @acronym{Libgcrypt} can be used in a MT environment. |
102 | 102 | ||
103 | Generalities | 103 | Generalities |
104 | * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior. | 104 | * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior. |
105 | * Modules:: Description of extension modules. | 105 | * Modules:: Description of extension modules. |
106 | * Error Handling:: Error codes and such. | 106 | * Error Handling:: Error codes and such. |
107 | 107 | ||
108 | Handler Functions | 108 | Handler Functions |
109 | * Progress handler:: Using a progress handler function. | 109 | * Progress handler:: Using a progress handler function. |
110 | * Allocation handler:: Using special memory allocation functions. | 110 | * Allocation handler:: Using special memory allocation functions. |
111 | * Error handler:: Using error handler functions. | 111 | * Error handler:: Using error handler functions. |
112 | * Logging handler:: Using a special logging function. | 112 | * Logging handler:: Using a special logging function. |
113 | 113 | ||
114 | Symmetric cryptography | 114 | Symmetric cryptography |
115 | * Available ciphers:: List of ciphers supported by the library. | 115 | * Available ciphers:: List of ciphers supported by the library. |
116 | * Cipher modules:: How to work with cipher modules. | 116 | * Cipher modules:: How to work with cipher modules. |
117 | * Available cipher modes:: List of cipher modes supported by the library. | 117 | * Available cipher modes:: List of cipher modes supported by the library. |
118 | * Working with cipher handles:: How to perform operations related to cipher handles. | 118 | * Working with cipher handles:: How to perform operations related to cipher handles. |
119 | * General cipher functions:: General cipher functions independent of cipher handles. | 119 | * General cipher functions:: General cipher functions independent of cipher handles. |
120 | 120 | ||
121 | Hashing | 121 | Hashing |
122 | * Available hash algorithms:: List of hash algorithms supported by the library. | 122 | * Available hash algorithms:: List of hash algorithms supported by the library. |
123 | * Hash algorithm modules:: How to work with hash algorithm modules. | 123 | * Hash algorithm modules:: How to work with hash algorithm modules. |
124 | * Working with hash algorithms:: List of functions related to hashing. | 124 | * Working with hash algorithms:: List of functions related to hashing. |
125 | 125 | ||
126 | Public Key cryptography (I) | 126 | Public Key cryptography (I) |
127 | * Used S-expressions:: Introduction into the used S-expression. | 127 | * Used S-expressions:: Introduction into the used S-expression. |
128 | * Available algorithms:: Algorithms supported by the library. | 128 | * Available algorithms:: Algorithms supported by the library. |
129 | * Public key modules:: How to work with public key modules. | 129 | * Public key modules:: How to work with public key modules. |
130 | * Cryptographic Functions:: Functions for performing the cryptographic actions. | 130 | * Cryptographic Functions:: Functions for performing the cryptographic actions. |
131 | * General public-key related Functions:: General functions, not implementing any cryptography. | 131 | * General public-key related Functions:: General functions, not implementing any cryptography. |
132 | 132 | ||
133 | Public Key cryptography (II) | 133 | Public Key cryptography (II) |
134 | * Available asymmetric algorithms:: List of algorithms supported by the library. | 134 | * Available asymmetric algorithms:: List of algorithms supported by the library. |
135 | * Working with sets of data:: How to work with sets of data. | 135 | * Working with sets of data:: How to work with sets of data. |
136 | * Working with handles:: How to use handles. | 136 | * Working with handles:: How to use handles. |
137 | * Working with keys:: How to work with keys. | 137 | * Working with keys:: How to work with keys. |
138 | * Using cryptographic functions:: How to perform cryptographic operations. | 138 | * Using cryptographic functions:: How to perform cryptographic operations. |
139 | * Handle-independent functions:: General functions independent of handles. | 139 | * Handle-independent functions:: General functions independent of handles. |
140 | 140 | ||
141 | Random Numbers | 141 | Random Numbers |
142 | * Quality of random numbers:: @acronym{Libgcrypt} uses different quality levels. | 142 | * Quality of random numbers:: @acronym{Libgcrypt} uses different quality levels. |
143 | * Retrieving random numbers:: How to retrieve random numbers. | 143 | * Retrieving random numbers:: How to retrieve random numbers. |
144 | 144 | ||
145 | S-expressions | 145 | S-expressions |
146 | * Data types for S-expressions:: Data types related with S-expressions. | 146 | * Data types for S-expressions:: Data types related with S-expressions. |
147 | * Working with S-expressions:: How to work with S-expressions. | 147 | * Working with S-expressions:: How to work with S-expressions. |
148 | 148 | ||
149 | MPI library | 149 | MPI library |
150 | * Data types:: MPI related data types. | 150 | * Data types:: MPI related data types. |
151 | * Basic functions:: First steps with MPI numbers. | 151 | * Basic functions:: First steps with MPI numbers. |
152 | * MPI formats:: External representation of MPIs. | 152 | * MPI formats:: External representation of MPIs. |
153 | * Calculations:: Performing MPI calculations. | 153 | * Calculations:: Performing MPI calculations. |
154 | * Comparisons:: How to compare MPI values. | 154 | * Comparisons:: How to compare MPI values. |
155 | * Bit manipulations:: How to access single bits of MPI values. | 155 | * Bit manipulations:: How to access single bits of MPI values. |
156 | * Miscellaneous:: Miscellaneous MPI functions. | 156 | * Miscellaneous:: Miscellaneous MPI functions. |
157 | 157 | ||
158 | Utilities | 158 | Utilities |
159 | * Memory allocation:: Functions related with memory allocation. | 159 | * Memory allocation:: Functions related with memory allocation. |
160 | 160 | ||
161 | @end detailmenu | 161 | @end detailmenu |
162 | 162 | ||
163 | @end menu | 163 | @end menu |
164 | 164 | ||
165 | 165 | ||
166 | 166 | ||
167 | @c ********************************************************** | 167 | @c ********************************************************** |
168 | @c ******************* Introduction *********************** | 168 | @c ******************* Introduction *********************** |
169 | @c ********************************************************** | 169 | @c ********************************************************** |
170 | @node Introduction | 170 | @node Introduction |
171 | @chapter Introduction | 171 | @chapter Introduction |
172 | `@acronym{Libgcrypt}' is a library providing cryptographic building blocks. | 172 | `@acronym{Libgcrypt}' is a library providing cryptographic building blocks. |
173 | 173 | ||
174 | @menu | 174 | @menu |
175 | * Getting Started:: How to use this manual. | 175 | * Getting Started:: How to use this manual. |
176 | * Features:: A glance at @acronym{Libgcrypt}'s features. | 176 | * Features:: A glance at @acronym{Libgcrypt}'s features. |
177 | * Overview:: Overview about the library. | 177 | * Overview:: Overview about the library. |
178 | @end menu | 178 | @end menu |
179 | 179 | ||
180 | @node Getting Started | 180 | @node Getting Started |
181 | @section Getting Started | 181 | @section Getting Started |
182 | 182 | ||
183 | This manual documents the `@acronym{Libgcrypt}' library application programming | 183 | This manual documents the `@acronym{Libgcrypt}' library application programming |
184 | interface (API). All functions and data types provided by the library | 184 | interface (API). All functions and data types provided by the library |
185 | are explained. | 185 | are explained. |
186 | 186 | ||
187 | @noindent | 187 | @noindent |
188 | The reader is assumed to possess basic knowledge about applied | 188 | The reader is assumed to possess basic knowledge about applied |
189 | cryptography. | 189 | cryptography. |
190 | 190 | ||
191 | This manual can be used in several ways. If read from the beginning | 191 | This manual can be used in several ways. If read from the beginning |
192 | to the end, it gives a good introduction into the library and how it | 192 | to the end, it gives a good introduction into the library and how it |
193 | can be used in an application. Forward references are included where | 193 | can be used in an application. Forward references are included where |
194 | necessary. Later on, the manual can be used as a reference manual to | 194 | necessary. Later on, the manual can be used as a reference manual to |
195 | get just the information needed about any particular interface of the | 195 | get just the information needed about any particular interface of the |
196 | library. Experienced programmers might want to start looking at the | 196 | library. Experienced programmers might want to start looking at the |
197 | examples at the end of the manual, and then only read up those parts | 197 | examples at the end of the manual, and then only read up those parts |
198 | of the interface which are unclear. | 198 | of the interface which are unclear. |
199 | 199 | ||
200 | 200 | ||
201 | @node Features | 201 | @node Features |
202 | @section Features | 202 | @section Features |
203 | 203 | ||
204 | `Libgcrypt' might have a couple of advantages over other libraries doing | 204 | `Libgcrypt' might have a couple of advantages over other libraries doing |
205 | a similar job. | 205 | a similar job. |
206 | 206 | ||
207 | @table @asis | 207 | @table @asis |
208 | @item It's Free Software | 208 | @item It's Free Software |
209 | Anybody can use, modify, and redistribute it under the terms of the GNU | 209 | Anybody can use, modify, and redistribute it under the terms of the GNU |
210 | Lesser General Public License (@pxref{Library Copying}). Note, that | 210 | Lesser General Public License (@pxref{Library Copying}). Note, that |
211 | some parts (which are not needed on a GNU or GNU/Linux system) are | 211 | some parts (which are not needed on a GNU or GNU/Linux system) are |
212 | subject to the terms of the GNU General Public License | 212 | subject to the terms of the GNU General Public License |
213 | (@pxref{Copying}); please see the README file of the distribution for of | 213 | (@pxref{Copying}); please see the README file of the distribution for of |
214 | list of these parts. | 214 | list of these parts. |
215 | 215 | ||
216 | @item It encapsulates the low level cryptography | 216 | @item It encapsulates the low level cryptography |
217 | `@acronym{Libgcrypt}' provides a high level interface to cryptographic building | 217 | `@acronym{Libgcrypt}' provides a high level interface to cryptographic building |
218 | blocks using an extendable and flexible API. | 218 | blocks using an extendable and flexible API. |
219 | 219 | ||
220 | @end table | 220 | @end table |
221 | 221 | ||
222 | @node Overview | 222 | @node Overview |
223 | @section Overview | 223 | @section Overview |
224 | 224 | ||
225 | @noindent | 225 | @noindent |
226 | The `@acronym{Libgcrypt}' library is fully thread-safe, where it makes | 226 | The `@acronym{Libgcrypt}' library is fully thread-safe, where it makes |
227 | sense to be thread-safe. An exception for thread-safety are some | 227 | sense to be thread-safe. An exception for thread-safety are some |
228 | cryptographic functions that modify a certain context stored in | 228 | cryptographic functions that modify a certain context stored in |
229 | handles. If the user really intents to use such functions from | 229 | handles. If the user really intents to use such functions from |
230 | different threads on the same handle, he has to take care of the | 230 | different threads on the same handle, he has to take care of the |
231 | serialization of such functions himself. If not described otherwise, | 231 | serialization of such functions himself. If not described otherwise, |
232 | every function is thread-safe. | 232 | every function is thread-safe. |
233 | 233 | ||
234 | @acronym{Libgcrypt} depends on the library `libgpg-error', which | 234 | @acronym{Libgcrypt} depends on the library `libgpg-error', which |
235 | contains common error handling related code for GnuPG components. | 235 | contains common error handling related code for GnuPG components. |
236 | 236 | ||
237 | @c ********************************************************** | 237 | @c ********************************************************** |
238 | @c ******************* Preparation ************************ | 238 | @c ******************* Preparation ************************ |
239 | @c ********************************************************** | 239 | @c ********************************************************** |
240 | @node Preparation | 240 | @node Preparation |
241 | @chapter Preparation | 241 | @chapter Preparation |
242 | 242 | ||
243 | To use `@acronym{Libgcrypt}', you have to perform some changes to your | 243 | To use `@acronym{Libgcrypt}', you have to perform some changes to your |
244 | sources and the build system. The necessary changes are small and | 244 | sources and the build system. The necessary changes are small and |
245 | explained in the following sections. At the end of this chapter, it | 245 | explained in the following sections. At the end of this chapter, it |
246 | is described how the library is initialized, and how the requirements | 246 | is described how the library is initialized, and how the requirements |
247 | of the library are verified. | 247 | of the library are verified. |
248 | 248 | ||
249 | @menu | 249 | @menu |
250 | * Header:: What header file you need to include. | 250 | * Header:: What header file you need to include. |
251 | * Building sources:: How to build sources using the library. | 251 | * Building sources:: How to build sources using the library. |
252 | * Building sources using Automake:: How to build sources with the help of Automake. | 252 | * Building sources using Automake:: How to build sources with the help of Automake. |
253 | * Initializing the library:: How to initialize the library. | 253 | * Initializing the library:: How to initialize the library. |
254 | * Multi Threading:: How @acronym{Libgcrypt} can be used in a MT environment. | 254 | * Multi Threading:: How @acronym{Libgcrypt} can be used in a MT environment. |
255 | @end menu | 255 | @end menu |
256 | 256 | ||
257 | 257 | ||
258 | @node Header | 258 | @node Header |
259 | @section Header | 259 | @section Header |
260 | 260 | ||
261 | All interfaces (data types and functions) of the library are defined | 261 | All interfaces (data types and functions) of the library are defined |
262 | in the header file `gcrypt.h'. You must include this in all source | 262 | in the header file `gcrypt.h'. You must include this in all source |
263 | files using the library, either directly or through some other header | 263 | files using the library, either directly or through some other header |
264 | file, like this: | 264 | file, like this: |
265 | 265 | ||
266 | @example | 266 | @example |
267 | #include <gcrypt.h> | 267 | #include <gcrypt.h> |
268 | @end example | 268 | @end example |
269 | 269 | ||
270 | The name space of `@acronym{Libgcrypt}' is @code{gcry_*} for function | 270 | The name space of `@acronym{Libgcrypt}' is @code{gcry_*} for function |
271 | and type names and @code{GCRY*} for other symbols. In addition the | 271 | and type names and @code{GCRY*} for other symbols. In addition the |
272 | same name prefixes with one prepended underscore are reserved for | 272 | same name prefixes with one prepended underscore are reserved for |
273 | internal use and should never be used by an application. Furthermore | 273 | internal use and should never be used by an application. Furthermore |
274 | `libgpg-error' defines functions prefixed with `gpg_' and preprocessor | 274 | `libgpg-error' defines functions prefixed with `gpg_' and preprocessor |
275 | symbols prefixed with `GPG_'. Note that @acronym{Libgcrypt} uses | 275 | symbols prefixed with `GPG_'. Note that @acronym{Libgcrypt} uses |
276 | libgpg-error, which uses @code{gpg_err_*} as name space for function | 276 | libgpg-error, which uses @code{gpg_err_*} as name space for function |
277 | and type names and @code{GPG_ERR_*} for other symbols, including all | 277 | and type names and @code{GPG_ERR_*} for other symbols, including all |
278 | the error codes. | 278 | the error codes. |
279 | 279 | ||
280 | @node Building sources | 280 | @node Building sources |
281 | @section Building sources | 281 | @section Building sources |
282 | 282 | ||
283 | If you want to compile a source file including the `gcrypt.h' header | 283 | If you want to compile a source file including the `gcrypt.h' header |
284 | file, you must make sure that the compiler can find it in the | 284 | file, you must make sure that the compiler can find it in the |
285 | directory hierarchy. This is accomplished by adding the path to the | 285 | directory hierarchy. This is accomplished by adding the path to the |
286 | directory in which the header file is located to the compilers include | 286 | directory in which the header file is located to the compilers include |
287 | file search path (via the @option{-I} option). | 287 | file search path (via the @option{-I} option). |
288 | 288 | ||
289 | However, the path to the include file is determined at the time the | 289 | However, the path to the include file is determined at the time the |
290 | source is configured. To solve this problem, `@acronym{Libgcrypt}' ships with a small | 290 | source is configured. To solve this problem, `@acronym{Libgcrypt}' ships with a small |
291 | helper program @command{libgcrypt-config} that knows the path to the | 291 | helper program @command{libgcrypt-config} that knows the path to the |
292 | include file and other configuration options. The options that need | 292 | include file and other configuration options. The options that need |
293 | to be added to the compiler invocation at compile time are output by | 293 | to be added to the compiler invocation at compile time are output by |
294 | the @option{--cflags} option to @command{libgcrypt-config}. The following | 294 | the @option{--cflags} option to @command{libgcrypt-config}. The following |
295 | example shows how it can be used at the command line: | 295 | example shows how it can be used at the command line: |
296 | 296 | ||
297 | @example | 297 | @example |
298 | gcc -c foo.c `libgcrypt-config --cflags` | 298 | gcc -c foo.c `libgcrypt-config --cflags` |
299 | @end example | 299 | @end example |
300 | 300 | ||
301 | Adding the output of @samp{libgcrypt-config --cflags} to the compilers | 301 | Adding the output of @samp{libgcrypt-config --cflags} to the compilers |
302 | command line will ensure that the compiler can find the `@acronym{Libgcrypt}' header | 302 | command line will ensure that the compiler can find the `@acronym{Libgcrypt}' header |
303 | file. | 303 | file. |
304 | 304 | ||
305 | A similar problem occurs when linking the program with the library. | 305 | A similar problem occurs when linking the program with the library. |
306 | Again, the compiler has to find the library files. For this to work, | 306 | Again, the compiler has to find the library files. For this to work, |
307 | the path to the library files has to be added to the library search path | 307 | the path to the library files has to be added to the library search path |
308 | (via the @option{-L} option). For this, the option @option{--libs} to | 308 | (via the @option{-L} option). For this, the option @option{--libs} to |
309 | @command{libgcrypt-config} can be used. For convenience, this option | 309 | @command{libgcrypt-config} can be used. For convenience, this option |
310 | also outputs all other options that are required to link the program | 310 | also outputs all other options that are required to link the program |
311 | with the `@acronym{Libgcrypt}' libraries (in particular, the @samp{-lgcrypt} | 311 | with the `@acronym{Libgcrypt}' libraries (in particular, the @samp{-lgcrypt} |
312 | option). The example shows how to link @file{foo.o} with the `@acronym{Libgcrypt}' | 312 | option). The example shows how to link @file{foo.o} with the `@acronym{Libgcrypt}' |
313 | library to a program @command{foo}. | 313 | library to a program @command{foo}. |
314 | 314 | ||
315 | @example | 315 | @example |
316 | gcc -o foo foo.o `libgcrypt-config --libs` | 316 | gcc -o foo foo.o `libgcrypt-config --libs` |
317 | @end example | 317 | @end example |
318 | 318 | ||
319 | Of course you can also combine both examples to a single command by | 319 | Of course you can also combine both examples to a single command by |
320 | specifying both options to @command{libgcrypt-config}: | 320 | specifying both options to @command{libgcrypt-config}: |
321 | 321 | ||
322 | @example | 322 | @example |
323 | gcc -o foo foo.c `libgcrypt-config --cflags --libs` | 323 | gcc -o foo foo.c `libgcrypt-config --cflags --libs` |
324 | @end example | 324 | @end example |
325 | 325 | ||
326 | @node Building sources using Automake | 326 | @node Building sources using Automake |
327 | @section Building sources using Automake | 327 | @section Building sources using Automake |
328 | 328 | ||
329 | It is much easier if you use GNU Automake instead of writing your own | 329 | It is much easier if you use GNU Automake instead of writing your own |
330 | Makefiles. If you do that you do not have to worry about finding and | 330 | Makefiles. If you do that you do not have to worry about finding and |
331 | invoking the @command{libgcrypt-config} script at all. | 331 | invoking the @command{libgcrypt-config} script at all. |
332 | @acronym{Libgcrypt} provides an extension to Automake that does all | 332 | @acronym{Libgcrypt} provides an extension to Automake that does all |
333 | the work for you. | 333 | the work for you. |
334 | 334 | ||
335 | @c A simple macro for optional variables. | 335 | @c A simple macro for optional variables. |
336 | @macro ovar{varname} | 336 | @macro ovar{varname} |
337 | @r{[}@var{\varname\}@r{]} | 337 | @r{[}@var{\varname\}@r{]} |
338 | @end macro | 338 | @end macro |
339 | @defmac AM_PATH_LIBGCRYPT (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found}) | 339 | @defmac AM_PATH_LIBGCRYPT (@ovar{minimum-version}, @ovar{action-if-found}, @ovar{action-if-not-found}) |
340 | Check whether @acronym{Libgcrypt} (at least version | 340 | Check whether @acronym{Libgcrypt} (at least version |
341 | @var{minimum-version}, if given) exists on the host system. If it is | 341 | @var{minimum-version}, if given) exists on the host system. If it is |
342 | found, execute @var{action-if-found}, otherwise do | 342 | found, execute @var{action-if-found}, otherwise do |
343 | @var{action-if-not-found}, if given. | 343 | @var{action-if-not-found}, if given. |
344 | 344 | ||
345 | Additionally, the function defines @code{LIBGCRYPT_CFLAGS} to the | 345 | Additionally, the function defines @code{LIBGCRYPT_CFLAGS} to the |
346 | flags needed for compilation of the program to find the | 346 | flags needed for compilation of the program to find the |
347 | @file{gcrypt.h} header file, and @code{LIBGCRYPT_LIBS} to the linker | 347 | @file{gcrypt.h} header file, and @code{LIBGCRYPT_LIBS} to the linker |
348 | flags needed to link the program to the @acronym{Libgcrypt} library. | 348 | flags needed to link the program to the @acronym{Libgcrypt} library. |
349 | @end defmac | 349 | @end defmac |
350 | 350 | ||
351 | You can use the defined Autoconf variables like this in your | 351 | You can use the defined Autoconf variables like this in your |
352 | @file{Makefile.am}: | 352 | @file{Makefile.am}: |
353 | 353 | ||
354 | @example | 354 | @example |
355 | AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS) | 355 | AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS) |
356 | LDADD = $(LIBGCRYPT_LIBS) | 356 | LDADD = $(LIBGCRYPT_LIBS) |
357 | @end example | 357 | @end example |
358 | 358 | ||
359 | @node Initializing the library | 359 | @node Initializing the library |
360 | @section Initializing the library | 360 | @section Initializing the library |
361 | 361 | ||
362 | It is often desirable to check that the version of `@acronym{Libgcrypt}' used is | 362 | It is often desirable to check that the version of `@acronym{Libgcrypt}' used is |
363 | indeed one which fits all requirements. Even with binary compatibility | 363 | indeed one which fits all requirements. Even with binary compatibility |
364 | new features may have been introduced but due to problem with the | 364 | new features may have been introduced but due to problem with the |
365 | dynamic linker an old version is actually used. So you may want to | 365 | dynamic linker an old version is actually used. So you may want to |
366 | check that the version is okay right after program startup. | 366 | check that the version is okay right after program startup. |
367 | 367 | ||
368 | @deftypefun const char *gcry_check_version (const char *@var{req_version}) | 368 | @deftypefun const char *gcry_check_version (const char *@var{req_version}) |
369 | 369 | ||
370 | The function @code{gcry_check_version} has three purposes. It can be | 370 | The function @code{gcry_check_version} has three purposes. It can be |
371 | used to retrieve the version number of the library. In addition it | 371 | used to retrieve the version number of the library. In addition it |
372 | can verify that the version number is higher than a certain required | 372 | can verify that the version number is higher than a certain required |
373 | version number. | 373 | version number. |
374 | 374 | ||
375 | In either case, the function initializes some sub-systems, and for | 375 | In either case, the function initializes some sub-systems, and for |
376 | this reason alone it must be invoked early in your program, before you | 376 | this reason alone it must be invoked early in your program, before you |
377 | make use of the other functions of @acronym{Libgcrypt}. | 377 | make use of the other functions of @acronym{Libgcrypt}. |
378 | @end deftypefun | 378 | @end deftypefun |
379 | 379 | ||
380 | @node Multi Threading | 380 | @node Multi Threading |
381 | @section Multi Threading | 381 | @section Multi Threading |
382 | 382 | ||
383 | As mentioned earlier, the `@acronym{Libgcrypt}' library is | 383 | As mentioned earlier, the `@acronym{Libgcrypt}' library is |
384 | thread-safe if you adhere to the following requirements: | 384 | thread-safe if you adhere to the following requirements: |
385 | 385 | ||
386 | @itemize @bullet | 386 | @itemize @bullet |
387 | @item | 387 | @item |
388 | If your application is multi-threaded, you must set the thread support | 388 | If your application is multi-threaded, you must set the thread support |
389 | callbacks with the @code{GCRYCTL_SET_THREAD_CBS} command | 389 | callbacks with the @code{GCRYCTL_SET_THREAD_CBS} command |
390 | @strong{before} any other function in the library. | 390 | @strong{before} any other function in the library. |
391 | 391 | ||
392 | This is easy enough if you are indeed writing an application using | 392 | This is easy enough if you are indeed writing an application using |
393 | Libgcrypt. It is rather problematic if you are writing a library | 393 | Libgcrypt. It is rather problematic if you are writing a library |
394 | instead. Here are some tips what to do if you are writing a library: | 394 | instead. Here are some tips what to do if you are writing a library: |
395 | 395 | ||
396 | If your library requires a certain thread package, just initialize | 396 | If your library requires a certain thread package, just initialize |
397 | Libgcrypt to use this thread package. If your library supports multiple | 397 | Libgcrypt to use this thread package. If your library supports multiple |
398 | thread packages, but needs to be configured, you will have to | 398 | thread packages, but needs to be configured, you will have to |
399 | implement a way to determine which thread package the application | 399 | implement a way to determine which thread package the application |
400 | wants to use with your library anyway. Then configure Libgcrypt to use | 400 | wants to use with your library anyway. Then configure Libgcrypt to use |
401 | this thread package. | 401 | this thread package. |
402 | 402 | ||
403 | If your library is fully reentrant without any special support by a | 403 | If your library is fully reentrant without any special support by a |
404 | thread package, then you are lucky indeed. Unfortunately, this does | 404 | thread package, then you are lucky indeed. Unfortunately, this does |
405 | not relieve you from doing either of the two above, or use a third | 405 | not relieve you from doing either of the two above, or use a third |
406 | option. The third option is to let the application initialize Libgcrypt | 406 | option. The third option is to let the application initialize Libgcrypt |
407 | for you. Then you are not using Libgcrypt transparently, though. | 407 | for you. Then you are not using Libgcrypt transparently, though. |
408 | 408 | ||
409 | As if this was not difficult enough, a conflict may arise if two | 409 | As if this was not difficult enough, a conflict may arise if two |
410 | libraries try to initialize Libgcrypt independently of each others, and | 410 | libraries try to initialize Libgcrypt independently of each others, and |
411 | both such libraries are then linked into the same application. To | 411 | both such libraries are then linked into the same application. To |
412 | make it a bit simpler for you, this will probably work, but only if | 412 | make it a bit simpler for you, this will probably work, but only if |
413 | both libraries have the same requirement for the thread package. This | 413 | both libraries have the same requirement for the thread package. This |
414 | is currently only supported for the non-threaded case, GNU Pth and | 414 | is currently only supported for the non-threaded case, GNU Pth and |
415 | pthread. Support for more thread packages is easy to add, so contact | 415 | pthread. Support for more thread packages is easy to add, so contact |
416 | us if you require it. | 416 | us if you require it. |
417 | 417 | ||
418 | @item | 418 | @item |
419 | The function @code{gcry_check_version} must be called before any other | 419 | The function @code{gcry_check_version} must be called before any other |
420 | function in the library, except the @code{GCRYCTL_SET_THREAD_CBS} | 420 | function in the library, except the @code{GCRYCTL_SET_THREAD_CBS} |
421 | command (called via the @code{gcry_control} function), because it | 421 | command (called via the @code{gcry_control} function), because it |
422 | initializes the thread support subsystem in @acronym{Libgcrypt}. To | 422 | initializes the thread support subsystem in @acronym{Libgcrypt}. To |
423 | achieve this in multi-threaded programs, you must synchronize the | 423 | achieve this in multi-threaded programs, you must synchronize the |
424 | memory with respect to other threads that also want to use | 424 | memory with respect to other threads that also want to use |
425 | @acronym{Libgcrypt}. For this, it is sufficient to call | 425 | @acronym{Libgcrypt}. For this, it is sufficient to call |
426 | @code{gcry_check_version} before creating the other threads using | 426 | @code{gcry_check_version} before creating the other threads using |
427 | @acronym{Libgcrypt}@footnote{At least this is true for POSIX threads, | 427 | @acronym{Libgcrypt}@footnote{At least this is true for POSIX threads, |
428 | as @code{pthread_create} is a function that synchronizes memory with | 428 | as @code{pthread_create} is a function that synchronizes memory with |
429 | respects to other threads. There are many functions which have this | 429 | respects to other threads. There are many functions which have this |
430 | property, a complete list can be found in POSIX, IEEE Std 1003.1-2003, | 430 | property, a complete list can be found in POSIX, IEEE Std 1003.1-2003, |
431 | Base Definitions, Issue 6, in the definition of the term ``Memory | 431 | Base Definitions, Issue 6, in the definition of the term ``Memory |
432 | Synchronization''. For other thread packages, more relaxed or more | 432 | Synchronization''. For other thread packages, more relaxed or more |
433 | strict rules may apply.}. | 433 | strict rules may apply.}. |
434 | 434 | ||
435 | @item | 435 | @item |
436 | 436 | ||
437 | As with the function @code{gpg_strerror}, @code{gcry_strerror} is not | 437 | As with the function @code{gpg_strerror}, @code{gcry_strerror} is not |
438 | thread safe. You have to use @code{gpg_strerror_r} instead. | 438 | thread safe. You have to use @code{gpg_strerror_r} instead. |
439 | @end itemize | 439 | @end itemize |
440 | 440 | ||
441 | 441 | ||
442 | @acronym{Libgcrypt} contains convenient macros, which define the | 442 | @acronym{Libgcrypt} contains convenient macros, which define the |
443 | necessary thread callbacks for PThread and for GNU Pth: | 443 | necessary thread callbacks for PThread and for GNU Pth: |
444 | 444 | ||
445 | @table @code | 445 | @table @code |
446 | @item GCRY_THREAD_OPTION_PTH_IMPL | 446 | @item GCRY_THREAD_OPTION_PTH_IMPL |
447 | 447 | ||
448 | This macro defines the following (static) symbols: gcry_pth_init, | 448 | This macro defines the following (static) symbols: gcry_pth_init, |
449 | gcry_pth_mutex_init, gcry_pth_mutex_destroy, gcry_pth_mutex_lock, | 449 | gcry_pth_mutex_init, gcry_pth_mutex_destroy, gcry_pth_mutex_lock, |
450 | gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, gcry_pth_select, | 450 | gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, gcry_pth_select, |
451 | gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, gcry_threads_pth. | 451 | gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, gcry_threads_pth. |
452 | 452 | ||
453 | After including this macro, gcry_control() shall be used with a | 453 | After including this macro, gcry_control() shall be used with a |
454 | command of GCRYCTL_SET_THREAD_CBS in order to register the thread | 454 | command of GCRYCTL_SET_THREAD_CBS in order to register the thread |
455 | callback structure named ``gcry_threads_pth''. | 455 | callback structure named ``gcry_threads_pth''. |
456 | 456 | ||
457 | @item GCRY_THREAD_OPTION_PTHREAD_IMPL | 457 | @item GCRY_THREAD_OPTION_PTHREAD_IMPL |
458 | 458 | ||
459 | This macro defines the following (static) symbols: | 459 | This macro defines the following (static) symbols: |
460 | gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, gcry_mutex_lock, | 460 | gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, gcry_mutex_lock, |
461 | gcry_mutex_unlock, gcry_threads_pthread. | 461 | gcry_mutex_unlock, gcry_threads_pthread. |
462 | 462 | ||
463 | After including this macro, gcry_control() shall be used with a | 463 | After including this macro, gcry_control() shall be used with a |
464 | command of GCRYCTL_SET_THREAD_CBS in order to register the thread | 464 | command of GCRYCTL_SET_THREAD_CBS in order to register the thread |
465 | callback structure named ``gcry_threads_pthread''. | 465 | callback structure named ``gcry_threads_pthread''. |
466 | @end table | 466 | @end table |
467 | 467 | ||
468 | Note that these macros need to be terminated with a semicolon. Keep | 468 | Note that these macros need to be terminated with a semicolon. Keep |
469 | in mind that these are convenient macros for C programmers; C++ | 469 | in mind that these are convenient macros for C programmers; C++ |
470 | programmers might have to wrap these macros in an ``extern C'' body. | 470 | programmers might have to wrap these macros in an ``extern C'' body. |
471 | 471 | ||
472 | @c ********************************************************** | 472 | @c ********************************************************** |
473 | @c ******************* General **************************** | 473 | @c ******************* General **************************** |
474 | @c ********************************************************** | 474 | @c ********************************************************** |
475 | @node Generalities | 475 | @node Generalities |
476 | @chapter Generalities | 476 | @chapter Generalities |
477 | 477 | ||
478 | @menu | 478 | @menu |
479 | * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior. | 479 | * Controlling the library:: Controlling @acronym{Libgcrypt}'s behavior. |
480 | * Modules:: Description of extension modules. | 480 | * Modules:: Description of extension modules. |
481 | * Error Handling:: Error codes and such. | 481 | * Error Handling:: Error codes and such. |
482 | @end menu | 482 | @end menu |
483 | 483 | ||
484 | @node Controlling the library | 484 | @node Controlling the library |
485 | @section Controlling the library | 485 | @section Controlling the library |
486 | 486 | ||
487 | @deftypefun gcry_error_t gcry_control (enum gcry_ctl_cmds @var{cmd}, ...) | 487 | @deftypefun gcry_error_t gcry_control (enum gcry_ctl_cmds @var{cmd}, ...) |
488 | 488 | ||
489 | This function can be used to influence the general behavior of | 489 | This function can be used to influence the general behavior of |
490 | @acronym{Libgcrypt} in several ways. Depending on @var{cmd}, more | 490 | @acronym{Libgcrypt} in several ways. Depending on @var{cmd}, more |
491 | arguments can or have to be provided. | 491 | arguments can or have to be provided. |
492 | 492 | ||
493 | @end deftypefun | 493 | @end deftypefun |
494 | 494 | ||
495 | @node Modules | 495 | @node Modules |
496 | @section Modules | 496 | @section Modules |
497 | 497 | ||
498 | @acronym{Libgcrypt} supports the use of `extension modules', which | 498 | @acronym{Libgcrypt} supports the use of `extension modules', which |
499 | implement algorithms in addition to those already built into the | 499 | implement algorithms in addition to those already built into the |
500 | library directly. | 500 | library directly. |
501 | 501 | ||
502 | @deftp {Data type} gcry_module_t | 502 | @deftp {Data type} gcry_module_t |
503 | This data type represents a `module'. | 503 | This data type represents a `module'. |
504 | @end deftp | 504 | @end deftp |
505 | 505 | ||
506 | Functions registering modules provided by the user take a `module | 506 | Functions registering modules provided by the user take a `module |
507 | specification structure' as input and return a value of | 507 | specification structure' as input and return a value of |
508 | @code{gcry_module_t} and an ID that is unique in the modules' | 508 | @code{gcry_module_t} and an ID that is unique in the modules' |
509 | category. This ID can be used to reference the newly registered | 509 | category. This ID can be used to reference the newly registered |
510 | module. After registering a module successfully, the new functionality | 510 | module. After registering a module successfully, the new functionality |
511 | should be able to be used through the normal functions provided by | 511 | should be able to be used through the normal functions provided by |
512 | @acronym{Libgcrypt} until it is unregistered again. | 512 | @acronym{Libgcrypt} until it is unregistered again. |
513 | 513 | ||
514 | @c ********************************************************** | 514 | @c ********************************************************** |
515 | @c ******************* Errors **************************** | 515 | @c ******************* Errors **************************** |
516 | @c ********************************************************** | 516 | @c ********************************************************** |
517 | @node Error Handling | 517 | @node Error Handling |
518 | @section Error Handling | 518 | @section Error Handling |
519 | 519 | ||
520 | Many functions in @acronym{Libgcrypt} can return an error if they | 520 | Many functions in @acronym{Libgcrypt} can return an error if they |
521 | fail. For this reason, the application should always catch the error | 521 | fail. For this reason, the application should always catch the error |
522 | condition and take appropriate measures, for example by releasing the | 522 | condition and take appropriate measures, for example by releasing the |
523 | resources and passing the error up to the caller, or by displaying a | 523 | resources and passing the error up to the caller, or by displaying a |
524 | descriptive message to the user and cancelling the operation. | 524 | descriptive message to the user and cancelling the operation. |
525 | 525 | ||
526 | Some error values do not indicate a system error or an error in the | 526 | Some error values do not indicate a system error or an error in the |
527 | operation, but the result of an operation that failed properly. For | 527 | operation, but the result of an operation that failed properly. For |
528 | example, if you try to decrypt a tempered message, the decryption will | 528 | example, if you try to decrypt a tempered message, the decryption will |
529 | fail. Another error value actually means that the end of a data | 529 | fail. Another error value actually means that the end of a data |
530 | buffer or list has been reached. The following descriptions explain | 530 | buffer or list has been reached. The following descriptions explain |
531 | for many error codes what they mean usually. Some error values have | 531 | for many error codes what they mean usually. Some error values have |
532 | specific meanings if returned by a certain functions. Such cases are | 532 | specific meanings if returned by a certain functions. Such cases are |
533 | described in the documentation of those functions. | 533 | described in the documentation of those functions. |
534 | 534 | ||
535 | @acronym{Libgcrypt} uses the @code{libgpg-error} library. This allows | 535 | @acronym{Libgcrypt} uses the @code{libgpg-error} library. This allows |
536 | to share the error codes with other components of the GnuPG system, | 536 | to share the error codes with other components of the GnuPG system, |
537 | and thus pass error values transparently from the crypto engine, or | 537 | and thus pass error values transparently from the crypto engine, or |
538 | some helper application of the crypto engine, to the user. This way | 538 | some helper application of the crypto engine, to the user. This way |
539 | no information is lost. As a consequence, @acronym{Libgcrypt} does | 539 | no information is lost. As a consequence, @acronym{Libgcrypt} does |
540 | not use its own identifiers for error codes, but uses those provided | 540 | not use its own identifiers for error codes, but uses those provided |
541 | by @code{libgpg-error}. They usually start with @code{GPG_ERR_}. | 541 | by @code{libgpg-error}. They usually start with @code{GPG_ERR_}. |
542 | 542 | ||
543 | However, @acronym{Libgcrypt} does provide aliases for the functions | 543 | However, @acronym{Libgcrypt} does provide aliases for the functions |
544 | defined in libgpg-error, which might be preferred for name space | 544 | defined in libgpg-error, which might be preferred for name space |
545 | consistency. | 545 | consistency. |
546 | 546 | ||
547 | 547 | ||
548 | Most functions in @acronym{Libgcrypt} return an error code in the case | 548 | Most functions in @acronym{Libgcrypt} return an error code in the case |
549 | of failure. For this reason, the application should always catch the | 549 | of failure. For this reason, the application should always catch the |
550 | error condition and take appropriate measures, for example by | 550 | error condition and take appropriate measures, for example by |
551 | releasing the resources and passing the error up to the caller, or by | 551 | releasing the resources and passing the error up to the caller, or by |
552 | displaying a descriptive message to the user and canceling the | 552 | displaying a descriptive message to the user and canceling the |
553 | operation. | 553 | operation. |
554 | 554 | ||
555 | Some error values do not indicate a system error or an error in the | 555 | Some error values do not indicate a system error or an error in the |
556 | operation, but the result of an operation that failed properly. | 556 | operation, but the result of an operation that failed properly. |
557 | 557 | ||
558 | GnuPG components, including Libgcrypt, use an extra library named | 558 | GnuPG components, including Libgcrypt, use an extra library named |
559 | libgpg-error to provide a common error handling scheme. For more | 559 | libgpg-error to provide a common error handling scheme. For more |
560 | information on libgpg-error, see the according manual. | 560 | information on libgpg-error, see the according manual. |
561 | 561 | ||
562 | @menu | 562 | @menu |
563 | * Error Values:: The error value and what it means. | 563 | * Error Values:: The error value and what it means. |
564 | * Error Sources:: A list of important error sources. | 564 | * Error Sources:: A list of important error sources. |
565 | * Error Codes:: A list of important error codes. | 565 | * Error Codes:: A list of important error codes. |
566 | * Error Strings:: How to get a descriptive string from a value. | 566 | * Error Strings:: How to get a descriptive string from a value. |
567 | @end menu | 567 | @end menu |
568 | 568 | ||
569 | 569 | ||
570 | @node Error Values | 570 | @node Error Values |
571 | @subsection Error Values | 571 | @subsection Error Values |
572 | @cindex error values | 572 | @cindex error values |
573 | @cindex error codes | 573 | @cindex error codes |
574 | @cindex error sources | 574 | @cindex error sources |
575 | 575 | ||
576 | @deftp {Data type} {gcry_err_code_t} | 576 | @deftp {Data type} {gcry_err_code_t} |
577 | The @code{gcry_err_code_t} type is an alias for the | 577 | The @code{gcry_err_code_t} type is an alias for the |
578 | @code{libgpg-error} type @code{gpg_err_code_t}. The error code | 578 | @code{libgpg-error} type @code{gpg_err_code_t}. The error code |
579 | indicates the type of an error, or the reason why an operation failed. | 579 | indicates the type of an error, or the reason why an operation failed. |
580 | 580 | ||
581 | A list of important error codes can be found in the next section. | 581 | A list of important error codes can be found in the next section. |
582 | @end deftp | 582 | @end deftp |
583 | 583 | ||
584 | @deftp {Data type} {gcry_err_source_t} | 584 | @deftp {Data type} {gcry_err_source_t} |
585 | The @code{gcry_err_source_t} type is an alias for the | 585 | The @code{gcry_err_source_t} type is an alias for the |
586 | @code{libgpg-error} type @code{gpg_err_source_t}. The error source | 586 | @code{libgpg-error} type @code{gpg_err_source_t}. The error source |
587 | has not a precisely defined meaning. Sometimes it is the place where | 587 | has not a precisely defined meaning. Sometimes it is the place where |
588 | the error happened, sometimes it is the place where an error was | 588 | the error happened, sometimes it is the place where an error was |
589 | encoded into an error value. Usually the error source will give an | 589 | encoded into an error value. Usually the error source will give an |
590 | indication to where to look for the problem. This is not always true, | 590 | indication to where to look for the problem. This is not always true, |
591 | but it is attempted to achieve this goal. | 591 | but it is attempted to achieve this goal. |
592 | 592 | ||
593 | A list of important error sources can be found in the next section. | 593 | A list of important error sources can be found in the next section. |
594 | @end deftp | 594 | @end deftp |
595 | 595 | ||
596 | @deftp {Data type} {gcry_error_t} | 596 | @deftp {Data type} {gcry_error_t} |
597 | The @code{gcry_error_t} type is an alias for the @code{libgpg-error} | 597 | The @code{gcry_error_t} type is an alias for the @code{libgpg-error} |
598 | type @code{gpg_error_t}. An error value like this has always two | 598 | type @code{gpg_error_t}. An error value like this has always two |
599 | components, an error code and an error source. Both together form the | 599 | components, an error code and an error source. Both together form the |
600 | error value. | 600 | error value. |
601 | 601 | ||
602 | Thus, the error value can not be directly compared against an error | 602 | Thus, the error value can not be directly compared against an error |
603 | code, but the accessor functions described below must be used. | 603 | code, but the accessor functions described below must be used. |
604 | However, it is guaranteed that only 0 is used to indicate success | 604 | However, it is guaranteed that only 0 is used to indicate success |
605 | (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of | 605 | (@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of |
606 | the error value are set to 0, too. | 606 | the error value are set to 0, too. |
607 | 607 | ||
608 | Note that in @acronym{Libgcrypt}, the error source is used purely for | 608 | Note that in @acronym{Libgcrypt}, the error source is used purely for |
609 | diagnostic purposes. Only the error code should be checked to test | 609 | diagnostic purposes. Only the error code should be checked to test |
610 | for a certain outcome of a function. The manual only documents the | 610 | for a certain outcome of a function. The manual only documents the |
611 | error code part of an error value. The error source is left | 611 | error code part of an error value. The error source is left |
612 | unspecified and might be anything. | 612 | unspecified and might be anything. |
613 | @end deftp | 613 | @end deftp |
614 | 614 | ||
615 | @deftypefun {gcry_err_code_t} gcry_err_code (@w{gcry_error_t @var{err}}) | 615 | @deftypefun {gcry_err_code_t} gcry_err_code (@w{gcry_error_t @var{err}}) |
616 | The static inline function @code{gcry_err_code} returns the | 616 | The static inline function @code{gcry_err_code} returns the |
617 | @code{gcry_err_code_t} component of the error value @var{err}. This | 617 | @code{gcry_err_code_t} component of the error value @var{err}. This |
618 | function must be used to extract the error code from an error value in | 618 | function must be used to extract the error code from an error value in |
619 | order to compare it with the @code{GPG_ERR_*} error code macros. | 619 | order to compare it with the @code{GPG_ERR_*} error code macros. |
620 | @end deftypefun | 620 | @end deftypefun |
621 | 621 | ||
622 | @deftypefun {gcry_err_source_t} gcry_err_source (@w{gcry_error_t @var{err}}) | 622 | @deftypefun {gcry_err_source_t} gcry_err_source (@w{gcry_error_t @var{err}}) |
623 | The static inline function @code{gcry_err_source} returns the | 623 | The static inline function @code{gcry_err_source} returns the |
624 | @code{gcry_err_source_t} component of the error value @var{err}. This | 624 | @code{gcry_err_source_t} component of the error value @var{err}. This |
625 | function must be used to extract the error source from an error value in | 625 | function must be used to extract the error source from an error value in |
626 | order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros. | 626 | order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros. |
627 | @end deftypefun | 627 | @end deftypefun |
628 | 628 | ||
629 | @deftypefun {gcry_error_t} gcry_err_make (@w{gcry_err_source_t @var{source}}, @w{gcry_err_code_t @var{code}}) | 629 | @deftypefun {gcry_error_t} gcry_err_make (@w{gcry_err_source_t @var{source}}, @w{gcry_err_code_t @var{code}}) |
630 | The static inline function @code{gcry_err_make} returns the error | 630 | The static inline function @code{gcry_err_make} returns the error |
631 | value consisting of the error source @var{source} and the error code | 631 | value consisting of the error source @var{source} and the error code |
632 | @var{code}. | 632 | @var{code}. |
633 | 633 | ||
634 | This function can be used in callback functions to construct an error | 634 | This function can be used in callback functions to construct an error |
635 | value to return it to the library. | 635 | value to return it to the library. |
636 | @end deftypefun | 636 | @end deftypefun |
637 | 637 | ||
638 | @deftypefun {gcry_error_t} gcry_error (@w{gcry_err_code_t @var{code}}) | 638 | @deftypefun {gcry_error_t} gcry_error (@w{gcry_err_code_t @var{code}}) |
639 | The static inline function @code{gcry_error} returns the error value | 639 | The static inline function @code{gcry_error} returns the error value |
640 | consisting of the default error source and the error code @var{code}. | 640 | consisting of the default error source and the error code @var{code}. |
641 | 641 | ||
642 | For @acronym{GCRY} applications, the default error source is | 642 | For @acronym{GCRY} applications, the default error source is |
643 | @code{GPG_ERR_SOURCE_USER_1}. You can define | 643 | @code{GPG_ERR_SOURCE_USER_1}. You can define |
644 | @code{GCRY_ERR_SOURCE_DEFAULT} before including @file{gcrypt.h} to | 644 | @code{GCRY_ERR_SOURCE_DEFAULT} before including @file{gcrypt.h} to |
645 | change this default. | 645 | change this default. |
646 | 646 | ||
647 | This function can be used in callback functions to construct an error | 647 | This function can be used in callback functions to construct an error |
648 | value to return it to the library. | 648 | value to return it to the library. |
649 | @end deftypefun | 649 | @end deftypefun |
650 | 650 | ||
651 | The @code{libgpg-error} library provides error codes for all system | 651 | The @code{libgpg-error} library provides error codes for all system |
652 | error numbers it knows about. If @var{err} is an unknown error | 652 | error numbers it knows about. If @var{err} is an unknown error |
653 | number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The | 653 | number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The |
654 | following functions can be used to construct error values from system | 654 | following functions can be used to construct error values from system |
655 | errno numbers. | 655 | errno numbers. |
656 | 656 | ||
657 | @deftypefun {gcry_error_t} gcry_err_make_from_errno (@w{gcry_err_source_t @var{source}}, @w{int @var{err}}) | 657 | @deftypefun {gcry_error_t} gcry_err_make_from_errno (@w{gcry_err_source_t @var{source}}, @w{int @var{err}}) |
658 | The function @code{gcry_err_make_from_errno} is like | 658 | The function @code{gcry_err_make_from_errno} is like |
659 | @code{gcry_err_make}, but it takes a system error like @code{errno} | 659 | @code{gcry_err_make}, but it takes a system error like @code{errno} |
660 | instead of a @code{gcry_err_code_t} error code. | 660 | instead of a @code{gcry_err_code_t} error code. |
661 | @end deftypefun | 661 | @end deftypefun |
662 | 662 | ||
663 | @deftypefun {gcry_error_t} gcry_error_from_errno (@w{int @var{err}}) | 663 | @deftypefun {gcry_error_t} gcry_error_from_errno (@w{int @var{err}}) |
664 | The function @code{gcry_error_from_errno} is like @code{gcry_error}, | 664 | The function @code{gcry_error_from_errno} is like @code{gcry_error}, |
665 | but it takes a system error like @code{errno} instead of a | 665 | but it takes a system error like @code{errno} instead of a |
666 | @code{gcry_err_code_t} error code. | 666 | @code{gcry_err_code_t} error code. |
667 | @end deftypefun | 667 | @end deftypefun |
668 | 668 | ||
669 | Sometimes you might want to map system error numbers to error codes | 669 | Sometimes you might want to map system error numbers to error codes |
670 | directly, or map an error code representing a system error back to the | 670 | directly, or map an error code representing a system error back to the |
671 | system error number. The following functions can be used to do that. | 671 | system error number. The following functions can be used to do that. |
672 | 672 | ||
673 | @deftypefun {gcry_err_code_t} gcry_err_code_from_errno (@w{int @var{err}}) | 673 | @deftypefun {gcry_err_code_t} gcry_err_code_from_errno (@w{int @var{err}}) |
674 | The function @code{gcry_err_code_from_errno} returns the error code | 674 | The function @code{gcry_err_code_from_errno} returns the error code |
675 | for the system error @var{err}. If @var{err} is not a known system | 675 | for the system error @var{err}. If @var{err} is not a known system |
676 | error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}. | 676 | error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}. |
677 | @end deftypefun | 677 | @end deftypefun |
678 | 678 | ||
679 | @deftypefun {int} gcry_err_code_to_errno (@w{gcry_err_code_t @var{err}}) | 679 | @deftypefun {int} gcry_err_code_to_errno (@w{gcry_err_code_t @var{err}}) |
680 | The function @code{gcry_err_code_to_errno} returns the system error | 680 | The function @code{gcry_err_code_to_errno} returns the system error |
681 | for the error code @var{err}. If @var{err} is not an error code | 681 | for the error code @var{err}. If @var{err} is not an error code |
682 | representing a system error, or if this system error is not defined on | 682 | representing a system error, or if this system error is not defined on |
683 | this system, the function returns @code{0}. | 683 | this system, the function returns @code{0}. |
684 | @end deftypefun | 684 | @end deftypefun |
685 | 685 | ||
686 | 686 | ||
687 | @node Error Sources | 687 | @node Error Sources |
688 | @subsection Error Sources | 688 | @subsection Error Sources |
689 | @cindex error codes, list of | 689 | @cindex error codes, list of |
690 | 690 | ||
691 | The library @code{libgpg-error} defines an error source for every | 691 | The library @code{libgpg-error} defines an error source for every |
692 | component of the GnuPG system. The error source part of an error | 692 | component of the GnuPG system. The error source part of an error |
693 | value is not well defined. As such it is mainly useful to improve the | 693 | value is not well defined. As such it is mainly useful to improve the |
694 | diagnostic error message for the user. | 694 | diagnostic error message for the user. |
695 | 695 | ||
696 | If the error code part of an error value is @code{0}, the whole error | 696 | If the error code part of an error value is @code{0}, the whole error |
697 | value will be @code{0}. In this case the error source part is of | 697 | value will be @code{0}. In this case the error source part is of |
698 | course @code{GPG_ERR_SOURCE_UNKNOWN}. | 698 | course @code{GPG_ERR_SOURCE_UNKNOWN}. |
699 | 699 | ||
700 | The list of error sources that might occur in applications using | 700 | The list of error sources that might occur in applications using |
701 | @acronym{Libgctypt} is: | 701 | @acronym{Libgctypt} is: |
702 | 702 | ||
703 | @table @code | 703 | @table @code |
704 | @item GPG_ERR_SOURCE_UNKNOWN | 704 | @item GPG_ERR_SOURCE_UNKNOWN |
705 | The error source is not known. The value of this error source is | 705 | The error source is not known. The value of this error source is |
706 | @code{0}. | 706 | @code{0}. |
707 | 707 | ||
708 | @item GPG_ERR_SOURCE_GPGME | 708 | @item GPG_ERR_SOURCE_GPGME |
709 | The error source is @acronym{GPGME} itself. | 709 | The error source is @acronym{GPGME} itself. |
710 | 710 | ||
711 | @item GPG_ERR_SOURCE_GPG | 711 | @item GPG_ERR_SOURCE_GPG |
712 | The error source is GnuPG, which is the crypto engine used for the | 712 | The error source is GnuPG, which is the crypto engine used for the |
713 | OpenPGP protocol. | 713 | OpenPGP protocol. |
714 | 714 | ||
715 | @item GPG_ERR_SOURCE_GPGSM | 715 | @item GPG_ERR_SOURCE_GPGSM |
716 | The error source is GPGSM, which is the crypto engine used for the | 716 | The error source is GPGSM, which is the crypto engine used for the |
717 | OpenPGP protocol. | 717 | OpenPGP protocol. |
718 | 718 | ||
719 | @item GPG_ERR_SOURCE_GCRYPT | 719 | @item GPG_ERR_SOURCE_GCRYPT |
720 | The error source is @code{libgcrypt}, which is used by crypto engines | 720 | The error source is @code{libgcrypt}, which is used by crypto engines |
721 | to perform cryptographic operations. | 721 | to perform cryptographic operations. |
722 | 722 | ||
723 | @item GPG_ERR_SOURCE_GPGAGENT | 723 | @item GPG_ERR_SOURCE_GPGAGENT |
724 | The error source is @command{gpg-agent}, which is used by crypto | 724 | The error source is @command{gpg-agent}, which is used by crypto |
725 | engines to perform operations with the secret key. | 725 | engines to perform operations with the secret key. |
726 | 726 | ||
727 | @item GPG_ERR_SOURCE_PINENTRY | 727 | @item GPG_ERR_SOURCE_PINENTRY |
728 | The error source is @command{pinentry}, which is used by | 728 | The error source is @command{pinentry}, which is used by |
729 | @command{gpg-agent} to query the passphrase to unlock a secret key. | 729 | @command{gpg-agent} to query the passphrase to unlock a secret key. |
730 | 730 | ||
731 | @item GPG_ERR_SOURCE_SCD | 731 | @item GPG_ERR_SOURCE_SCD |
732 | The error source is the SmartCard Daemon, which is used by | 732 | The error source is the SmartCard Daemon, which is used by |
733 | @command{gpg-agent} to delegate operations with the secret key to a | 733 | @command{gpg-agent} to delegate operations with the secret key to a |
734 | SmartCard. | 734 | SmartCard. |
735 | 735 | ||
736 | @item GPG_ERR_SOURCE_KEYBOX | 736 | @item GPG_ERR_SOURCE_KEYBOX |
737 | The error source is @code{libkbx}, a library used by the crypto | 737 | The error source is @code{libkbx}, a library used by the crypto |
738 | engines to manage local keyrings. | 738 | engines to manage local keyrings. |
739 | 739 | ||
740 | @item GPG_ERR_SOURCE_USER_1 | 740 | @item GPG_ERR_SOURCE_USER_1 |
741 | @item GPG_ERR_SOURCE_USER_2 | 741 | @item GPG_ERR_SOURCE_USER_2 |
742 | @item GPG_ERR_SOURCE_USER_3 | 742 | @item GPG_ERR_SOURCE_USER_3 |
743 | @item GPG_ERR_SOURCE_USER_4 | 743 | @item GPG_ERR_SOURCE_USER_4 |
744 | These error sources are not used by any GnuPG component and can be | 744 | These error sources are not used by any GnuPG component and can be |
745 | used by other software. For example, applications using | 745 | used by other software. For example, applications using |
746 | @acronym{Libgcrypt} can use them to mark error values coming from callback | 746 | @acronym{Libgcrypt} can use them to mark error values coming from callback |
747 | handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors | 747 | handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors |
748 | created with @code{gcry_error} and @code{gcry_error_from_errno}, | 748 | created with @code{gcry_error} and @code{gcry_error_from_errno}, |
749 | unless you define @code{GCRY_ERR_SOURCE_DEFAULT} before including | 749 | unless you define @code{GCRY_ERR_SOURCE_DEFAULT} before including |
750 | @file{gcrypt.h}. | 750 | @file{gcrypt.h}. |
751 | @end table | 751 | @end table |
752 | 752 | ||
753 | 753 | ||
754 | @node Error Codes | 754 | @node Error Codes |
755 | @subsection Error Codes | 755 | @subsection Error Codes |
756 | @cindex error codes, list of | 756 | @cindex error codes, list of |
757 | 757 | ||
758 | The library @code{libgpg-error} defines many error values. The | 758 | The library @code{libgpg-error} defines many error values. The |
759 | following list includes the most important error codes. | 759 | following list includes the most important error codes. |
760 | 760 | ||
761 | @table @code | 761 | @table @code |
762 | @item GPG_ERR_EOF | 762 | @item GPG_ERR_EOF |
763 | This value indicates the end of a list, buffer or file. | 763 | This value indicates the end of a list, buffer or file. |
764 | 764 | ||
765 | @item GPG_ERR_NO_ERROR | 765 | @item GPG_ERR_NO_ERROR |
766 | This value indicates success. The value of this error code is | 766 | This value indicates success. The value of this error code is |
767 | @code{0}. Also, it is guaranteed that an error value made from the | 767 | @code{0}. Also, it is guaranteed that an error value made from the |
768 | error code @code{0} will be @code{0} itself (as a whole). This means | 768 | error code @code{0} will be @code{0} itself (as a whole). This means |
769 | that the error source information is lost for this error code, | 769 | that the error source information is lost for this error code, |
770 | however, as this error code indicates that no error occured, this is | 770 | however, as this error code indicates that no error occured, this is |
771 | generally not a problem. | 771 | generally not a problem. |
772 | 772 | ||
773 | @item GPG_ERR_GENERAL | 773 | @item GPG_ERR_GENERAL |
774 | This value means that something went wrong, but either there is not | 774 | This value means that something went wrong, but either there is not |
775 | enough information about the problem to return a more useful error | 775 | enough information about the problem to return a more useful error |
776 | value, or there is no separate error value for this type of problem. | 776 | value, or there is no separate error value for this type of problem. |
777 | 777 | ||
778 | @item GPG_ERR_ENOMEM | 778 | @item GPG_ERR_ENOMEM |
779 | This value means that an out-of-memory condition occurred. | 779 | This value means that an out-of-memory condition occurred. |
780 | 780 | ||
781 | @item GPG_ERR_E... | 781 | @item GPG_ERR_E... |
782 | System errors are mapped to GPG_ERR_EFOO where FOO is the symbol for | 782 | System errors are mapped to GPG_ERR_EFOO where FOO is the symbol for |
783 | the system error. | 783 | the system error. |
784 | 784 | ||
785 | @item GPG_ERR_INV_VALUE | 785 | @item GPG_ERR_INV_VALUE |
786 | This value means that some user provided data was out of range. | 786 | This value means that some user provided data was out of range. |
787 | 787 | ||
788 | @item GPG_ERR_UNUSABLE_PUBKEY | 788 | @item GPG_ERR_UNUSABLE_PUBKEY |
789 | This value means that some recipients for a message were invalid. | 789 | This value means that some recipients for a message were invalid. |
790 | 790 | ||
791 | @item GPG_ERR_UNUSABLE_SECKEY | 791 | @item GPG_ERR_UNUSABLE_SECKEY |
792 | This value means that some signers were invalid. | 792 | This value means that some signers were invalid. |
793 | 793 | ||
794 | @item GPG_ERR_NO_DATA | 794 | @item GPG_ERR_NO_DATA |
795 | This value means that data was expected where no data was found. | 795 | This value means that data was expected where no data was found. |
796 | 796 | ||
797 | @item GPG_ERR_CONFLICT | 797 | @item GPG_ERR_CONFLICT |
798 | This value means that a conflict of some sort occurred. | 798 | This value means that a conflict of some sort occurred. |
799 | 799 | ||
800 | @item GPG_ERR_NOT_IMPLEMENTED | 800 | @item GPG_ERR_NOT_IMPLEMENTED |
801 | This value indicates that the specific function (or operation) is not | 801 | This value indicates that the specific function (or operation) is not |
802 | implemented. This error should never happen. It can only occur if | 802 | implemented. This error should never happen. It can only occur if |
803 | you use certain values or configuration options which do not work, | 803 | you use certain values or configuration options which do not work, |
804 | but for which we think that they should work at some later time. | 804 | but for which we think that they should work at some later time. |
805 | 805 | ||
806 | @item GPG_ERR_DECRYPT_FAILED | 806 | @item GPG_ERR_DECRYPT_FAILED |
807 | This value indicates that a decryption operation was unsuccessful. | 807 | This value indicates that a decryption operation was unsuccessful. |
808 | 808 | ||
809 | @item GPG_ERR_WRONG_KEY_USAGE | 809 | @item GPG_ERR_WRONG_KEY_USAGE |
810 | This value indicates that a key is not used appropriately. | 810 | This value indicates that a key is not used appropriately. |
811 | 811 | ||
812 | @item GPG_ERR_NO_SECKEY | 812 | @item GPG_ERR_NO_SECKEY |
813 | This value indicates that no secret key for the user ID is available. | 813 | This value indicates that no secret key for the user ID is available. |
814 | 814 | ||
815 | @item GPG_ERR_UNSUPPORTED_ALGORITHM | 815 | @item GPG_ERR_UNSUPPORTED_ALGORITHM |
816 | This value means a verification failed because the cryptographic | 816 | This value means a verification failed because the cryptographic |
817 | algorithm is not supported by the crypto backend. | 817 | algorithm is not supported by the crypto backend. |
818 | 818 | ||
819 | @item GPG_ERR_BAD_SIGNATURE | 819 | @item GPG_ERR_BAD_SIGNATURE |
820 | This value means a verification failed because the signature is bad. | 820 | This value means a verification failed because the signature is bad. |
821 | 821 | ||
822 | @item GPG_ERR_NO_PUBKEY | 822 | @item GPG_ERR_NO_PUBKEY |
823 | This value means a verification failed because the public key is not | 823 | This value means a verification failed because the public key is not |
824 | available. | 824 | available. |
825 | 825 | ||
826 | @item GPG_ERR_USER_1 | 826 | @item GPG_ERR_USER_1 |
827 | @item GPG_ERR_USER_2 | 827 | @item GPG_ERR_USER_2 |
828 | @item ... | 828 | @item ... |
829 | @item GPG_ERR_USER_16 | 829 | @item GPG_ERR_USER_16 |
830 | These error codes are not used by any GnuPG component and can be | 830 | These error codes are not used by any GnuPG component and can be |
831 | freely used by other software. Applications using @acronym{Libgcrypt} | 831 | freely used by other software. Applications using @acronym{Libgcrypt} |
832 | might use them to mark specific errors returned by callback handlers | 832 | might use them to mark specific errors returned by callback handlers |
833 | if no suitable error codes (including the system errors) for these | 833 | if no suitable error codes (including the system errors) for these |
834 | errors exist already. | 834 | errors exist already. |
835 | @end table | 835 | @end table |
836 | 836 | ||
837 | 837 | ||
838 | @node Error Strings | 838 | @node Error Strings |
839 | @subsection Error Strings | 839 | @subsection Error Strings |
840 | @cindex error values, printing of | 840 | @cindex error values, printing of |
841 | @cindex error codes, printing of | 841 | @cindex error codes, printing of |
842 | @cindex error sources, printing of | 842 | @cindex error sources, printing of |
843 | @cindex error strings | 843 | @cindex error strings |
844 | 844 | ||
845 | @deftypefun {const char *} gcry_strerror (@w{gcry_error_t @var{err}}) | 845 | @deftypefun {const char *} gcry_strerror (@w{gcry_error_t @var{err}}) |
846 | The function @code{gcry_strerror} returns a pointer to a statically | 846 | The function @code{gcry_strerror} returns a pointer to a statically |
847 | allocated string containing a description of the error code contained | 847 | allocated string containing a description of the error code contained |
848 | in the error value @var{err}. This string can be used to output a | 848 | in the error value @var{err}. This string can be used to output a |
849 | diagnostic message to the user. | 849 | diagnostic message to the user. |
850 | @end deftypefun | 850 | @end deftypefun |
851 | 851 | ||
852 | 852 | ||
853 | @deftypefun {const char *} gcry_strsource (@w{gcry_error_t @var{err}}) | 853 | @deftypefun {const char *} gcry_strsource (@w{gcry_error_t @var{err}}) |
854 | The function @code{gcry_strerror} returns a pointer to a statically | 854 | The function @code{gcry_strerror} returns a pointer to a statically |
855 | allocated string containing a description of the error source | 855 | allocated string containing a description of the error source |
856 | contained in the error value @var{err}. This string can be used to | 856 | contained in the error value @var{err}. This string can be used to |
857 | output a diagnostic message to the user. | 857 | output a diagnostic message to the user. |
858 | @end deftypefun | 858 | @end deftypefun |
859 | 859 | ||
860 | The following example illustrates the use of the functions described | 860 | The following example illustrates the use of the functions described |
861 | above: | 861 | above: |
862 | 862 | ||
863 | @example | 863 | @example |
864 | @{ | 864 | @{ |
865 | gcry_cipher_hd_t handle; | 865 | gcry_cipher_hd_t handle; |
866 | gcry_error_t err = 0; | 866 | gcry_error_t err = 0; |
867 | 867 | ||
868 | err = gcry_cipher_open (&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0); | 868 | err = gcry_cipher_open (&handle, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0); |
869 | if (err) | 869 | if (err) |
870 | @{ | 870 | @{ |
871 | fprintf (stderr, "Failure: %s/%s\n", | 871 | fprintf (stderr, "Failure: %s/%s\n", |
872 | gcry_strsource (err), | 872 | gcry_strsource (err), |
873 | gcry_strerror (err)); | 873 | gcry_strerror (err)); |
874 | @} | 874 | @} |
875 | @} | 875 | @} |
876 | @end example | 876 | @end example |
877 | 877 | ||
878 | @c ********************************************************** | 878 | @c ********************************************************** |
879 | @c ******************* General **************************** | 879 | @c ******************* General **************************** |
880 | @c ********************************************************** | 880 | @c ********************************************************** |
881 | @node Handler Functions | 881 | @node Handler Functions |
882 | @chapter Handler Functions | 882 | @chapter Handler Functions |
883 | 883 | ||
884 | @acronym{Libgcrypt} makes it possible to install so called `handler functions', | 884 | @acronym{Libgcrypt} makes it possible to install so called `handler functions', |
885 | which get called by @acronym{Libgcrypt} in case of certain events. | 885 | which get called by @acronym{Libgcrypt} in case of certain events. |
886 | 886 | ||
887 | @menu | 887 | @menu |
888 | * Progress handler:: Using a progress handler function. | 888 | * Progress handler:: Using a progress handler function. |
889 | * Allocation handler:: Using special memory allocation functions. | 889 | * Allocation handler:: Using special memory allocation functions. |
890 | * Error handler:: Using error handler functions. | 890 | * Error handler:: Using error handler functions. |
891 | * Logging handler:: Using a special logging function. | 891 | * Logging handler:: Using a special logging function. |
892 | @end menu | 892 | @end menu |
893 | 893 | ||
894 | @node Progress handler | 894 | @node Progress handler |
895 | @section Progress handler | 895 | @section Progress handler |
896 | 896 | ||
897 | It is often useful to retrieve some feedback while long running | 897 | It is often useful to retrieve some feedback while long running |
898 | operations are performed. | 898 | operations are performed. |
899 | 899 | ||
900 | @deftp {Data type} gcry_handler_progress_t | 900 | @deftp {Data type} gcry_handler_progress_t |
901 | Progress handler functions have to be of the type | 901 | Progress handler functions have to be of the type |
902 | @code{gcry_handler_progress_t}, which is defined as: | 902 | @code{gcry_handler_progress_t}, which is defined as: |
903 | 903 | ||
904 | @code{void (*gcry_handler_progress_t) (void *, const char *, int, int, int)} | 904 | @code{void (*gcry_handler_progress_t) (void *, const char *, int, int, int)} |
905 | @end deftp | 905 | @end deftp |
906 | 906 | ||
907 | The following function may be used to register a handler function for | 907 | The following function may be used to register a handler function for |
908 | this purpose. | 908 | this purpose. |
909 | 909 | ||
910 | @deftypefun void gcry_set_progress_handler (gcry_handler_progress_t @var{cb}, void *@var{cb_data}) | 910 | @deftypefun void gcry_set_progress_handler (gcry_handler_progress_t @var{cb}, void *@var{cb_data}) |
911 | 911 | ||
912 | This function installs @var{cb} as the `Progress handler' function. | 912 | This function installs @var{cb} as the `Progress handler' function. |
913 | @var{cb} must be defined as follows: | 913 | @var{cb} must be defined as follows: |
914 | 914 | ||
915 | @example | 915 | @example |
916 | void | 916 | void |
917 | my_progress_handler (void *@var{cb_data}, const char *@var{what}, | 917 | my_progress_handler (void *@var{cb_data}, const char *@var{what}, |
918 | int @var{printchar}, int @var{current}, int @var{total}) | 918 | int @var{printchar}, int @var{current}, int @var{total}) |
919 | @{ | 919 | @{ |
920 | /* Do something. */ | 920 | /* Do something. */ |
921 | @} | 921 | @} |
922 | @end example | 922 | @end example |
923 | 923 | ||
924 | A description of the arguments of the progress handler function follows. | 924 | A description of the arguments of the progress handler function follows. |
925 | 925 | ||
926 | @table @var | 926 | @table @var |
927 | @item cb_data | 927 | @item cb_data |
928 | The argument provided in the call to @code{gcry_set_progress_handler}. | 928 | The argument provided in the call to @code{gcry_set_progress_handler}. |
929 | @item what | 929 | @item what |
930 | A string identifying the type of the progress output. The following | 930 | A string identifying the type of the progress output. The following |
931 | values for @var{what} are defined: | 931 | values for @var{what} are defined: |
932 | 932 | ||
933 | @table @code | 933 | @table @code |
934 | @item need_entropy | 934 | @item need_entropy |
935 | Not enough entropy is available. @var{total} holds the number of | 935 | Not enough entropy is available. @var{total} holds the number of |
936 | required bytes. | 936 | required bytes. |
937 | 937 | ||
938 | @item primegen | 938 | @item primegen |
939 | Values for @var{printchar}: | 939 | Values for @var{printchar}: |
940 | @table @code | 940 | @table @code |
941 | @item \n | 941 | @item \n |
942 | Prime generated. | 942 | Prime generated. |
943 | @item ! | 943 | @item ! |
944 | Need to refresh the pool of prime numbers. | 944 | Need to refresh the pool of prime numbers. |
945 | @item <, > | 945 | @item <, > |
946 | Number of bits adjusted. | 946 | Number of bits adjusted. |
947 | @item ^ | 947 | @item ^ |
948 | Searching for a generator. | 948 | Searching for a generator. |
949 | @item . | 949 | @item . |
950 | Fermat test on 10 candidates failed. | 950 | Fermat test on 10 candidates failed. |
951 | @item : | 951 | @item : |
952 | Restart with a new random value. | 952 | Restart with a new random value. |
953 | @item + | 953 | @item + |
954 | Rabin Miller test passed. | 954 | Rabin Miller test passed. |
955 | @end table | 955 | @end table |
956 | 956 | ||
957 | @end table | 957 | @end table |
958 | 958 | ||
959 | @end table | 959 | @end table |
960 | @end deftypefun | 960 | @end deftypefun |
961 | 961 | ||
962 | @node Allocation handler | 962 | @node Allocation handler |
963 | @section Allocation handler | 963 | @section Allocation handler |
964 | 964 | ||
965 | It is possible to make @acronym{Libgcrypt} use special memory | 965 | It is possible to make @acronym{Libgcrypt} use special memory |
966 | allocation functions instead of the built-in ones. | 966 | allocation functions instead of the built-in ones. |
967 | 967 | ||
968 | Memory allocation functions are of the following types: | 968 | Memory allocation functions are of the following types: |
969 | @deftp {Data type} gcry_handler_alloc_t | 969 | @deftp {Data type} gcry_handler_alloc_t |
970 | This type is defined as: @code{void *(*gcry_handler_alloc_t) (size_t n)}. | 970 | This type is defined as: @code{void *(*gcry_handler_alloc_t) (size_t n)}. |
971 | @end deftp | 971 | @end deftp |
972 | @deftp {Data type} gcry_handler_secure_check_t | 972 | @deftp {Data type} gcry_handler_secure_check_t |
973 | This type is defined as: @code{int *(*gcry_handler_secure_check_t) (const void *)}. | 973 | This type is defined as: @code{int *(*gcry_handler_secure_check_t) (const void *)}. |
974 | @end deftp | 974 | @end deftp |
975 | @deftp {Data type} gcry_handler_realloc_t | 975 | @deftp {Data type} gcry_handler_realloc_t |
976 | This type is defined as: @code{void *(*gcry_handler_realloc_t) (void *p, size_t n)}. | 976 | This type is defined as: @code{void *(*gcry_handler_realloc_t) (void *p, size_t n)}. |
977 | @end deftp | 977 | @end deftp |
978 | @deftp {Data type} gcry_handler_free_t | 978 | @deftp {Data type} gcry_handler_free_t |
979 | This type is defined as: @code{void *(*gcry_handler_free_t) (void *)}. | 979 | This type is defined as: @code{void *(*gcry_handler_free_t) (void *)}. |
980 | @end deftp | 980 | @end deftp |
981 | 981 | ||
982 | Special memory allocation functions can be installed with the | 982 | Special memory allocation functions can be installed with the |
983 | following function: | 983 | following function: |
984 | 984 | ||
985 | @deftypefun void gcry_set_allocation_handler (gcry_handler_alloc_t @var{func_alloc}, gcry_handler_alloc_t @var{func_alloc_secure}, gcry_handler_secure_check_t @var{func_secure_check}, gcry_handler_realloc_t @var{func_realloc}, gcry_handler_free_t @var{func_free}) | 985 | @deftypefun void gcry_set_allocation_handler (gcry_handler_alloc_t @var{func_alloc}, gcry_handler_alloc_t @var{func_alloc_secure}, gcry_handler_secure_check_t @var{func_secure_check}, gcry_handler_realloc_t @var{func_realloc}, gcry_handler_free_t @var{func_free}) |
986 | Install the provided functions and use them instead of the built-in | 986 | Install the provided functions and use them instead of the built-in |
987 | functions for doing memory allocation. | 987 | functions for doing memory allocation. |
988 | @end deftypefun | 988 | @end deftypefun |
989 | 989 | ||
990 | @node Error handler | 990 | @node Error handler |
991 | @section Error handler | 991 | @section Error handler |
992 | 992 | ||
993 | The following functions may be used to register handler functions that | 993 | The following functions may be used to register handler functions that |
994 | are called by @acronym{Libgcrypt} in case certain error conditions | 994 | are called by @acronym{Libgcrypt} in case certain error conditions |
995 | occur. | 995 | occur. |
996 | 996 | ||
997 | @deftp {Data type} gcry_handler_no_mem_t | 997 | @deftp {Data type} gcry_handler_no_mem_t |
998 | This type is defined as: @code{void (*gcry_handler_no_mem_t) (void *, size_t, unsigned int)} | 998 | This type is defined as: @code{void (*gcry_handler_no_mem_t) (void *, size_t, unsigned int)} |
999 | @end deftp | 999 | @end deftp |
1000 | @deftypefun void gcry_set_outofcore_handler (gcry_handler_no_mem_t @var{func_no_mem}, void *@var{cb_data}) | 1000 | @deftypefun void gcry_set_outofcore_handler (gcry_handler_no_mem_t @var{func_no_mem}, void *@var{cb_data}) |
1001 | This function registers @var{func_no_mem} as `out-of-core handler', | 1001 | This function registers @var{func_no_mem} as `out-of-core handler', |
1002 | which means that it will be called in the case of not having enough | 1002 | which means that it will be called in the case of not having enough |
1003 | memory available. | 1003 | memory available. |
1004 | @end deftypefun | 1004 | @end deftypefun |
1005 | 1005 | ||
1006 | @deftp {Data type} gcry_handler_error_t | 1006 | @deftp {Data type} gcry_handler_error_t |
1007 | This type is defined as: @code{void (*gcry_handler_error_t) (void *, int, const char *)} | 1007 | This type is defined as: @code{void (*gcry_handler_error_t) (void *, int, const char *)} |
1008 | @end deftp | 1008 | @end deftp |
1009 | 1009 | ||
1010 | @deftypefun void gcry_set_fatalerror_handler (gcry_handler_error_t @var{func_error}, void *@var{cb_data}) | 1010 | @deftypefun void gcry_set_fatalerror_handler (gcry_handler_error_t @var{func_error}, void *@var{cb_data}) |
1011 | This function registers @var{func_error} as `error handler', | 1011 | This function registers @var{func_error} as `error handler', |
1012 | which means that it will be called in error conditions. | 1012 | which means that it will be called in error conditions. |
1013 | @end deftypefun | 1013 | @end deftypefun |
1014 | 1014 | ||
1015 | @node Logging handler | 1015 | @node Logging handler |
1016 | @section Logging handler | 1016 | @section Logging handler |
1017 | 1017 | ||
1018 | @deftp {Data type} gcry_handler_log_t | 1018 | @deftp {Data type} gcry_handler_log_t |
1019 | This type is defined as: @code{void (*gcry_handler_log_t) (void *, int, const char *, va_list)} | 1019 | This type is defined as: @code{void (*gcry_handler_log_t) (void *, int, const char *, va_list)} |
1020 | @end deftp | 1020 | @end deftp |
1021 | 1021 | ||
1022 | @deftypefun void gcry_set_log_handler (gcry_handler_log_t @var{func_log}, void *@var{cb_data}) | 1022 | @deftypefun void gcry_set_log_handler (gcry_handler_log_t @var{func_log}, void *@var{cb_data}) |
1023 | This function registers @var{func_log} as `logging handler', which | 1023 | This function registers @var{func_log} as `logging handler', which |
1024 | means that it will be called in case @acronym{Libgcrypt} wants to log | 1024 | means that it will be called in case @acronym{Libgcrypt} wants to log |
1025 | a message. | 1025 | a message. |
1026 | @end deftypefun | 1026 | @end deftypefun |
1027 | 1027 | ||
1028 | @c ********************************************************** | 1028 | @c ********************************************************** |
1029 | @c ******************* Ciphers **************************** | 1029 | @c ******************* Ciphers **************************** |
1030 | @c ********************************************************** | 1030 | @c ********************************************************** |
1031 | @c @include cipher-ref.texi | 1031 | @c @include cipher-ref.texi |
1032 | @node Symmetric cryptography | 1032 | @node Symmetric cryptography |
1033 | @chapter Symmetric cryptography | 1033 | @chapter Symmetric cryptography |
1034 | 1034 | ||
1035 | The cipher functions are used for symmetrical cryptography, | 1035 | The cipher functions are used for symmetrical cryptography, |
1036 | i.e. cryptography using a shared key. The programming model follows | 1036 | i.e. cryptography using a shared key. The programming model follows |
1037 | an open/process/close paradigm and is in that similar to other | 1037 | an open/process/close paradigm and is in that similar to other |
1038 | building blocks provided by @acronym{Libgcrypt}. | 1038 | building blocks provided by @acronym{Libgcrypt}. |
1039 | 1039 | ||
1040 | @menu | 1040 | @menu |
1041 | * Available ciphers:: List of ciphers supported by the library. | 1041 | * Available ciphers:: List of ciphers supported by the library. |
1042 | * Cipher modules:: How to work with cipher modules. | 1042 | * Cipher modules:: How to work with cipher modules. |
1043 | * Available cipher modes:: List of cipher modes supported by the library. | 1043 | * Available cipher modes:: List of cipher modes supported by the library. |
1044 | * Working with cipher handles:: How to perform operations related to cipher handles. | 1044 | * Working with cipher handles:: How to perform operations related to cipher handles. |
1045 | * General cipher functions:: General cipher functions independent of cipher handles. | 1045 | * General cipher functions:: General cipher functions independent of cipher handles. |
1046 | @end menu | 1046 | @end menu |
1047 | 1047 | ||
1048 | @node Available ciphers | 1048 | @node Available ciphers |
1049 | @section Available ciphers | 1049 | @section Available ciphers |
1050 | 1050 | ||
1051 | @table @code | 1051 | @table @code |
1052 | @item GCRY_CIPHER_NONE | 1052 | @item GCRY_CIPHER_NONE |
1053 | This is not a real algorithm but used by some functions as error return. | 1053 | This is not a real algorithm but used by some functions as error return. |
1054 | The value always evaluates to false. | 1054 | The value always evaluates to false. |
1055 | 1055 | ||
1056 | @item GCRY_CIPHER_IDEA | 1056 | @item GCRY_CIPHER_IDEA |
1057 | This is the IDEA algorithm. The constant is provided but there is | 1057 | This is the IDEA algorithm. The constant is provided but there is |
1058 | currently no implementation for it because the algorithm is patented. | 1058 | currently no implementation for it because the algorithm is patented. |
1059 | 1059 | ||
1060 | @item GCRY_CIPHER_3DES | 1060 | @item GCRY_CIPHER_3DES |
1061 | Triple-DES with 3 Keys as EDE. The key size of this algorithm is 168 but | 1061 | Triple-DES with 3 Keys as EDE. The key size of this algorithm is 168 but |
1062 | you have to pass 192 bits because the most significant bits of each byte | 1062 | you have to pass 192 bits because the most significant bits of each byte |
1063 | are ignored. | 1063 | are ignored. |
1064 | 1064 | ||
1065 | @item GCRY_CIPHER_CAST5 | 1065 | @item GCRY_CIPHER_CAST5 |
1066 | CAST128-5 block cipher algorithm. The key size is 128 bits. | 1066 | CAST128-5 block cipher algorithm. The key size is 128 bits. |
1067 | 1067 | ||
1068 | @item GCRY_CIPHER_BLOWFISH | 1068 | @item GCRY_CIPHER_BLOWFISH |
1069 | The blowfish algorithm. The current implementation allows only for a key | 1069 | The blowfish algorithm. The current implementation allows only for a key |
1070 | size of 128 bits. | 1070 | size of 128 bits. |
1071 | 1071 | ||
1072 | @item GCRY_CIPHER_SAFER_SK128 | 1072 | @item GCRY_CIPHER_SAFER_SK128 |
1073 | Reserved and not currently implemented. | 1073 | Reserved and not currently implemented. |
1074 | 1074 | ||
1075 | @item GCRY_CIPHER_DES_SK | 1075 | @item GCRY_CIPHER_DES_SK |
1076 | Reserved and not currently implemented. | 1076 | Reserved and not currently implemented. |
1077 | 1077 | ||
1078 | @item GCRY_CIPHER_AES | 1078 | @item GCRY_CIPHER_AES |
1079 | @itemx GCRY_CIPHER_AES128 | 1079 | @itemx GCRY_CIPHER_AES128 |
1080 | @itemx GCRY_CIPHER_RIJNDAEL | 1080 | @itemx GCRY_CIPHER_RIJNDAEL |
1081 | @itemx GCRY_CIPHER_RIJNDAEL128 | 1081 | @itemx GCRY_CIPHER_RIJNDAEL128 |
1082 | AES (Rijndael) with a 128 bit key. | 1082 | AES (Rijndael) with a 128 bit key. |
1083 | 1083 | ||
1084 | @item GCRY_CIPHER_AES192 | 1084 | @item GCRY_CIPHER_AES192 |
1085 | @itemx GCRY_CIPHER_RIJNDAEL128 | 1085 | @itemx GCRY_CIPHER_RIJNDAEL128 |
1086 | AES (Rijndael) with a 192 bit key. | 1086 | AES (Rijndael) with a 192 bit key. |
1087 | 1087 | ||
1088 | @item GCRY_CIPHER_AES256 | 1088 | @item GCRY_CIPHER_AES256 |
1089 | @itemx GCRY_CIPHER_RIJNDAEL256 | 1089 | @itemx GCRY_CIPHER_RIJNDAEL256 |
1090 | AES (Rijndael) with a 256 bit key. | 1090 | AES (Rijndael) with a 256 bit key. |
1091 | 1091 | ||
1092 | @item GCRY_CIPHER_TWOFISH | 1092 | @item GCRY_CIPHER_TWOFISH |
1093 | The Twofish algorithm with a 256 bit key. | 1093 | The Twofish algorithm with a 256 bit key. |
1094 | 1094 | ||
1095 | @item GCRY_CIPHER_TWOFISH128 | 1095 | @item GCRY_CIPHER_TWOFISH128 |
1096 | The Twofish algorithm with a 128 bit key. | 1096 | The Twofish algorithm with a 128 bit key. |
1097 | 1097 | ||
1098 | @item GCRY_CIPHER_ARCFOUR | 1098 | @item GCRY_CIPHER_ARCFOUR |
1099 | An algorithm which is 100% compatible with RSA Inc.'s RC4 algorithm. | 1099 | An algorithm which is 100% compatible with RSA Inc.'s RC4 algorithm. |
1100 | Note that this is a stream cipher and must be used very carefully to | 1100 | Note that this is a stream cipher and must be used very carefully to |
1101 | avoid a couple of weaknesses. | 1101 | avoid a couple of weaknesses. |
1102 | 1102 | ||
1103 | @item GCRY_CIPHER_DES | 1103 | @item GCRY_CIPHER_DES |
1104 | Standard DES with a 56 bit key. You need to pass 64 bit but the high | 1104 | Standard DES with a 56 bit key. You need to pass 64 bit but the high |
1105 | bits of each byte are ignored. Note, that this is a weak algorithm | 1105 | bits of each byte are ignored. Note, that this is a weak algorithm |
1106 | which can be broken in reasonable time using a brute force approach. | 1106 | which can be broken in reasonable time using a brute force approach. |
1107 | 1107 | ||
1108 | @end table | 1108 | @end table |
1109 | 1109 | ||
1110 | @node Cipher modules | 1110 | @node Cipher modules |
1111 | @section Cipher modules | 1111 | @section Cipher modules |
1112 | 1112 | ||
1113 | @acronym{Libgcrypt} makes it possible to load additional `cipher | 1113 | @acronym{Libgcrypt} makes it possible to load additional `cipher |
1114 | modules'; these cipher can be used just like the cipher algorithms | 1114 | modules'; these cipher can be used just like the cipher algorithms |
1115 | that are built into the library directly. For an introduction into | 1115 | that are built into the library directly. For an introduction into |
1116 | extension modules, see @xref{Modules}. | 1116 | extension modules, see @xref{Modules}. |
1117 | 1117 | ||
1118 | @deftp {Data type} gcry_cipher_spec_t | 1118 | @deftp {Data type} gcry_cipher_spec_t |
1119 | This is the `module specification structure' needed for registering | 1119 | This is the `module specification structure' needed for registering |
1120 | cipher modules, which has to be filled in by the user before it can be | 1120 | cipher modules, which has to be filled in by the user before it can be |
1121 | used to register a module. It contains the following members: | 1121 | used to register a module. It contains the following members: |
1122 | 1122 | ||
1123 | @table @code | 1123 | @table @code |
1124 | @item const char *name | 1124 | @item const char *name |
1125 | The primary name of the algorithm. | 1125 | The primary name of the algorithm. |
1126 | @item const char **aliases | 1126 | @item const char **aliases |
1127 | A list of strings that are `aliases' for the algorithm. The list must | 1127 | A list of strings that are `aliases' for the algorithm. The list must |
1128 | be terminated with a NULL element. | 1128 | be terminated with a NULL element. |
1129 | @item gcry_cipher_oid_spec_t *oids | 1129 | @item gcry_cipher_oid_spec_t *oids |
1130 | A list of OIDs that are to be associated with the algorithm. The | 1130 | A list of OIDs that are to be associated with the algorithm. The |
1131 | list's last element must have it's `oid' member set to NULL. See | 1131 | list's last element must have it's `oid' member set to NULL. See |
1132 | below for an explanation of this type. | 1132 | below for an explanation of this type. |
1133 | @item size_t blocksize | 1133 | @item size_t blocksize |
1134 | The block size of the algorithm, in bytes. | 1134 | The block size of the algorithm, in bytes. |
1135 | @item size_t keylen | 1135 | @item size_t keylen |
1136 | The length of the key, in bits. | 1136 | The length of the key, in bits. |
1137 | @item size_t contextsize | 1137 | @item size_t contextsize |
1138 | The size of the algorithm-specific `context', that should be allocated | 1138 | The size of the algorithm-specific `context', that should be allocated |
1139 | for each handle. | 1139 | for each handle. |
1140 | @item gcry_cipher_setkey_t setkey | 1140 | @item gcry_cipher_setkey_t setkey |
1141 | The function responsible for initializing a handle with a provided | 1141 | The function responsible for initializing a handle with a provided |
1142 | key. See below for a description of this type. | 1142 | key. See below for a description of this type. |
1143 | @item gcry_cipher_encrypt_t encrypt | 1143 | @item gcry_cipher_encrypt_t encrypt |
1144 | The function responsible for encrypting a single block. See below for | 1144 | The function responsible for encrypting a single block. See below for |
1145 | a description of this type. | 1145 | a description of this type. |
1146 | @item gcry_cipher_decrypt_t decrypt | 1146 | @item gcry_cipher_decrypt_t decrypt |
1147 | The function responsible for decrypting a single block. See below for | 1147 | The function responsible for decrypting a single block. See below for |
1148 | a description of this type. | 1148 | a description of this type. |
1149 | @item gcry_cipher_stencrypt_t stencrypt | 1149 | @item gcry_cipher_stencrypt_t stencrypt |
1150 | Like `encrypt', for stream ciphers. See below for a description of | 1150 | Like `encrypt', for stream ciphers. See below for a description of |
1151 | this type. | 1151 | this type. |
1152 | @item gcry_cipher_stdecrypt_t stdecrypt | 1152 | @item gcry_cipher_stdecrypt_t stdecrypt |
1153 | Like `decrypt', for stream ciphers. See below for a description of | 1153 | Like `decrypt', for stream ciphers. See below for a description of |
1154 | this type. | 1154 | this type. |
1155 | @end table | 1155 | @end table |
1156 | @end deftp | 1156 | @end deftp |
1157 | 1157 | ||
1158 | @deftp {Data type} gcry_cipher_oid_spec_t | 1158 | @deftp {Data type} gcry_cipher_oid_spec_t |
1159 | This type is used for associating a user-provided algorithm | 1159 | This type is used for associating a user-provided algorithm |
1160 | implementation with certain OIDs. It contains the following members: | 1160 | implementation with certain OIDs. It contains the following members: |
1161 | @table @code | 1161 | @table @code |
1162 | @item const char *oid | 1162 | @item const char *oid |
1163 | Textual representation of the OID. | 1163 | Textual representation of the OID. |
1164 | @item int mode | 1164 | @item int mode |
1165 | Cipher mode for which this OID is valid. | 1165 | Cipher mode for which this OID is valid. |
1166 | @end table | 1166 | @end table |
1167 | @end deftp | 1167 | @end deftp |
1168 | 1168 | ||
1169 | @deftp {Data type} gcry_cipher_setkey_t | 1169 | @deftp {Data type} gcry_cipher_setkey_t |
1170 | Type for the `setkey' function, defined as: gcry_err_code_t | 1170 | Type for the `setkey' function, defined as: gcry_err_code_t |
1171 | (*gcry_cipher_setkey_t) (void *c, const unsigned char *key, unsigned | 1171 | (*gcry_cipher_setkey_t) (void *c, const unsigned char *key, unsigned |
1172 | keylen) | 1172 | keylen) |
1173 | @end deftp | 1173 | @end deftp |
1174 | 1174 | ||
1175 | @deftp {Data type} gcry_cipher_encrypt_t | 1175 | @deftp {Data type} gcry_cipher_encrypt_t |
1176 | Type for the `encrypt' function, defined as: gcry_err_code_t | 1176 | Type for the `encrypt' function, defined as: gcry_err_code_t |
1177 | (*gcry_cipher_encrypt_t) (void *c, const unsigned char *outbuf, const | 1177 | (*gcry_cipher_encrypt_t) (void *c, const unsigned char *outbuf, const |
1178 | unsigned char *inbuf) | 1178 | unsigned char *inbuf) |
1179 | @end deftp | 1179 | @end deftp |
1180 | 1180 | ||
1181 | @deftp {Data type} gcry_cipher_decrypt_t | 1181 | @deftp {Data type} gcry_cipher_decrypt_t |
1182 | Type for the `decrypt' function, defined as: gcry_err_code_t | 1182 | Type for the `decrypt' function, defined as: gcry_err_code_t |
1183 | (*gcry_cipher_decrypt_t) (void *c, const unsigned char *outbuf, const | 1183 | (*gcry_cipher_decrypt_t) (void *c, const unsigned char *outbuf, const |
1184 | unsigned char *inbuf) | 1184 | unsigned char *inbuf) |
1185 | @end deftp | 1185 | @end deftp |
1186 | 1186 | ||
1187 | @deftp {Data type} gcry_cipher_stencrypt_t | 1187 | @deftp {Data type} gcry_cipher_stencrypt_t |
1188 | Type for the `stencrypt' function, defined as: gcry_err_code_t | 1188 | Type for the `stencrypt' function, defined as: gcry_err_code_t |
1189 | (*gcry_cipher_stencrypt_t) (void *c, const unsigned char *outbuf, const | 1189 | (*gcry_cipher_stencrypt_t) (void *c, const unsigned char *outbuf, const |
1190 | unsigned char *, unsigned int n) | 1190 | unsigned char *, unsigned int n) |
1191 | @end deftp | 1191 | @end deftp |
1192 | 1192 | ||
1193 | @deftp {Data type} gcry_cipher_stdecrypt_t | 1193 | @deftp {Data type} gcry_cipher_stdecrypt_t |
1194 | Type for the `stdecrypt' function, defined as: gcry_err_code_t | 1194 | Type for the `stdecrypt' function, defined as: gcry_err_code_t |
1195 | (*gcry_cipher_stdecrypt_t) (void *c, const unsigned char *outbuf, const | 1195 | (*gcry_cipher_stdecrypt_t) (void *c, const unsigned char *outbuf, const |
1196 | unsigned char *, unsigned int n) | 1196 | unsigned char *, unsigned int n) |
1197 | @end deftp | 1197 | @end deftp |
1198 | 1198 | ||
1199 | @deftypefun gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *@var{cipher}, unsigned int *algorithm_id, gcry_module_t *@var{module}) | 1199 | @deftypefun gcry_error_t gcry_cipher_register (gcry_cipher_spec_t *@var{cipher}, unsigned int *algorithm_id, gcry_module_t *@var{module}) |
1200 | 1200 | ||
1201 | Register a new cipher module whose specification can be found in | 1201 | Register a new cipher module whose specification can be found in |
1202 | @var{cipher}. On success, a new algorithm ID is stored in | 1202 | @var{cipher}. On success, a new algorithm ID is stored in |
1203 | @var{algorithm_id} and a pointer representing this module is stored | 1203 | @var{algorithm_id} and a pointer representing this module is stored |
1204 | in @var{module}. | 1204 | in @var{module}. |
1205 | @end deftypefun | 1205 | @end deftypefun |
1206 | 1206 | ||
1207 | @deftypefun void gcry_cipher_unregister (gcry_module_t @var{module}) | 1207 | @deftypefun void gcry_cipher_unregister (gcry_module_t @var{module}) |
1208 | Unregister the cipher identified by @var{module}, which must have been | 1208 | Unregister the cipher identified by @var{module}, which must have been |
1209 | registered with gcry_cipher_register. | 1209 | registered with gcry_cipher_register. |
1210 | @end deftypefun | 1210 | @end deftypefun |
1211 | 1211 | ||
1212 | @deftypefun gcry_error_t gcry_cipher_list (int *@var{list}, int *@var{list_length}) | 1212 | @deftypefun gcry_error_t gcry_cipher_list (int *@var{list}, int *@var{list_length}) |
1213 | Get a list consisting of the IDs of the loaded cipher modules. If | 1213 | Get a list consisting of the IDs of the loaded cipher modules. If |
1214 | @var{list} is zero, write the number of loaded cipher modules to | 1214 | @var{list} is zero, write the number of loaded cipher modules to |
1215 | @var{list_length} and return. If @var{list} is non-zero, the first | 1215 | @var{list_length} and return. If @var{list} is non-zero, the first |
1216 | *@var{list_length} algorithm IDs are stored in @var{list}, which must | 1216 | *@var{list_length} algorithm IDs are stored in @var{list}, which must |
1217 | be of according size. In case there are less cipher modules than | 1217 | be of according size. In case there are less cipher modules than |
1218 | *@var{list_length}, *@var{list_length} is updated to the correct | 1218 | *@var{list_length}, *@var{list_length} is updated to the correct |
1219 | number. | 1219 | number. |
1220 | @end deftypefun | 1220 | @end deftypefun |
1221 | 1221 | ||
1222 | @node Available cipher modes | 1222 | @node Available cipher modes |
1223 | @section Available cipher modes | 1223 | @section Available cipher modes |
1224 | 1224 | ||
1225 | @table @code | 1225 | @table @code |
1226 | @item GCRY_CIPHER_MODE_NONE | 1226 | @item GCRY_CIPHER_MODE_NONE |
1227 | No mode specified, may be set later using other functions. The value | 1227 | No mode specified, may be set later using other functions. The value |
1228 | of this constant is always 0. | 1228 | of this constant is always 0. |
1229 | 1229 | ||
1230 | @item GCRY_CIPHER_MODE_ECB | 1230 | @item GCRY_CIPHER_MODE_ECB |
1231 | Electronic Codebook mode. | 1231 | Electronic Codebook mode. |
1232 | 1232 | ||
1233 | @item GCRY_CIPHER_MODE_CFB | 1233 | @item GCRY_CIPHER_MODE_CFB |
1234 | Cipher Feedback mode. | 1234 | Cipher Feedback mode. |
1235 | 1235 | ||
1236 | @item GCRY_CIPHER_MODE_CBC | 1236 | @item GCRY_CIPHER_MODE_CBC |
1237 | Cipher Block Chaining mode. | 1237 | Cipher Block Chaining mode. |
1238 | 1238 | ||
1239 | @item GCRY_CIPHER_MODE_STREAM | 1239 | @item GCRY_CIPHER_MODE_STREAM |
1240 | Stream mode, only to be used with stream cipher algorithms. | 1240 | Stream mode, only to be used with stream cipher algorithms. |
1241 | 1241 | ||
1242 | @item GCRY_CIPHER_MODE_OFB | 1242 | @item GCRY_CIPHER_MODE_OFB |
1243 | Outer Feedback mode. | 1243 | Outer Feedback mode. |
1244 | 1244 | ||
1245 | @item GCRY_CIPHER_MODE_CTR | 1245 | @item GCRY_CIPHER_MODE_CTR |
1246 | Counter mode. | 1246 | Counter mode. |
1247 | 1247 | ||
1248 | @end table | 1248 | @end table |
1249 | 1249 | ||
1250 | @node Working with cipher handles | 1250 | @node Working with cipher handles |
1251 | @section Working with cipher handles | 1251 | @section Working with cipher handles |
1252 | 1252 | ||
1253 | To use a cipher algorithm, you must first allocate an according | 1253 | To use a cipher algorithm, you must first allocate an according |
1254 | handle. This is to be done using the open function: | 1254 | handle. This is to be done using the open function: |
1255 | 1255 | ||
1256 | @deftypefun gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *@var{hd}, int @var{algo}, int @var{mode}, unsigned int @var{flags}) | 1256 | @deftypefun gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *@var{hd}, int @var{algo}, int @var{mode}, unsigned int @var{flags}) |
1257 | 1257 | ||
1258 | This function creates the context handle required for most of the | 1258 | This function creates the context handle required for most of the |
1259 | other cipher functions and returns a handle to it in `hd'. In case of | 1259 | other cipher functions and returns a handle to it in `hd'. In case of |
1260 | an error, an according error code is returned. | 1260 | an error, an according error code is returned. |
1261 | 1261 | ||
1262 | The ID of algorithm to use must be specified via @var{algo}. See | 1262 | The ID of algorithm to use must be specified via @var{algo}. See |
1263 | @xref{Available ciphers}, for a list of supported ciphers and the | 1263 | @xref{Available ciphers}, for a list of supported ciphers and the |
1264 | according constants. | 1264 | according constants. |
1265 | 1265 | ||
1266 | Besides using the constants directly, the function | 1266 | Besides using the constants directly, the function |
1267 | @code{gcry_cipher_map_name} may be used to convert the textual name of | 1267 | @code{gcry_cipher_map_name} may be used to convert the textual name of |
1268 | an algorithm into the according numeric ID. | 1268 | an algorithm into the according numeric ID. |
1269 | 1269 | ||
1270 | The cipher mode to use must be specified via @var{mode}. See | 1270 | The cipher mode to use must be specified via @var{mode}. See |
1271 | @xref{Available cipher modes}, for a list of supported cipher modes | 1271 | @xref{Available cipher modes}, for a list of supported cipher modes |
1272 | and the according constants. Note, that some modes do not work | 1272 | and the according constants. Note, that some modes do not work |
1273 | together with all algorithms. | 1273 | together with all algorithms. |
1274 | 1274 | ||
1275 | The third argument @var{flags} can either be passed as @code{0} or as | 1275 | The third argument @var{flags} can either be passed as @code{0} or as |
1276 | the bit-wise OR of the following constants. | 1276 | the bit-wise OR of the following constants. |
1277 | 1277 | ||
1278 | @table @code | 1278 | @table @code |
1279 | @item GCRY_CIPHER_SECURE | 1279 | @item GCRY_CIPHER_SECURE |
1280 | Make sure that all operations are allocated in secure memory. This is | 1280 | Make sure that all operations are allocated in secure memory. This is |
1281 | useful, when the key material is highly confidential. | 1281 | useful, when the key material is highly confidential. |
1282 | @item GCRY_CIPHER_ENABLE_SYNC | 1282 | @item GCRY_CIPHER_ENABLE_SYNC |
1283 | This flag enables the CFB sync mode, which is a special feature of | 1283 | This flag enables the CFB sync mode, which is a special feature of |
1284 | @acronym{Libgcrypt}'s CFB mode implementation to allow for OpenPGP's CFB variant. | 1284 | @acronym{Libgcrypt}'s CFB mode implementation to allow for OpenPGP's CFB variant. |
1285 | See @code{gcry_cipher_sync}. | 1285 | See @code{gcry_cipher_sync}. |
1286 | @item GCRY_CIPHER_CBC_CTS | 1286 | @item GCRY_CIPHER_CBC_CTS |
1287 | Enable cipher text stealing (CTS) for the CBC mode. Cannot be used | 1287 | Enable cipher text stealing (CTS) for the CBC mode. Cannot be used |
1288 | simultaneous as GCRY_CIPHER_CBC_MAC | 1288 | simultaneous as GCRY_CIPHER_CBC_MAC |
1289 | @item GCRY_CIPHER_CBC_MAC | 1289 | @item GCRY_CIPHER_CBC_MAC |
1290 | Compute CBC-MAC keyed checksums. This is the same as CBC mode, but | 1290 | Compute CBC-MAC keyed checksums. This is the same as CBC mode, but |
1291 | only output the last block. Cannot be used simultaneous as | 1291 | only output the last block. Cannot be used simultaneous as |
1292 | GCRY_CIPHER_CBC_CTS. | 1292 | GCRY_CIPHER_CBC_CTS. |
1293 | @end table | 1293 | @end table |
1294 | @end deftypefun | 1294 | @end deftypefun |
1295 | 1295 | ||
1296 | Use the following function to release an existing handle: | 1296 | Use the following function to release an existing handle: |
1297 | 1297 | ||
1298 | @deftypefun void gcry_cipher_close (gcry_cipher_hd_t @var{h}) | 1298 | @deftypefun void gcry_cipher_close (gcry_cipher_hd_t @var{h}) |
1299 | 1299 | ||
1300 | This function releases the context created by @code{gcry_cipher_open}. | 1300 | This function releases the context created by @code{gcry_cipher_open}. |
1301 | @end deftypefun | 1301 | @end deftypefun |
1302 | 1302 | ||
1303 | In order to use a handle for performing cryptographic operations, a | 1303 | In order to use a handle for performing cryptographic operations, a |
1304 | `key' has to be set first: | 1304 | `key' has to be set first: |
1305 | 1305 | ||
1306 | @deftypefun gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t @var{h}, void *@var{k}, size_t @var{l}) | 1306 | @deftypefun gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t @var{h}, void *@var{k}, size_t @var{l}) |
1307 | 1307 | ||
1308 | Set the key @var{k} used for encryption or decryption in the context | 1308 | Set the key @var{k} used for encryption or decryption in the context |
1309 | denoted by the handle @var{h}. The length @var{l} of the key @var{k} | 1309 | denoted by the handle @var{h}. The length @var{l} of the key @var{k} |
1310 | must match the required length of the algorithm set for this context or | 1310 | must match the required length of the algorithm set for this context or |
1311 | be in the allowed range for algorithms with variable key size. The | 1311 | be in the allowed range for algorithms with variable key size. The |
1312 | function checks this and returns an error if there is a problem. A | 1312 | function checks this and returns an error if there is a problem. A |
1313 | caller should always check for an error. | 1313 | caller should always check for an error. |
1314 | 1314 | ||
1315 | Note, this is currently implemented as a macro but may be changed to a | 1315 | Note, this is currently implemented as a macro but may be changed to a |
1316 | function in the future. | 1316 | function in the future. |
1317 | @end deftypefun | 1317 | @end deftypefun |
1318 | 1318 | ||
1319 | Most crypto modes requires an initialization vector (IV), which | 1319 | Most crypto modes requires an initialization vector (IV), which |
1320 | usually is a non-secret random string acting as a kind of salt value. | 1320 | usually is a non-secret random string acting as a kind of salt value. |
1321 | The CTR mode requires a counter, which is also similar to a salt | 1321 | The CTR mode requires a counter, which is also similar to a salt |
1322 | value. To set the IV or CTR, use these functions: | 1322 | value. To set the IV or CTR, use these functions: |
1323 | 1323 | ||
1324 | @deftypefun gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t @var{h}, void *@var{k}, size_t @var{l}) | 1324 | @deftypefun gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t @var{h}, void *@var{k}, size_t @var{l}) |
1325 | 1325 | ||
1326 | Set the initialization vector used for encryption or decryption. The | 1326 | Set the initialization vector used for encryption or decryption. The |
1327 | vector is passed as the buffer @var{K} of length @var{l} and copied to | 1327 | vector is passed as the buffer @var{K} of length @var{l} and copied to |
1328 | internal data structures. The function checks that the IV matches the | 1328 | internal data structures. The function checks that the IV matches the |
1329 | requirement of the selected algorithm and mode. Note, that this is | 1329 | requirement of the selected algorithm and mode. Note, that this is |
1330 | implemented as a macro. | 1330 | implemented as a macro. |
1331 | @end deftypefun | 1331 | @end deftypefun |
1332 | 1332 | ||
1333 | @deftypefun gcry_error_t gcry_cipher_setctr (gcry_cipher_hd_t @var{h}, void *@var{c}, size_t @var{l}) | 1333 | @deftypefun gcry_error_t gcry_cipher_setctr (gcry_cipher_hd_t @var{h}, void *@var{c}, size_t @var{l}) |
1334 | 1334 | ||
1335 | Set the counter vector used for encryption or decryption. The counter | 1335 | Set the counter vector used for encryption or decryption. The counter |
1336 | is passed as the buffer @var{c} of length @var{l} and copied to | 1336 | is passed as the buffer @var{c} of length @var{l} and copied to |
1337 | internal data structures. The function checks that the counter | 1337 | internal data structures. The function checks that the counter |
1338 | matches the requirement of the selected algorithm (i.e., it must be | 1338 | matches the requirement of the selected algorithm (i.e., it must be |
1339 | the same size as the block size). Note, that this is implemented as a | 1339 | the same size as the block size). Note, that this is implemented as a |
1340 | macro. | 1340 | macro. |
1341 | @end deftypefun | 1341 | @end deftypefun |
1342 | 1342 | ||
1343 | @deftypefun gcry_error_t gcry_cipher_reset (gcry_cipher_hd_t @var{h}) | 1343 | @deftypefun gcry_error_t gcry_cipher_reset (gcry_cipher_hd_t @var{h}) |
1344 | 1344 | ||
1345 | Set the given handle's context back to the state it had after the last | 1345 | Set the given handle's context back to the state it had after the last |
1346 | call to gcry_cipher_setkey and clear the initialization vector. | 1346 | call to gcry_cipher_setkey and clear the initialization vector. |
1347 | 1347 | ||
1348 | Note, that gcry_cipher_reset is implemented as a macro. | 1348 | Note, that gcry_cipher_reset is implemented as a macro. |
1349 | @end deftypefun | 1349 | @end deftypefun |
1350 | 1350 | ||
1351 | The actual encryption and decryption is done by using one of the | 1351 | The actual encryption and decryption is done by using one of the |
1352 | following functions. They may be used as often as required to process | 1352 | following functions. They may be used as often as required to process |
1353 | all the data. | 1353 | all the data. |
1354 | 1354 | ||
1355 | @deftypefun gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t @var{h}, void *{out}, size_t @var{outsize}, const void *@var{in}, size_t @var{inlen}) | 1355 | @deftypefun gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t @var{h}, void *{out}, size_t @var{outsize}, const void *@var{in}, size_t @var{inlen}) |
1356 | 1356 | ||
1357 | @code{gcry_cipher_encrypt} is used to encrypt the data. This function | 1357 | @code{gcry_cipher_encrypt} is used to encrypt the data. This function |
1358 | can either work in place or with two buffers. It uses the cipher | 1358 | can either work in place or with two buffers. It uses the cipher |
1359 | context already setup and described by the handle @var{h}. There are 2 | 1359 | context already setup and described by the handle @var{h}. There are 2 |
1360 | ways to use the function: If @var{in} is passed as @code{NULL} and | 1360 | ways to use the function: If @var{in} is passed as @code{NULL} and |
1361 | @var{inlen} is @code{0}, in-place encryption of the data in @var{out} or | 1361 | @var{inlen} is @code{0}, in-place encryption of the data in @var{out} or |
1362 | length @var{outsize} takes place. With @var{in} being not @code{NULL}, | 1362 | length @var{outsize} takes place. With @var{in} being not @code{NULL}, |
1363 | @var{inlen} bytes are encrypted to the buffer @var{out} which must have | 1363 | @var{inlen} bytes are encrypted to the buffer @var{out} which must have |
1364 | at least a size of @var{inlen}. @var{outlen} must be set to the | 1364 | at least a size of @var{inlen}. @var{outlen} must be set to the |
1365 | allocated size of @var{out}, so that the function can check that there | 1365 | allocated size of @var{out}, so that the function can check that there |
1366 | is sufficient space. Note, that overlapping buffers are not allowed. | 1366 | is sufficient space. Note, that overlapping buffers are not allowed. |
1367 | 1367 | ||
1368 | Depending on the selected algorithms and encryption mode, the length of | 1368 | Depending on the selected algorithms and encryption mode, the length of |
1369 | the buffers must be a multiple of the block size. | 1369 | the buffers must be a multiple of the block size. |
1370 | 1370 | ||
1371 | The function returns @code{0} on success or an error code. | 1371 | The function returns @code{0} on success or an error code. |
1372 | @end deftypefun | 1372 | @end deftypefun |
1373 | 1373 | ||
1374 | 1374 | ||
1375 | @deftypefun gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t @var{h}, void *{out}, size_t @var{outsize}, const void *@var{in}, size_t @var{inlen}) | 1375 | @deftypefun gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t @var{h}, void *{out}, size_t @var{outsize}, const void *@var{in}, size_t @var{inlen}) |
1376 | 1376 | ||
1377 | @code{gcry_cipher_decrypt} is used to decrypt the data. This function | 1377 | @code{gcry_cipher_decrypt} is used to decrypt the data. This function |
1378 | can either work in place or with two buffers. It uses the cipher | 1378 | can either work in place or with two buffers. It uses the cipher |
1379 | context already setup and described by the handle @var{h}. There are 2 | 1379 | context already setup and described by the handle @var{h}. There are 2 |
1380 | ways to use the function: If @var{in} is passed as @code{NULL} and | 1380 | ways to use the function: If @var{in} is passed as @code{NULL} and |
1381 | @var{inlen} is @code{0}, in-place decryption of the data in @var{out} or | 1381 | @var{inlen} is @code{0}, in-place decryption of the data in @var{out} or |
1382 | length @var{outsize} takes place. With @var{in} being not @code{NULL}, | 1382 | length @var{outsize} takes place. With @var{in} being not @code{NULL}, |
1383 | @var{inlen} bytes are decrypted to the buffer @var{out} which must have | 1383 | @var{inlen} bytes are decrypted to the buffer @var{out} which must have |
1384 | at least a size of @var{inlen}. @var{outlen} must be set to the | 1384 | at least a size of @var{inlen}. @var{outlen} must be set to the |
1385 | allocated size of @var{out}, so that the function can check that there | 1385 | allocated size of @var{out}, so that the function can check that there |
1386 | is sufficient space. Note, that overlapping buffers are not allowed. | 1386 | is sufficient space. Note, that overlapping buffers are not allowed. |
1387 | 1387 | ||
1388 | Depending on the selected algorithms and encryption mode, the length of | 1388 | Depending on the selected algorithms and encryption mode, the length of |
1389 | the buffers must be a multiple of the block size. | 1389 | the buffers must be a multiple of the block size. |
1390 | 1390 | ||
1391 | The function returns @code{0} on success or an error code. | 1391 | The function returns @code{0} on success or an error code. |
1392 | @end deftypefun | 1392 | @end deftypefun |
1393 | 1393 | ||
1394 | 1394 | ||
1395 | OpenPGP (as defined in RFC-2440) requires a special sync operation in | 1395 | OpenPGP (as defined in RFC-2440) requires a special sync operation in |
1396 | some places, the following function is used for this: | 1396 | some places, the following function is used for this: |
1397 | 1397 | ||
1398 | @deftypefun gcry_error_t gcry_cipher_sync (gcry_cipher_hd_t @var{h}) | 1398 | @deftypefun gcry_error_t gcry_cipher_sync (gcry_cipher_hd_t @var{h}) |
1399 | 1399 | ||
1400 | Perform the OpenPGP sync operation on context @var{h}. Note, that this | 1400 | Perform the OpenPGP sync operation on context @var{h}. Note, that this |
1401 | is a no-op unless the context was created with the flag | 1401 | is a no-op unless the context was created with the flag |
1402 | @code{GCRY_CIPHER_ENABLE_SYNC} | 1402 | @code{GCRY_CIPHER_ENABLE_SYNC} |
1403 | @end deftypefun | 1403 | @end deftypefun |
1404 | 1404 | ||
1405 | Some of the described functions are implemented as macros utilizing a | 1405 | Some of the described functions are implemented as macros utilizing a |
1406 | catch-all control function. This control function is rarely used | 1406 | catch-all control function. This control function is rarely used |
1407 | directly but there is nothing which would inhibit it: | 1407 | directly but there is nothing which would inhibit it: |
1408 | 1408 | ||
1409 | @deftypefun gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t @var{h}, int @var{cmd}, void *@var{buffer}, size_t @var{buflen}) | 1409 | @deftypefun gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t @var{h}, int @var{cmd}, void *@var{buffer}, size_t @var{buflen}) |
1410 | 1410 | ||
1411 | @code{gcry_cipher_ctl} controls various aspects of the cipher module and | 1411 | @code{gcry_cipher_ctl} controls various aspects of the cipher module and |
1412 | specific cipher contexts. Usually some more specialized functions or | 1412 | specific cipher contexts. Usually some more specialized functions or |
1413 | macros are used for this purpose. The semantics of the function and its | 1413 | macros are used for this purpose. The semantics of the function and its |
1414 | parameters depends on the the command @var{cmd} and the passed context | 1414 | parameters depends on the the command @var{cmd} and the passed context |
1415 | handle @var{h}. Please see the comments in the source code | 1415 | handle @var{h}. Please see the comments in the source code |
1416 | (@code{src/global.c}) for details. | 1416 | (@code{src/global.c}) for details. |
1417 | @end deftypefun | 1417 | @end deftypefun |
1418 | 1418 | ||
1419 | @deftypefun gcry_error_t gcry_cipher_info (gcry_cipher_hd_t @var{h}, int @var{what}, void *@var{buffer}, size_t *@var{nbytes}) | 1419 | @deftypefun gcry_error_t gcry_cipher_info (gcry_cipher_hd_t @var{h}, int @var{what}, void *@var{buffer}, size_t *@var{nbytes}) |
1420 | 1420 | ||
1421 | @code{gcry_cipher_info} is used to retrieve various | 1421 | @code{gcry_cipher_info} is used to retrieve various |
1422 | information about a cipher context or the cipher module in general. | 1422 | information about a cipher context or the cipher module in general. |
1423 | 1423 | ||
1424 | Currently no information is available. | 1424 | Currently no information is available. |
1425 | @end deftypefun | 1425 | @end deftypefun |
1426 | 1426 | ||
1427 | @node General cipher functions | 1427 | @node General cipher functions |
1428 | @section General cipher functions | 1428 | @section General cipher functions |
1429 | 1429 | ||
1430 | To work with the algorithms, several functions are available to map | 1430 | To work with the algorithms, several functions are available to map |
1431 | algorithm names to the internal identifiers, as well as ways to | 1431 | algorithm names to the internal identifiers, as well as ways to |
1432 | retrieve information about an algorithm or the current cipher context. | 1432 | retrieve information about an algorithm or the current cipher context. |
1433 | 1433 | ||
1434 | @deftypefun gcry_error_t gcry_cipher_algo_info (int @var{algo}, int @var{what}, void *@var{buffer}, size_t *@var{nbytes}) | 1434 | @deftypefun gcry_error_t gcry_cipher_algo_info (int @var{algo}, int @var{what}, void *@var{buffer}, size_t *@var{nbytes}) |
1435 | 1435 | ||
1436 | This function is used to retrieve information on a specific algorithm. | 1436 | This function is used to retrieve information on a specific algorithm. |
1437 | You pass the cipher algorithm ID as @var{algo} and the type of | 1437 | You pass the cipher algorithm ID as @var{algo} and the type of |
1438 | information requested as @var{what}. The result is either returned as | 1438 | information requested as @var{what}. The result is either returned as |
1439 | the return code of the function or copied to the provided @var{buffer} | 1439 | the return code of the function or copied to the provided @var{buffer} |
1440 | whose allocated length must be available in an integer variable with the | 1440 | whose allocated length must be available in an integer variable with the |
1441 | address passed in @var{nbytes}. This variable will also receive the | 1441 | address passed in @var{nbytes}. This variable will also receive the |
1442 | actual used length of the buffer. | 1442 | actual used length of the buffer. |
1443 | 1443 | ||
1444 | Here is a list of supported codes for @var{what}: | 1444 | Here is a list of supported codes for @var{what}: |
1445 | 1445 | ||
1446 | @c begin constants for gcry_cipher_algo_info | 1446 | @c begin constants for gcry_cipher_algo_info |
1447 | @table @code | 1447 | @table @code |
1448 | @item GCRYCTL_GET_KEYLEN: | 1448 | @item GCRYCTL_GET_KEYLEN: |
1449 | Return the length of the key. If the algorithm supports multiple key | 1449 | Return the length of the key. If the algorithm supports multiple key |
1450 | lengths, the maximum supported value is returned. The length is | 1450 | lengths, the maximum supported value is returned. The length is |
1451 | returned as number of octets (bytes) and not as number of bits in | 1451 | returned as number of octets (bytes) and not as number of bits in |
1452 | @var{nbytes}; @var{buffer} must be zero. | 1452 | @var{nbytes}; @var{buffer} must be zero. |
1453 | 1453 | ||
1454 | @item GCRYCTL_GET_BLKLEN: | 1454 | @item GCRYCTL_GET_BLKLEN: |
1455 | Return the block length of the algorithm. The length is returned as a | 1455 | Return the block length of the algorithm. The length is returned as a |
1456 | number of octets in @var{nbytes}; @var{buffer} must be zero. | 1456 | number of octets in @var{nbytes}; @var{buffer} must be zero. |
1457 | 1457 | ||
1458 | @item GCRYCTL_TEST_ALGO: | 1458 | @item GCRYCTL_TEST_ALGO: |
1459 | Returns @code{0} when the specified algorithm is available for use. | 1459 | Returns @code{0} when the specified algorithm is available for use. |
1460 | @var{buffer} and @var{nbytes} must be zero. | 1460 | @var{buffer} and @var{nbytes} must be zero. |
1461 | 1461 | ||
1462 | @end table | 1462 | @end table |
1463 | @c end constants for gcry_cipher_algo_info | 1463 | @c end constants for gcry_cipher_algo_info |
1464 | 1464 | ||
1465 | @end deftypefun | 1465 | @end deftypefun |
1466 | @c end gcry_cipher_algo_info | 1466 | @c end gcry_cipher_algo_info |
1467 | 1467 | ||
1468 | @deftypefun const char *gcry_cipher_algo_name (int @var{algo}) | 1468 | @deftypefun const char *gcry_cipher_algo_name (int @var{algo}) |
1469 | 1469 | ||
1470 | @code{gcry_cipher_algo_name} returns a string with the name of the | 1470 | @code{gcry_cipher_algo_name} returns a string with the name of the |
1471 | cipher algorithm @var{algo}. If the algorithm is not known or another | 1471 | cipher algorithm @var{algo}. If the algorithm is not known or another |
1472 | error occurred, an empty string is returned. This function will never | 1472 | error occurred, an empty string is returned. This function will never |
1473 | return @code{NULL}. | 1473 | return @code{NULL}. |
1474 | @end deftypefun | 1474 | @end deftypefun |
1475 | 1475 | ||
1476 | @deftypefun int gcry_cipher_map_name (const char *@var{name}) | 1476 | @deftypefun int gcry_cipher_map_name (const char *@var{name}) |
1477 | 1477 | ||
1478 | @code{gcry_cipher_map_name} returns the algorithm identifier for the | 1478 | @code{gcry_cipher_map_name} returns the algorithm identifier for the |
1479 | cipher algorithm described by the string @var{name}. If this algorithm | 1479 | cipher algorithm described by the string @var{name}. If this algorithm |
1480 | is not available @code{0} is returned. | 1480 | is not available @code{0} is returned. |
1481 | @end deftypefun | 1481 | @end deftypefun |
1482 | 1482 | ||
1483 | @deftypefun int gcry_cipher_mode_from_oid (const char *@var{string}) | 1483 | @deftypefun int gcry_cipher_mode_from_oid (const char *@var{string}) |
1484 | 1484 | ||
1485 | Return the cipher mode associated with an @acronym{ASN.1} object | 1485 | Return the cipher mode associated with an @acronym{ASN.1} object |
1486 | identifier. The object identifier is expected to be in the | 1486 | identifier. The object identifier is expected to be in the |
1487 | @acronym{IETF}-style dotted decimal notation. The function returns | 1487 | @acronym{IETF}-style dotted decimal notation. The function returns |
1488 | @code{0} for an unknown object identifier or when no mode is associated | 1488 | @code{0} for an unknown object identifier or when no mode is associated |
1489 | with it. | 1489 | with it. |
1490 | @end deftypefun | 1490 | @end deftypefun |
1491 | 1491 | ||
1492 | 1492 | ||
1493 | @c ********************************************************** | 1493 | @c ********************************************************** |
1494 | @c ******************* Hash Functions ********************* | 1494 | @c ******************* Hash Functions ********************* |
1495 | @c ********************************************************** | 1495 | @c ********************************************************** |
1496 | @node Hashing | 1496 | @node Hashing |
1497 | @chapter Hashing | 1497 | @chapter Hashing |
1498 | 1498 | ||
1499 | @acronym{Libgcrypt} provides an easy and consistent to use interface | 1499 | @acronym{Libgcrypt} provides an easy and consistent to use interface |
1500 | for hashing. Hashing is buffered and several hash algorithms can be | 1500 | for hashing. Hashing is buffered and several hash algorithms can be |
1501 | updated at once. It is possible to calculate a MAC using the same | 1501 | updated at once. It is possible to calculate a MAC using the same |
1502 | routines. The programming model follows an open/process/close | 1502 | routines. The programming model follows an open/process/close |
1503 | paradigm and is in that similar to other building blocks provided by | 1503 | paradigm and is in that similar to other building blocks provided by |
1504 | @acronym{Libgcrypt}. | 1504 | @acronym{Libgcrypt}. |
1505 | 1505 | ||
1506 | For convenience reasons, a few cyclic redundancy check value operations | 1506 | For convenience reasons, a few cyclic redundancy check value operations |
1507 | are also supported. | 1507 | are also supported. |
1508 | 1508 | ||
1509 | @menu | 1509 | @menu |
1510 | * Available hash algorithms:: List of hash algorithms supported by the library. | 1510 | * Available hash algorithms:: List of hash algorithms supported by the library. |
1511 | * Hash algorithm modules:: How to work with hash algorithm modules. | 1511 | * Hash algorithm modules:: How to work with hash algorithm modules. |
1512 | * Working with hash algorithms:: List of functions related to hashing. | 1512 | * Working with hash algorithms:: List of functions related to hashing. |
1513 | @end menu | 1513 | @end menu |
1514 | 1514 | ||
1515 | @node Available hash algorithms | 1515 | @node Available hash algorithms |
1516 | @section Available hash algorithms | 1516 | @section Available hash algorithms |
1517 | 1517 | ||
1518 | @c begin table of hash algorithms | 1518 | @c begin table of hash algorithms |
1519 | @table @code | 1519 | @table @code |
1520 | @item GCRY_MD_NONE | 1520 | @item GCRY_MD_NONE |
1521 | This is not a real algorithm but used by some functions as an error | 1521 | This is not a real algorithm but used by some functions as an error |
1522 | return value. This constant is guaranteed to have the value @code{0}. | 1522 | return value. This constant is guaranteed to have the value @code{0}. |
1523 | 1523 | ||
1524 | @item GCRY_MD_SHA1 | 1524 | @item GCRY_MD_SHA1 |
1525 | This is the SHA-1 algorithm which yields a message digest of 20 bytes. | 1525 | This is the SHA-1 algorithm which yields a message digest of 20 bytes. |
1526 | 1526 | ||
1527 | @item GCRY_MD_RMD160 | 1527 | @item GCRY_MD_RMD160 |
1528 | This is the 160 bit version of the RIPE message digest (RIPE-MD-160). | 1528 | This is the 160 bit version of the RIPE message digest (RIPE-MD-160). |
1529 | Like SHA-1 it also yields a digest of 20 bytes. | 1529 | Like SHA-1 it also yields a digest of 20 bytes. |
1530 | 1530 | ||
1531 | @item GCRY_MD_MD5 | 1531 | @item GCRY_MD_MD5 |
1532 | This is the well known MD5 algorithm, which yields a message digest of | 1532 | This is the well known MD5 algorithm, which yields a message digest of |
1533 | 16 bytes. | 1533 | 16 bytes. |
1534 | 1534 | ||
1535 | @item GCRY_MD_MD4 | 1535 | @item GCRY_MD_MD4 |
1536 | This is the MD4 algorithm, which yields a message digest of 16 bytes. | 1536 | This is the MD4 algorithm, which yields a message digest of 16 bytes. |
1537 | 1537 | ||
1538 | @item GCRY_MD_MD2 | 1538 | @item GCRY_MD_MD2 |
1539 | This is an reserved identifier for MD-2; there is no implementation yet. | 1539 | This is an reserved identifier for MD-2; there is no implementation yet. |
1540 | 1540 | ||
1541 | @item GCRY_MD_TIGER | 1541 | @item GCRY_MD_TIGER |
1542 | This is the TIGER/192 algorithm which yields a message digest of 24 bytes. | 1542 | This is the TIGER/192 algorithm which yields a message digest of 24 bytes. |
1543 | 1543 | ||
1544 | @item GCRY_MD_HAVAL | 1544 | @item GCRY_MD_HAVAL |
1545 | This is an reserved for the HAVAL algorithm with 5 passes and 160 | 1545 | This is an reserved for the HAVAL algorithm with 5 passes and 160 |
1546 | bit. It yields a message digest of 20 bytes. Note that there is no | 1546 | bit. It yields a message digest of 20 bytes. Note that there is no |
1547 | implementation yet available. | 1547 | implementation yet available. |
1548 | 1548 | ||
1549 | @item GCRY_MD_SHA256 | 1549 | @item GCRY_MD_SHA256 |
1550 | This is the SHA-256 algorithm which yields a message digest of 32 bytes. | 1550 | This is the SHA-256 algorithm which yields a message digest of 32 bytes. |
1551 | See FIPS 180-2 for the specification. | 1551 | See FIPS 180-2 for the specification. |
1552 | 1552 | ||
1553 | @item GCRY_MD_SHA384 | 1553 | @item GCRY_MD_SHA384 |
1554 | This is reserved for SHA-2 with 384 bits. It yields a message digest of | 1554 | This is reserved for SHA-2 with 384 bits. It yields a message digest of |
1555 | 48 bytes. Note that there is no implementation yet available. | 1555 | 48 bytes. Note that there is no implementation yet available. |
1556 | 1556 | ||
1557 | @item GCRY_MD_SHA512 | 1557 | @item GCRY_MD_SHA512 |
1558 | This is reserved for SHA-2 with 512 bits. It yields a message digest of | 1558 | This is reserved for SHA-2 with 512 bits. It yields a message digest of |
1559 | 64 bytes. Note that there is no implementation yet available. | 1559 | 64 bytes. Note that there is no implementation yet available. |
1560 | 1560 | ||
1561 | @item GCRY_MD_CRC32 | 1561 | @item GCRY_MD_CRC32 |
1562 | This is the ISO 3309 and ITU-T V.42 cyclic redundancy check. It | 1562 | This is the ISO 3309 and ITU-T V.42 cyclic redundancy check. It |
1563 | yields an output of 4 bytes. | 1563 | yields an output of 4 bytes. |
1564 | 1564 | ||
1565 | @item GCRY_MD_CRC32_RFC1510 | 1565 | @item GCRY_MD_CRC32_RFC1510 |
1566 | This is the above cyclic redundancy check function, as modified by RFC | 1566 | This is the above cyclic redundancy check function, as modified by RFC |
1567 | 1510. It yields an output of 4 bytes. | 1567 | 1510. It yields an output of 4 bytes. |
1568 | 1568 | ||
1569 | @item GCRY_MD_CRC24_RFC2440 | 1569 | @item GCRY_MD_CRC24_RFC2440 |
1570 | This is the OpenPGP cyclic redundancy check function. It yields an | 1570 | This is the OpenPGP cyclic redundancy check function. It yields an |
1571 | output of 3 bytes. | 1571 | output of 3 bytes. |
1572 | 1572 | ||
1573 | @end table | 1573 | @end table |
1574 | @c end table of hash algorithms | 1574 | @c end table of hash algorithms |
1575 | 1575 | ||
1576 | @node Hash algorithm modules | 1576 | @node Hash algorithm modules |
1577 | @section Hash algorithm modules | 1577 | @section Hash algorithm modules |
1578 | 1578 | ||
1579 | @acronym{Libgcrypt} makes it possible to load additional `message | 1579 | @acronym{Libgcrypt} makes it possible to load additional `message |
1580 | digest modules'; these cipher can be used just like the message digest | 1580 | digest modules'; these cipher can be used just like the message digest |
1581 | algorithms that are built into the library directly. For an | 1581 | algorithms that are built into the library directly. For an |
1582 | introduction into extension modules, see @xref{Modules}. | 1582 | introduction into extension modules, see @xref{Modules}. |
1583 | 1583 | ||
1584 | @deftp {Data type} gcry_md_spec_t | 1584 | @deftp {Data type} gcry_md_spec_t |
1585 | This is the `module specification structure' needed for registering | 1585 | This is the `module specification structure' needed for registering |
1586 | message digest modules, which has to be filled in by the user before | 1586 | message digest modules, which has to be filled in by the user before |
1587 | it can be used to register a module. It contains the following | 1587 | it can be used to register a module. It contains the following |
1588 | members: | 1588 | members: |
1589 | 1589 | ||
1590 | @table @code | 1590 | @table @code |
1591 | @item const char *name | 1591 | @item const char *name |
1592 | The primary name of this algorithm. | 1592 | The primary name of this algorithm. |
1593 | @item unsigned char *asnoid | 1593 | @item unsigned char *asnoid |
1594 | Array of bytes that form the ASN OID. | 1594 | Array of bytes that form the ASN OID. |
1595 | @item int asnlen | 1595 | @item int asnlen |
1596 | Length of bytes in `asnoid'. | 1596 | Length of bytes in `asnoid'. |
1597 | @item gcry_md_oid_spec_t *oids | 1597 | @item gcry_md_oid_spec_t *oids |
1598 | A list of OIDs that are to be associated with the algorithm. The | 1598 | A list of OIDs that are to be associated with the algorithm. The |
1599 | list's last element must have it's `oid' member set to NULL. See | 1599 | list's last element must have it's `oid' member set to NULL. See |
1600 | below for an explanation of this type. See below for an explanation | 1600 | below for an explanation of this type. See below for an explanation |
1601 | of this type. | 1601 | of this type. |
1602 | @item int mdlen | 1602 | @item int mdlen |
1603 | Length of the message digest algorithm. See below for an explanation | 1603 | Length of the message digest algorithm. See below for an explanation |
1604 | of this type. | 1604 | of this type. |
1605 | @item gcry_md_init_t init | 1605 | @item gcry_md_init_t init |
1606 | The function responsible for initializing a handle. See below for an | 1606 | The function responsible for initializing a handle. See below for an |
1607 | explanation of this type. | 1607 | explanation of this type. |
1608 | @item gcry_md_write_t write | 1608 | @item gcry_md_write_t write |
1609 | The function responsible for writing data into a message digest | 1609 | The function responsible for writing data into a message digest |
1610 | context. See below for an explanation of this type. | 1610 | context. See below for an explanation of this type. |
1611 | @item gcry_md_final_t final | 1611 | @item gcry_md_final_t final |
1612 | The function responsible for `finalizing' a message digest context. | 1612 | The function responsible for `finalizing' a message digest context. |
1613 | See below for an explanation of this type. | 1613 | See below for an explanation of this type. |
1614 | @item gcry_md_read_t read | 1614 | @item gcry_md_read_t read |
1615 | The function responsible for reading out a message digest result. See | 1615 | The function responsible for reading out a message digest result. See |
1616 | below for an explanation of this type. | 1616 | below for an explanation of this type. |
1617 | @item size_t contextsize | 1617 | @item size_t contextsize |
1618 | The size of the algorithm-specific `context', that should be | 1618 | The size of the algorithm-specific `context', that should be |
1619 | allocated for each handle. | 1619 | allocated for each handle. |
1620 | @end table | 1620 | @end table |
1621 | @end deftp | 1621 | @end deftp |
1622 | 1622 | ||
1623 | @deftp {Data type} gcry_md_oid_spec_t | 1623 | @deftp {Data type} gcry_md_oid_spec_t |
1624 | This type is used for associating a user-provided algorithm | 1624 | This type is used for associating a user-provided algorithm |
1625 | implementation with certain OIDs. It contains the following members: | 1625 | implementation with certain OIDs. It contains the following members: |
1626 | 1626 | ||
1627 | @table @code | 1627 | @table @code |
1628 | @item const char *oidstring | 1628 | @item const char *oidstring |
1629 | Textual representation of the OID. | 1629 | Textual representation of the OID. |
1630 | @end table | 1630 | @end table |
1631 | @end deftp | 1631 | @end deftp |
1632 | 1632 | ||
1633 | @deftp {Data type} gcry_md_init_t | 1633 | @deftp {Data type} gcry_md_init_t |
1634 | Type for the `init' function, defined as: void (*gcry_md_init_t) (void | 1634 | Type for the `init' function, defined as: void (*gcry_md_init_t) (void |
1635 | *c) | 1635 | *c) |
1636 | @end deftp | 1636 | @end deftp |
1637 | 1637 | ||
1638 | @deftp {Data type} gcry_md_write_t | 1638 | @deftp {Data type} gcry_md_write_t |
1639 | Type for the `write' function, defined as: void (*gcry_md_write_t) | 1639 | Type for the `write' function, defined as: void (*gcry_md_write_t) |
1640 | (void *c, unsigned char *buf, size_t nbytes) | 1640 | (void *c, unsigned char *buf, size_t nbytes) |
1641 | @end deftp | 1641 | @end deftp |
1642 | 1642 | ||
1643 | @deftp {Data type} gcry_md_final_t | 1643 | @deftp {Data type} gcry_md_final_t |
1644 | Type for the `final' function, defined as: void (*gcry_md_final_t) | 1644 | Type for the `final' function, defined as: void (*gcry_md_final_t) |
1645 | (void *c) | 1645 | (void *c) |
1646 | @end deftp | 1646 | @end deftp |
1647 | 1647 | ||
1648 | @deftp {Data type} gcry_md_read_t | 1648 | @deftp {Data type} gcry_md_read_t |
1649 | Type for the `read' function, defined as: unsigned char | 1649 | Type for the `read' function, defined as: unsigned char |
1650 | *(*gcry_md_read_t) (void *c) | 1650 | *(*gcry_md_read_t) (void *c) |
1651 | @end deftp | 1651 | @end deftp |
1652 | 1652 | ||
1653 | @deftypefun gcry_error_t gcry_md_register (gcry_md_spec_t *@var{digest}, unsigned int *algorithm_id, gcry_module_t *@var{module}) | 1653 | @deftypefun gcry_error_t gcry_md_register (gcry_md_spec_t *@var{digest}, unsigned int *algorithm_id, gcry_module_t *@var{module}) |
1654 | 1654 | ||
1655 | Register a new digest module whose specification can be found in | 1655 | Register a new digest module whose specification can be found in |
1656 | @var{digest}. On success, a new algorithm ID is stored in | 1656 | @var{digest}. On success, a new algorithm ID is stored in |
1657 | @var{algorithm_id} and a pointer representing this module is stored | 1657 | @var{algorithm_id} and a pointer representing this module is stored |
1658 | in @var{module}. | 1658 | in @var{module}. |
1659 | @end deftypefun | 1659 | @end deftypefun |
1660 | 1660 | ||
1661 | @deftypefun void gcry_md_unregister (gcry_module_t @var{module}) | 1661 | @deftypefun void gcry_md_unregister (gcry_module_t @var{module}) |
1662 | Unregister the digest identified by @var{module}, which must have been | 1662 | Unregister the digest identified by @var{module}, which must have been |
1663 | registered with gcry_md_register. | 1663 | registered with gcry_md_register. |
1664 | @end deftypefun | 1664 | @end deftypefun |
1665 | 1665 | ||
1666 | @deftypefun gcry_error_t gcry_md_list (int *@var{list}, int *@var{list_length}) | 1666 | @deftypefun gcry_error_t gcry_md_list (int *@var{list}, int *@var{list_length}) |
1667 | Get a list consisting of the IDs of the loaded message digest modules. | 1667 | Get a list consisting of the IDs of the loaded message digest modules. |
1668 | If @var{list} is zero, write the number of loaded message digest | 1668 | If @var{list} is zero, write the number of loaded message digest |
1669 | modules to @var{list_length} and return. If @var{list} is non-zero, | 1669 | modules to @var{list_length} and return. If @var{list} is non-zero, |
1670 | the first *@var{list_length} algorithm IDs are stored in @var{list}, | 1670 | the first *@var{list_length} algorithm IDs are stored in @var{list}, |
1671 | which must be of according size. In case there are less message | 1671 | which must be of according size. In case there are less message |
1672 | digests modules than *@var{list_length}, *@var{list_length} is updated | 1672 | digests modules than *@var{list_length}, *@var{list_length} is updated |
1673 | to the correct number. | 1673 | to the correct number. |
1674 | @end deftypefun | 1674 | @end deftypefun |
1675 | 1675 | ||
1676 | @node Working with hash algorithms | 1676 | @node Working with hash algorithms |
1677 | @section Working with hash algorithms | 1677 | @section Working with hash algorithms |
1678 | 1678 | ||
1679 | To use most of these function it is necessary to create a context; | 1679 | To use most of these function it is necessary to create a context; |
1680 | this is done using: | 1680 | this is done using: |
1681 | 1681 | ||
1682 | @deftypefun gcry_error_t gcry_md_open (gcry_md_hd_t *@var{hd}, int @var{algo}, unsigned int @var{flags}) | 1682 | @deftypefun gcry_error_t gcry_md_open (gcry_md_hd_t *@var{hd}, int @var{algo}, unsigned int @var{flags}) |
1683 | 1683 | ||
1684 | Create a message digest object for algorithm @var{algo}. @var{flags} | 1684 | Create a message digest object for algorithm @var{algo}. @var{flags} |
1685 | may be given as an bitwise OR of constants described below. @var{algo} | 1685 | may be given as an bitwise OR of constants described below. @var{algo} |
1686 | may be given as @code{0} if the algorithms to use are later set using | 1686 | may be given as @code{0} if the algorithms to use are later set using |
1687 | @code{gcry_md_enable}. @var{hd} is guaranteed to either receive a valid | 1687 | @code{gcry_md_enable}. @var{hd} is guaranteed to either receive a valid |
1688 | handle or NULL. | 1688 | handle or NULL. |
1689 | 1689 | ||
1690 | For a list of supported algorithms, see @xref{Available hash | 1690 | For a list of supported algorithms, see @xref{Available hash |
1691 | algorithms}. | 1691 | algorithms}. |
1692 | 1692 | ||
1693 | The flags allowed for @var{mode} are: | 1693 | The flags allowed for @var{mode} are: |
1694 | 1694 | ||
1695 | @c begin table of hash flags | 1695 | @c begin table of hash flags |
1696 | @table @code | 1696 | @table @code |
1697 | @item GCRY_MD_FLAG_SECURE | 1697 | @item GCRY_MD_FLAG_SECURE |
1698 | Allocate all buffers and the resulting digest in "secure memory". Use | 1698 | Allocate all buffers and the resulting digest in "secure memory". Use |
1699 | this is the hashed data is highly confidential. | 1699 | this is the hashed data is highly confidential. |
1700 | 1700 | ||
1701 | @item GCRY_MD_FLAG_HMAC | 1701 | @item GCRY_MD_FLAG_HMAC |
1702 | Turn the algorithm into a HMAC message authentication algorithm. This | 1702 | Turn the algorithm into a HMAC message authentication algorithm. This |
1703 | does only work if just one algorithm is enabled for the handle and | 1703 | does only work if just one algorithm is enabled for the handle and |
1704 | SHA-384 and SHA512 is not used. Note that the function | 1704 | SHA-384 and SHA512 is not used. Note that the function |
1705 | @code{gcry_md_setkey} must be used set the MAC key. If you want CBC | 1705 | @code{gcry_md_setkey} must be used set the MAC key. If you want CBC |
1706 | message authentication codes based on a cipher, see @xref{Working with | 1706 | message authentication codes based on a cipher, see @xref{Working with |
1707 | cipher handles}. | 1707 | cipher handles}. |
1708 | 1708 | ||
1709 | @end table | 1709 | @end table |
1710 | @c begin table of hash flags | 1710 | @c begin table of hash flags |
1711 | 1711 | ||
1712 | You may use the function @code{gcry_md_is_enabled} to later check | 1712 | You may use the function @code{gcry_md_is_enabled} to later check |
1713 | whether an algorithm has been enabled. | 1713 | whether an algorithm has been enabled. |
1714 | 1714 | ||
1715 | @end deftypefun | 1715 | @end deftypefun |
1716 | @c end function gcry_md_open | 1716 | @c end function gcry_md_open |
1717 | 1717 | ||
1718 | If you want to calculate several hash algorithms at the same time, you | 1718 | If you want to calculate several hash algorithms at the same time, you |
1719 | have to use the following function right after the @code{gcry_md_open}: | 1719 | have to use the following function right after the @code{gcry_md_open}: |
1720 | 1720 | ||
1721 | @deftypefun gcry_error_t gcry_md_enable (gcry_md_hd_t @var{h}, int @var{algo}) | 1721 | @deftypefun gcry_error_t gcry_md_enable (gcry_md_hd_t @var{h}, int @var{algo}) |
1722 | 1722 | ||
1723 | Add the message digest algorithm @var{algo} to the digest object | 1723 | Add the message digest algorithm @var{algo} to the digest object |
1724 | described by handle @var{h}. Duplicated enabling of algorithms is | 1724 | described by handle @var{h}. Duplicated enabling of algorithms is |
1725 | detected and ignored. | 1725 | detected and ignored. |
1726 | @end deftypefun | 1726 | @end deftypefun |
1727 | 1727 | ||
1728 | If the flag @code{GCRY_MD_FLAG_HMAC} was used, the key for the MAC must | 1728 | If the flag @code{GCRY_MD_FLAG_HMAC} was used, the key for the MAC must |
1729 | be set using the function: | 1729 | be set using the function: |
1730 | 1730 | ||
1731 | @deftypefun gcry_error_t gcry_md_setkey (gcry_md_hd_t @var{h}, const void *@var{key}, size_t @var{keylen}) | 1731 | @deftypefun gcry_error_t gcry_md_setkey (gcry_md_hd_t @var{h}, const void *@var{key}, size_t @var{keylen}) |
1732 | 1732 | ||
1733 | For use with the HMAC feature, set the MAC key to the value of @var{key} | 1733 | For use with the HMAC feature, set the MAC key to the value of @var{key} |
1734 | of length @var{keylen}. | 1734 | of length @var{keylen}. |
1735 | @end deftypefun | 1735 | @end deftypefun |
1736 | 1736 | ||
1737 | 1737 | ||
1738 | After you are done with the hash calculation, you should release the | 1738 | After you are done with the hash calculation, you should release the |
1739 | resources by using: | 1739 | resources by using: |
1740 | 1740 | ||
1741 | @deftypefun void gcry_md_close (gcry_md_hd_t @var{h}) | 1741 | @deftypefun void gcry_md_close (gcry_md_hd_t @var{h}) |
1742 | 1742 | ||
1743 | Release all resources of hash context @var{h}. @var{h} should not be | 1743 | Release all resources of hash context @var{h}. @var{h} should not be |
1744 | used after a call to this function. A @code{NULL} passed as @var{h} is | 1744 | used after a call to this function. A @code{NULL} passed as @var{h} is |
1745 | ignored. | 1745 | ignored. |
1746 | 1746 | ||
1747 | @end deftypefun | 1747 | @end deftypefun |
1748 | 1748 | ||
1749 | Often you have to do several hash operations using the same algorithm. | 1749 | Often you have to do several hash operations using the same algorithm. |
1750 | To avoid the overhead of creating and releasing context, a reset function | 1750 | To avoid the overhead of creating and releasing context, a reset function |
1751 | is provided: | 1751 | is provided: |
1752 | 1752 | ||
1753 | @deftypefun void gcry_md_reset (gcry_md_hd_t @var{h}) | 1753 | @deftypefun void gcry_md_reset (gcry_md_hd_t @var{h}) |
1754 | 1754 | ||
1755 | Reset the current context to its initial state. This is effectively | 1755 | Reset the current context to its initial state. This is effectively |
1756 | identical to a close followed by an open and enabling all currently | 1756 | identical to a close followed by an open and enabling all currently |
1757 | active algorithms. | 1757 | active algorithms. |
1758 | @end deftypefun | 1758 | @end deftypefun |
1759 | 1759 | ||
1760 | 1760 | ||
1761 | Often it is necessary to start hashing some data and than continue to | 1761 | Often it is necessary to start hashing some data and than continue to |
1762 | hash different data. To avoid hashing the same data several times (which | 1762 | hash different data. To avoid hashing the same data several times (which |
1763 | might not even be possible if the data is received from a pipe), a | 1763 | might not even be possible if the data is received from a pipe), a |
1764 | snapshot of the current hash context can be taken and turned into a new | 1764 | snapshot of the current hash context can be taken and turned into a new |
1765 | context: | 1765 | context: |
1766 | 1766 | ||
1767 | @deftypefun gcry_error_t gcry_md_copy (gcry_md_hd_t *@var{handle_dst}, gcry_md_hd_t @var{handle_src}) | 1767 | @deftypefun gcry_error_t gcry_md_copy (gcry_md_hd_t *@var{handle_dst}, gcry_md_hd_t @var{handle_src}) |
1768 | 1768 | ||
1769 | Create a new digest object as an exact copy of the object described by | 1769 | Create a new digest object as an exact copy of the object described by |
1770 | handle @var{handle_src} and store it in @var{handle_dst}. The context | 1770 | handle @var{handle_src} and store it in @var{handle_dst}. The context |
1771 | is not reset and you can continue to hash data using this context and | 1771 | is not reset and you can continue to hash data using this context and |
1772 | independently using the original context. | 1772 | independently using the original context. |
1773 | @end deftypefun | 1773 | @end deftypefun |
1774 | 1774 | ||
1775 | 1775 | ||
1776 | Now that we have prepared everything to calculate hashes, its time to | 1776 | Now that we have prepared everything to calculate hashes, its time to |
1777 | see how it is actually done. There are 2 ways for this, one to | 1777 | see how it is actually done. There are 2 ways for this, one to |
1778 | update the hash with a block of memory and one macro to update the hash | 1778 | update the hash with a block of memory and one macro to update the hash |
1779 | by just one character. Both may be used intermixed. | 1779 | by just one character. Both may be used intermixed. |
1780 | 1780 | ||
1781 | @deftypefun void gcry_md_write (gcry_md_hd_t @var{h}, const void *@var{buffer}, size_t @var{length}) | 1781 | @deftypefun void gcry_md_write (gcry_md_hd_t @var{h}, const void *@var{buffer}, size_t @var{length}) |
1782 | 1782 | ||
1783 | Pass @var{length} bytes of the data in @var{buffer} to the digest object | 1783 | Pass @var{length} bytes of the data in @var{buffer} to the digest object |
1784 | with handle @var{h} to update the digest values. This | 1784 | with handle @var{h} to update the digest values. This |
1785 | function should be used for large blocks of data. | 1785 | function should be used for large blocks of data. |
1786 | @end deftypefun | 1786 | @end deftypefun |
1787 | 1787 | ||
1788 | @deftypefun void gcry_md_putc (gcry_md_hd_t @var{h}, int @var{c}) | 1788 | @deftypefun void gcry_md_putc (gcry_md_hd_t @var{h}, int @var{c}) |
1789 | 1789 | ||
1790 | Pass the byte in @var{c} to the digest object with handle @var{h} to | 1790 | Pass the byte in @var{c} to the digest object with handle @var{h} to |
1791 | update the digest value. This is an efficient function, implemented as | 1791 | update the digest value. This is an efficient function, implemented as |
1792 | a macro to buffer the data before an actual update. | 1792 | a macro to buffer the data before an actual update. |
1793 | @end deftypefun | 1793 | @end deftypefun |
1794 | 1794 | ||
1795 | The semantics of the hash functions don't allow to read out intermediate | 1795 | The semantics of the hash functions don't allow to read out intermediate |
1796 | message digests because the calculation must be finalized fist. This | 1796 | message digests because the calculation must be finalized fist. This |
1797 | finalization may for example include the number of bytes hashed in the | 1797 | finalization may for example include the number of bytes hashed in the |
1798 | message digest. | 1798 | message digest. |
1799 | 1799 | ||
1800 | @deftypefun void gcry_md_final (gcry_md_hd_t @var{h}) | 1800 | @deftypefun void gcry_md_final (gcry_md_hd_t @var{h}) |
1801 | 1801 | ||
1802 | Finalize the message digest calculation. This is not really needed | 1802 | Finalize the message digest calculation. This is not really needed |
1803 | because @code{gcry_md_read} does this implicitly. After this has been | 1803 | because @code{gcry_md_read} does this implicitly. After this has been |
1804 | done no further updates (by means of @code{gcry_md_write} or | 1804 | done no further updates (by means of @code{gcry_md_write} or |
1805 | @code{gcry_md_putc} are allowed. Only the first call to this function | 1805 | @code{gcry_md_putc} are allowed. Only the first call to this function |
1806 | has an effect. It is implemented as a macro. | 1806 | has an effect. It is implemented as a macro. |
1807 | @end deftypefun | 1807 | @end deftypefun |
1808 | 1808 | ||
1809 | The way to read out the calculated message digest is by using the | 1809 | The way to read out the calculated message digest is by using the |
1810 | function: | 1810 | function: |
1811 | 1811 | ||
1812 | @deftypefun unsigned char *gcry_md_read (gcry_md_hd_t @var{h}, int @var{algo}) | 1812 | @deftypefun unsigned char *gcry_md_read (gcry_md_hd_t @var{h}, int @var{algo}) |
1813 | 1813 | ||
1814 | @code{gcry_md_read} returns the message digest after finalizing the | 1814 | @code{gcry_md_read} returns the message digest after finalizing the |
1815 | calculation. This function may be used as often as required but it will | 1815 | calculation. This function may be used as often as required but it will |
1816 | always return the same value for one handle. The returned message digest | 1816 | always return the same value for one handle. The returned message digest |
1817 | is allocated within the message context and therefore valid until the | 1817 | is allocated within the message context and therefore valid until the |
1818 | handle is released or reseted (using @code{gcry_md_close} or | 1818 | handle is released or reseted (using @code{gcry_md_close} or |
1819 | @code{gcry_md_reset}. @var{algo} may be given as 0 to return the only | 1819 | @code{gcry_md_reset}. @var{algo} may be given as 0 to return the only |
1820 | enabled message digest or it may specify one of the enabled algorithms. | 1820 | enabled message digest or it may specify one of the enabled algorithms. |
1821 | The function does return @code{NULL} if the requested algorithm has not | 1821 | The function does return @code{NULL} if the requested algorithm has not |
1822 | been enabled. | 1822 | been enabled. |
1823 | @end deftypefun | 1823 | @end deftypefun |
1824 | 1824 | ||
1825 | Because it is often necessary to get the message digest of one block of | 1825 | Because it is often necessary to get the message digest of one block of |
1826 | memory, a fast convenience function is available for this task: | 1826 | memory, a fast convenience function is available for this task: |
1827 | 1827 | ||
1828 | @deftypefun void gcry_md_hash_buffer (int @var{algo}, void *@var{digest}, const cvoid *@var{buffer}, size_t @var{length}); | 1828 | @deftypefun void gcry_md_hash_buffer (int @var{algo}, void *@var{digest}, const cvoid *@var{buffer}, size_t @var{length}); |
1829 | 1829 | ||
1830 | @code{gcry_md_hash_buffer} is a shortcut function to calculate a message | 1830 | @code{gcry_md_hash_buffer} is a shortcut function to calculate a message |
1831 | digest of a buffer. This function does not require a context and | 1831 | digest of a buffer. This function does not require a context and |
1832 | immediately returns the message digest of the @var{length} bytes at | 1832 | immediately returns the message digest of the @var{length} bytes at |
1833 | @var{buffer}. @var{digest} must be allocated by the caller, large | 1833 | @var{buffer}. @var{digest} must be allocated by the caller, large |
1834 | enough to hold the message digest yielded by the the specified algorithm | 1834 | enough to hold the message digest yielded by the the specified algorithm |
1835 | @var{algo}. This required size may be obtained by using the function | 1835 | @var{algo}. This required size may be obtained by using the function |
1836 | @code{gcry_md_get_algo_dlen}. | 1836 | @code{gcry_md_get_algo_dlen}. |
1837 | 1837 | ||
1838 | Note, that this function will abort the process if an unavailable | 1838 | Note, that this function will abort the process if an unavailable |
1839 | algorithm is used. | 1839 | algorithm is used. |
1840 | @end deftypefun | 1840 | @end deftypefun |
1841 | 1841 | ||
1842 | @c *********************************** | 1842 | @c *********************************** |
1843 | @c ***** MD info functions *********** | 1843 | @c ***** MD info functions *********** |
1844 | @c *********************************** | 1844 | @c *********************************** |
1845 | 1845 | ||
1846 | Hash algorithms are identified by internal algorithm numbers (see | 1846 | Hash algorithms are identified by internal algorithm numbers (see |
1847 | @code{gcry_md_open} for a list. However, in most applications they are | 1847 | @code{gcry_md_open} for a list. However, in most applications they are |
1848 | used by names, so 2 functions are available to map between string | 1848 | used by names, so 2 functions are available to map between string |
1849 | representations and hash algorithm identifiers. | 1849 | representations and hash algorithm identifiers. |
1850 | 1850 | ||
1851 | @deftypefun const char *gcry_md_algo_name (int @var{algo}) | 1851 | @deftypefun const char *gcry_md_algo_name (int @var{algo}) |
1852 | 1852 | ||
1853 | Map the digest algorithm id @var{algo} to a string representation of the | 1853 | Map the digest algorithm id @var{algo} to a string representation of the |
1854 | algorithm name. For unknown algorithms this functions returns an | 1854 | algorithm name. For unknown algorithms this functions returns an |
1855 | empty string. This function should not be used to test for the | 1855 | empty string. This function should not be used to test for the |
1856 | availability of an algorithm. | 1856 | availability of an algorithm. |
1857 | @end deftypefun | 1857 | @end deftypefun |
1858 | 1858 | ||
1859 | @deftypefun int gcry_md_map_name (const char *@var{name}) | 1859 | @deftypefun int gcry_md_map_name (const char *@var{name}) |
1860 | 1860 | ||
1861 | Map the algorithm with @var{name} to a digest algorithm identifier. | 1861 | Map the algorithm with @var{name} to a digest algorithm identifier. |
1862 | Returns 0 if the algorithm name is not known. Names representing | 1862 | Returns 0 if the algorithm name is not known. Names representing |
1863 | @acronym{ASN.1} object identifiers are recognized if the @acronym{IETF} | 1863 | @acronym{ASN.1} object identifiers are recognized if the @acronym{IETF} |
1864 | dotted format is used and the OID is prefixed with either "@code{oid.}" | 1864 | dotted format is used and the OID is prefixed with either "@code{oid.}" |
1865 | or "@code{OID.}". For a list of supported OIDs, see the source code at | 1865 | or "@code{OID.}". For a list of supported OIDs, see the source code at |
1866 | @file{cipher/md.c}. This function should not be used to test for the | 1866 | @file{cipher/md.c}. This function should not be used to test for the |
1867 | availability of an algorithm. | 1867 | availability of an algorithm. |
1868 | @end deftypefun | 1868 | @end deftypefun |
1869 | 1869 | ||
1870 | @deftypefun gcry_error_t gcry_md_get_asnoid (int @var{algo}, void *@var{buffer}, size_t *@var{length}) | 1870 | @deftypefun gcry_error_t gcry_md_get_asnoid (int @var{algo}, void *@var{buffer}, size_t *@var{length}) |
1871 | 1871 | ||
1872 | Return an DER encoded ASN.1 OID for the algorithm @var{algo} in the | 1872 | Return an DER encoded ASN.1 OID for the algorithm @var{algo} in the |
1873 | user allocated @var{buffer}. @var{length} must point to variable with | 1873 | user allocated @var{buffer}. @var{length} must point to variable with |
1874 | the available size of @var{buffer} and receives after return the | 1874 | the available size of @var{buffer} and receives after return the |
1875 | actual size of the returned OID. The returned error code may be | 1875 | actual size of the returned OID. The returned error code may be |
1876 | @code{GPG_ERR_TOO_SHORT} if the provided buffer is to short to receive | 1876 | @code{GPG_ERR_TOO_SHORT} if the provided buffer is to short to receive |
1877 | the OID; it is possible to call the function with @code{NULL} for | 1877 | the OID; it is possible to call the function with @code{NULL} for |
1878 | @var{buffer} to have it only return the required size. The function | 1878 | @var{buffer} to have it only return the required size. The function |
1879 | returns 0 on success. | 1879 | returns 0 on success. |
1880 | 1880 | ||
1881 | @end deftypefun | 1881 | @end deftypefun |
1882 | 1882 | ||
1883 | 1883 | ||
1884 | To test whether an algorithm is actually available for use, the | 1884 | To test whether an algorithm is actually available for use, the |
1885 | following macro should be used: | 1885 | following macro should be used: |
1886 | 1886 | ||
1887 | @deftypefun gcry_error_t gcry_md_test_algo (int @var{algo}) | 1887 | @deftypefun gcry_error_t gcry_md_test_algo (int @var{algo}) |
1888 | 1888 | ||
1889 | The macro returns 0 if the algorithm @var{algo} is available for use. | 1889 | The macro returns 0 if the algorithm @var{algo} is available for use. |
1890 | @end deftypefun | 1890 | @end deftypefun |
1891 | 1891 | ||
1892 | If the length of a message digest is not known, it can be retrieved | 1892 | If the length of a message digest is not known, it can be retrieved |
1893 | using the following function: | 1893 | using the following function: |
1894 | 1894 | ||
1895 | @deftypefun unsigned int gcry_md_get_algo_dlen (int @var{algo}) | 1895 | @deftypefun unsigned int gcry_md_get_algo_dlen (int @var{algo}) |
1896 | 1896 | ||
1897 | Retrieve the length in bytes of the digest yielded by algorithm | 1897 | Retrieve the length in bytes of the digest yielded by algorithm |
1898 | @var{algo}. This is often used prior to @code{gcry_md_read} to allocate | 1898 | @var{algo}. This is often used prior to @code{gcry_md_read} to allocate |
1899 | sufficient memory for the digest. | 1899 | sufficient memory for the digest. |
1900 | @end deftypefun | 1900 | @end deftypefun |
1901 | 1901 | ||
1902 | 1902 | ||
1903 | In some situations it might be hard to remember the algorithm used for | 1903 | In some situations it might be hard to remember the algorithm used for |
1904 | the ongoing hashing. The following function might be used to get that | 1904 | the ongoing hashing. The following function might be used to get that |
1905 | information: | 1905 | information: |
1906 | 1906 | ||
1907 | @deftypefun int gcry_md_get_algo (gcry_md_hd_t @var{h}) | 1907 | @deftypefun int gcry_md_get_algo (gcry_md_hd_t @var{h}) |
1908 | 1908 | ||
1909 | Retrieve the algorithm used with the handle @var{h}. Note, that this | 1909 | Retrieve the algorithm used with the handle @var{h}. Note, that this |
1910 | does not work reliable if more than one algorithm is enabled in @var{h}. | 1910 | does not work reliable if more than one algorithm is enabled in @var{h}. |
1911 | @end deftypefun | 1911 | @end deftypefun |
1912 | 1912 | ||
1913 | The following macro might also be useful: | 1913 | The following macro might also be useful: |
1914 | 1914 | ||
1915 | @deftypefun int gcry_md_is_secure (gcry_md_hd_t @var{h}) | 1915 | @deftypefun int gcry_md_is_secure (gcry_md_hd_t @var{h}) |
1916 | 1916 | ||
1917 | This function returns true when the digest object @var{h} is allocated | 1917 | This function returns true when the digest object @var{h} is allocated |
1918 | in "secure memory"; i.e. @var{h} was created with the | 1918 | in "secure memory"; i.e. @var{h} was created with the |
1919 | @code{GCRY_MD_FLAG_SECURE}. | 1919 | @code{GCRY_MD_FLAG_SECURE}. |
1920 | @end deftypefun | 1920 | @end deftypefun |
1921 | 1921 | ||
1922 | @deftypefun int gcry_md_is_enabled (gcry_md_hd_t @var{h}, int @var{algo}) | 1922 | @deftypefun int gcry_md_is_enabled (gcry_md_hd_t @var{h}, int @var{algo}) |
1923 | 1923 | ||
1924 | This function returns true when the algorithm @var{algo} has been | 1924 | This function returns true when the algorithm @var{algo} has been |
1925 | enabled for the digest object @var{h}. | 1925 | enabled for the digest object @var{h}. |
1926 | @end deftypefun | 1926 | @end deftypefun |
1927 | 1927 | ||
1928 | 1928 | ||
1929 | 1929 | ||
1930 | Tracking bugs related to hashing is often a cumbersome task which | 1930 | Tracking bugs related to hashing is often a cumbersome task which |
1931 | requires to add a lot of printf statements into the code. @acronym{Libgcrypt} | 1931 | requires to add a lot of printf statements into the code. @acronym{Libgcrypt} |
1932 | provides an easy way to avoid this. The actual data hashed can be | 1932 | provides an easy way to avoid this. The actual data hashed can be |
1933 | written to files on request. The following 2 macros should be used to | 1933 | written to files on request. The following 2 macros should be used to |
1934 | implement such a debugging facility: | 1934 | implement such a debugging facility: |
1935 | 1935 | ||
1936 | @deftypefun void gcry_md_start_debug (gcry_md_hd_t @var{h}, const char *@var{suffix}) | 1936 | @deftypefun void gcry_md_start_debug (gcry_md_hd_t @var{h}, const char *@var{suffix}) |
1937 | 1937 | ||
1938 | Enable debugging for the digest object with handle @var{h}. This | 1938 | Enable debugging for the digest object with handle @var{h}. This |
1939 | creates create files named @file{dbgmd-<n>.<string>} while doing the | 1939 | creates create files named @file{dbgmd-<n>.<string>} while doing the |
1940 | actual hashing. @var{suffix} is the string part in the filename. The | 1940 | actual hashing. @var{suffix} is the string part in the filename. The |
1941 | number is a counter incremented for each new hashing. The data in the | 1941 | number is a counter incremented for each new hashing. The data in the |
1942 | file is the raw data as passed to @code{gcry_md_write} or | 1942 | file is the raw data as passed to @code{gcry_md_write} or |
1943 | @code{gcry_md_putc}. | 1943 | @code{gcry_md_putc}. |
1944 | @end deftypefun | 1944 | @end deftypefun |
1945 | 1945 | ||
1946 | 1946 | ||
1947 | @deftypefun void gcry_md_stop_debug (gcry_md_hd_t @var{h}, int @var{reserved}) | 1947 | @deftypefun void gcry_md_stop_debug (gcry_md_hd_t @var{h}, int @var{reserved}) |
1948 | 1948 | ||
1949 | Stop debugging on handle @var{h}. @var{reserved} should be specified as | 1949 | Stop debugging on handle @var{h}. @var{reserved} should be specified as |
1950 | 0. This function is usually not required because @code{gcry_md_close} | 1950 | 0. This function is usually not required because @code{gcry_md_close} |
1951 | does implicitly stop debugging. | 1951 | does implicitly stop debugging. |
1952 | @end deftypefun | 1952 | @end deftypefun |
1953 | 1953 | ||
1954 | 1954 | ||
1955 | @c ********************************************************** | 1955 | @c ********************************************************** |
1956 | @c ******************* Public Key ************************* | 1956 | @c ******************* Public Key ************************* |
1957 | @c ********************************************************** | 1957 | @c ********************************************************** |
1958 | @node Public Key cryptography (I) | 1958 | @node Public Key cryptography (I) |
1959 | @chapter Public Key cryptography (I) | 1959 | @chapter Public Key cryptography (I) |
1960 | 1960 | ||
1961 | Public key cryptography, also known as asymmetric cryptography, is an | 1961 | Public key cryptography, also known as asymmetric cryptography, is an |
1962 | easy way for key management and to provide digital signatures. | 1962 | easy way for key management and to provide digital signatures. |
1963 | @acronym{Libgcrypt} provides two completely different interfaces to | 1963 | @acronym{Libgcrypt} provides two completely different interfaces to |
1964 | public key cryptography, this chapter explains the one based on | 1964 | public key cryptography, this chapter explains the one based on |
1965 | S-expressions. | 1965 | S-expressions. |
1966 | 1966 | ||
1967 | @menu | 1967 | @menu |
1968 | * Available algorithms:: Algorithms supported by the library. | 1968 | * Available algorithms:: Algorithms supported by the library. |
1969 | * Used S-expressions:: Introduction into the used S-expression. | 1969 | * Used S-expressions:: Introduction into the used S-expression. |
1970 | * Public key modules:: How to work with public key modules. | 1970 | * Public key modules:: How to work with public key modules. |
1971 | * Cryptographic Functions:: Functions for performing the cryptographic actions. | 1971 | * Cryptographic Functions:: Functions for performing the cryptographic actions. |
1972 | * General public-key related Functions:: General functions, not implementing any cryptography. | 1972 | * General public-key related Functions:: General functions, not implementing any cryptography. |
1973 | @end menu | 1973 | @end menu |
1974 | 1974 | ||
1975 | @node Available algorithms | 1975 | @node Available algorithms |
1976 | @section Available algorithms | 1976 | @section Available algorithms |
1977 | 1977 | ||
1978 | @acronym{Libgcrypt} supports the RSA (Rivest-Shamir-Adleman) algorithms as well | 1978 | @acronym{Libgcrypt} supports the RSA (Rivest-Shamir-Adleman) algorithms as well |
1979 | as DSA (Digital Signature Algorithm) and ElGamal. The versatile | 1979 | as DSA (Digital Signature Algorithm) and ElGamal. The versatile |
1980 | interface allows to add more algorithms in the future. | 1980 | interface allows to add more algorithms in the future. |
1981 | 1981 | ||
1982 | @node Used S-expressions | 1982 | @node Used S-expressions |
1983 | @section Used S-expressions | 1983 | @section Used S-expressions |
1984 | 1984 | ||
1985 | @acronym{Libgcrypt}'s API for asymmetric cryptography is based on data | 1985 | @acronym{Libgcrypt}'s API for asymmetric cryptography is based on data |
1986 | structures called S-expressions (see XXXX) and does not work with | 1986 | structures called S-expressions (see XXXX) and does not work with |
1987 | contexts as most of the other building blocks of @acronym{Libgcrypt} | 1987 | contexts as most of the other building blocks of @acronym{Libgcrypt} |
1988 | do. | 1988 | do. |
1989 | 1989 | ||
1990 | The following information are stored in S-expressions: | 1990 | The following information are stored in S-expressions: |
1991 | 1991 | ||
1992 | @table @asis | 1992 | @table @asis |
1993 | @item keys | 1993 | @item keys |
1994 | 1994 | ||
1995 | @item plain text data | 1995 | @item plain text data |
1996 | 1996 | ||
1997 | @item encrypted data | 1997 | @item encrypted data |
1998 | 1998 | ||
1999 | @item signatures | 1999 | @item signatures |
2000 | 2000 | ||
2001 | @end table | 2001 | @end table |
2002 | 2002 | ||
2003 | @noindent | 2003 | @noindent |
2004 | To describe how @acronym{Libgcrypt} expect keys, we use some examples. Note that | 2004 | To describe how @acronym{Libgcrypt} expect keys, we use some examples. Note that |
2005 | words in | 2005 | words in |
2006 | @ifnottex | 2006 | @ifnottex |
2007 | uppercase | 2007 | uppercase |
2008 | @end ifnottex | 2008 | @end ifnottex |
2009 | @iftex | 2009 | @iftex |
2010 | italics | 2010 | italics |
2011 | @end iftex | 2011 | @end iftex |
2012 | indicate parameters whereas lowercase words are literals. | 2012 | indicate parameters whereas lowercase words are literals. |
2013 | 2013 | ||
2014 | @example | 2014 | @example |
2015 | (private-key | 2015 | (private-key |
2016 | (dsa | 2016 | (dsa |
2017 | (p @var{p-mpi}) | 2017 | (p @var{p-mpi}) |
2018 | (q @var{q-mpi}) | 2018 | (q @var{q-mpi}) |
2019 | (g @var{g-mpi}) | 2019 | (g @var{g-mpi}) |
2020 | (y @var{y-mpi}) | 2020 | (y @var{y-mpi}) |
2021 | (x @var{x-mpi}))) | 2021 | (x @var{x-mpi}))) |
2022 | @end example | 2022 | @end example |
2023 | 2023 | ||
2024 | @noindent | 2024 | @noindent |
2025 | This specifies a DSA private key with the following parameters: | 2025 | This specifies a DSA private key with the following parameters: |
2026 | 2026 | ||
2027 | @table @var | 2027 | @table @var |
2028 | @item p-mpi | 2028 | @item p-mpi |
2029 | DSA prime @math{p}. | 2029 | DSA prime @math{p}. |
2030 | @item q-mpi | 2030 | @item q-mpi |
2031 | DSA group order @math{q} (which is a prime divisor of @math{p-1}). | 2031 | DSA group order @math{q} (which is a prime divisor of @math{p-1}). |
2032 | @item g-mpi | 2032 | @item g-mpi |
2033 | DSA group generator @math{g}. | 2033 | DSA group generator @math{g}. |
2034 | @item y-mpi | 2034 | @item y-mpi |
2035 | DSA public key value @math{y = g^x \bmod p}. | 2035 | DSA public key value @math{y = g^x \bmod p}. |
2036 | @item x-mpi | 2036 | @item x-mpi |
2037 | DSA secret exponent x. | 2037 | DSA secret exponent x. |
2038 | @end table | 2038 | @end table |
2039 | 2039 | ||
2040 | All the MPI values are expected to be in @code{GCRYMPI_FMT_USG} format. | 2040 | All the MPI values are expected to be in @code{GCRYMPI_FMT_USG} format. |
2041 | The public key is similar with "private-key" replaced by "public-key" | 2041 | The public key is similar with "private-key" replaced by "public-key" |
2042 | and no @var{x-mpi}. | 2042 | and no @var{x-mpi}. |
2043 | 2043 | ||
2044 | An easy way to create such an S-expressions is by using | 2044 | An easy way to create such an S-expressions is by using |
2045 | @code{gcry_sexp_build} which allows to pass a string with printf-like | 2045 | @code{gcry_sexp_build} which allows to pass a string with printf-like |
2046 | escapes to insert MPI values. | 2046 | escapes to insert MPI values. |
2047 | 2047 | ||
2048 | @noindent | 2048 | @noindent |
2049 | Here is an example for an RSA key: | 2049 | Here is an example for an RSA key: |
2050 | 2050 | ||
2051 | @example | 2051 | @example |
2052 | (private-key | 2052 | (private-key |
2053 | (rsa | 2053 | (rsa |
2054 | (n @var{n-mpi}) | 2054 | (n @var{n-mpi}) |
2055 | (e @var{e-mpi}) | 2055 | (e @var{e-mpi}) |
2056 | (d @var{d-mpi}) | 2056 | (d @var{d-mpi}) |
2057 | (p @var{p-mpi}) | 2057 | (p @var{p-mpi}) |
2058 | (q @var{q-mpi}) | 2058 | (q @var{q-mpi}) |
2059 | (u @var{u-mpi}) | 2059 | (u @var{u-mpi}) |
2060 | @end example | 2060 | @end example |
2061 | 2061 | ||
2062 | @noindent | 2062 | @noindent |
2063 | with | 2063 | with |
2064 | 2064 | ||
2065 | @table @var | 2065 | @table @var |
2066 | @item n-mpi | 2066 | @item n-mpi |
2067 | RSA public modulus @math{n}. | 2067 | RSA public modulus @math{n}. |
2068 | @item e-mpi | 2068 | @item e-mpi |
2069 | RSA public exponent @math{e}. | 2069 | RSA public exponent @math{e}. |
2070 | @item d-mpi | 2070 | @item d-mpi |
2071 | RSA secret exponent @math{d = e^{-1} \bmod (p-1)(q-1)}. | 2071 | RSA secret exponent @math{d = e^{-1} \bmod (p-1)(q-1)}. |
2072 | @item p-mpi | 2072 | @item p-mpi |
2073 | RSA secret prime @math{p}. | 2073 | RSA secret prime @math{p}. |
2074 | @item q-mpi | 2074 | @item q-mpi |
2075 | RSA secret prime @math{q} with @math{q > p}. | 2075 | RSA secret prime @math{q} with @math{q > p}. |
2076 | @item u-mpi | 2076 | @item u-mpi |
2077 | multiplicative inverse @math{u = p^{-1} \bmod q}. | 2077 | multiplicative inverse @math{u = p^{-1} \bmod q}. |
2078 | @end table | 2078 | @end table |
2079 | 2079 | ||
2080 | @node Public key modules | 2080 | @node Public key modules |
2081 | @section Public key modules | 2081 | @section Public key modules |
2082 | 2082 | ||
2083 | @acronym{Libgcrypt} makes it possible to load additional `public key | 2083 | @acronym{Libgcrypt} makes it possible to load additional `public key |
2084 | modules'; these public key algorithms can be used just like the | 2084 | modules'; these public key algorithms can be used just like the |
2085 | algorithms that are built into the library directly. For an | 2085 | algorithms that are built into the library directly. For an |
2086 | introduction into extension modules, see @xref{Modules}. | 2086 | introduction into extension modules, see @xref{Modules}. |
2087 | 2087 | ||
2088 | @deftp {Data type} gcry_pk_spec_t | 2088 | @deftp {Data type} gcry_pk_spec_t |
2089 | This is the `module specification structure' needed for registering | 2089 | This is the `module specification structure' needed for registering |
2090 | public key modules, which has to be filled in by the user before it | 2090 | public key modules, which has to be filled in by the user before it |
2091 | can be used to register a module. It contains the following members: | 2091 | can be used to register a module. It contains the following members: |
2092 | 2092 | ||
2093 | @table @code | 2093 | @table @code |
2094 | @item const char *name | 2094 | @item const char *name |
2095 | The primary name of this algorithm. | 2095 | The primary name of this algorithm. |
2096 | @item char **aliases | 2096 | @item char **aliases |
2097 | A list of strings that are `aliases' for the algorithm. The list | 2097 | A list of strings that are `aliases' for the algorithm. The list |
2098 | must be terminated with a NULL element. | 2098 | must be terminated with a NULL element. |
2099 | @item const char *elements_pkey | 2099 | @item const char *elements_pkey |
2100 | String containing the one-letter names of the MPI values contained in | 2100 | String containing the one-letter names of the MPI values contained in |
2101 | a public key. | 2101 | a public key. |
2102 | @item const char *element_skey | 2102 | @item const char *element_skey |
2103 | String containing the one-letter names of the MPI values contained in | 2103 | String containing the one-letter names of the MPI values contained in |
2104 | a secret key. | 2104 | a secret key. |
2105 | @item const char *elements_enc | 2105 | @item const char *elements_enc |
2106 | String containing the one-letter names of the MPI values that are the | 2106 | String containing the one-letter names of the MPI values that are the |
2107 | result of an encryption operation using this algorithm. | 2107 | result of an encryption operation using this algorithm. |
2108 | @item const char *elements_sig | 2108 | @item const char *elements_sig |
2109 | String containing the one-letter names of the MPI values that are the | 2109 | String containing the one-letter names of the MPI values that are the |
2110 | result of a sign operation using this algorithm. | 2110 | result of a sign operation using this algorithm. |
2111 | @item const char *elements_grip | 2111 | @item const char *elements_grip |
2112 | String containing the one-letter names of the MPI values that are to | 2112 | String containing the one-letter names of the MPI values that are to |
2113 | be included in the `key grip'. | 2113 | be included in the `key grip'. |
2114 | @item int use | 2114 | @item int use |
2115 | The bitwise-OR of the following flags, depending on the abilities of | 2115 | The bitwise-OR of the following flags, depending on the abilities of |
2116 | the algorithm: | 2116 | the algorithm: |
2117 | @table @code | 2117 | @table @code |
2118 | @item GCRY_PK_USAGE_SIGN | 2118 | @item GCRY_PK_USAGE_SIGN |
2119 | The algorithm supports signing and verifying of data. | 2119 | The algorithm supports signing and verifying of data. |
2120 | @item GCRY_PK_USAGE_ENCR | 2120 | @item GCRY_PK_USAGE_ENCR |
2121 | The algorithm supports the encryption and decryption of data. | 2121 | The algorithm supports the encryption and decryption of data. |
2122 | @end table | 2122 | @end table |
2123 | @item gcry_pk_generate_t generate | 2123 | @item gcry_pk_generate_t generate |
2124 | The function responsible for generating a new key pair. See below for | 2124 | The function responsible for generating a new key pair. See below for |
2125 | a description of this type. | 2125 | a description of this type. |
2126 | @item gcry_pk_check_secret_key_t check_secret_key | 2126 | @item gcry_pk_check_secret_key_t check_secret_key |
2127 | The function responsible for checking the sanity of a provided secret | 2127 | The function responsible for checking the sanity of a provided secret |
2128 | key. See below for a description of this type. | 2128 | key. See below for a description of this type. |
2129 | @item gcry_pk_encrypt_t encrypt | 2129 | @item gcry_pk_encrypt_t encrypt |
2130 | The function responsible for encrypting data. See below for a | 2130 | The function responsible for encrypting data. See below for a |
2131 | description of this type. | 2131 | description of this type. |
2132 | @item gcry_pk_decrypt_t decrypt | 2132 | @item gcry_pk_decrypt_t decrypt |
2133 | The function responsible for decrypting data. See below for a | 2133 | The function responsible for decrypting data. See below for a |
2134 | description of this type. | 2134 | description of this type. |
2135 | @item gcry_pk_sign_t sign | 2135 | @item gcry_pk_sign_t sign |
2136 | The function responsible for signing data. See below for a description | 2136 | The function responsible for signing data. See below for a description |
2137 | of this type. | 2137 | of this type. |
2138 | @item gcry_pk_verify_t verify | 2138 | @item gcry_pk_verify_t verify |
2139 | The function responsible for verifying that the provided signature | 2139 | The function responsible for verifying that the provided signature |
2140 | matches the provided data. See below for a description of this type. | 2140 | matches the provided data. See below for a description of this type. |
2141 | @item gcry_pk_get_nbits_t get_nbits | 2141 | @item gcry_pk_get_nbits_t get_nbits |
2142 | The function responsible for returning the number of bits of a provided | 2142 | The function responsible for returning the number of bits of a provided |
2143 | key. See below for a description of this type. | 2143 | key. See below for a description of this type. |
2144 | @end table | 2144 | @end table |
2145 | @end deftp | 2145 | @end deftp |
2146 | 2146 | ||
2147 | @deftp {Data type} gcry_pk_generate_t | 2147 | @deftp {Data type} gcry_pk_generate_t |
2148 | Type for the `generate' function, defined as: gcry_err_code_t | 2148 | Type for the `generate' function, defined as: gcry_err_code_t |
2149 | (*gcry_pk_generate_t) (int algo, unsigned int nbits, unsigned long | 2149 | (*gcry_pk_generate_t) (int algo, unsigned int nbits, unsigned long |
2150 | use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors) | 2150 | use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors) |
2151 | @end deftp | 2151 | @end deftp |
2152 | 2152 | ||
2153 | @deftp {Data type} gcry_pk_check_secret_key_t | 2153 | @deftp {Data type} gcry_pk_check_secret_key_t |
2154 | Type for the `check_secret_key' function, defined as: gcry_err_code_t | 2154 | Type for the `check_secret_key' function, defined as: gcry_err_code_t |
2155 | (*gcry_pk_check_secret_key_t) (int algo, gcry_mpi_t *skey) | 2155 | (*gcry_pk_check_secret_key_t) (int algo, gcry_mpi_t *skey) |
2156 | @end deftp | 2156 | @end deftp |
2157 | 2157 | ||
2158 | @deftp {Data type} gcry_pk_encrypt_t | 2158 | @deftp {Data type} gcry_pk_encrypt_t |
2159 | Type for the `encrypt' function, defined as: gcry_err_code_t | 2159 | Type for the `encrypt' function, defined as: gcry_err_code_t |
2160 | (*gcry_pk_encrypt_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, | 2160 | (*gcry_pk_encrypt_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, |
2161 | gcry_mpi_t *pkey, int flags) | 2161 | gcry_mpi_t *pkey, int flags) |
2162 | @end deftp | 2162 | @end deftp |
2163 | 2163 | ||
2164 | @deftp {Data type} gcry_pk_decrypt_t | 2164 | @deftp {Data type} gcry_pk_decrypt_t |
2165 | Type for the `decrypt' function, defined as: gcry_err_code_t | 2165 | Type for the `decrypt' function, defined as: gcry_err_code_t |
2166 | (*gcry_pk_decrypt_t) (int algo, gcry_mpi_t *result, gcry_mpi_t *data, | 2166 | (*gcry_pk_decrypt_t) (int algo, gcry_mpi_t *result, gcry_mpi_t *data, |
2167 | gcry_mpi_t *skey, int flags) | 2167 | gcry_mpi_t *skey, int flags) |
2168 | @end deftp | 2168 | @end deftp |
2169 | 2169 | ||
2170 | @deftp {Data type} gcry_pk_sign_t | 2170 | @deftp {Data type} gcry_pk_sign_t |
2171 | Type for the `sign' function, defined as: gcry_err_code_t | 2171 | Type for the `sign' function, defined as: gcry_err_code_t |
2172 | (*gcry_pk_sign_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, | 2172 | (*gcry_pk_sign_t) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, |
2173 | gcry_mpi_t *skey) | 2173 | gcry_mpi_t *skey) |
2174 | @end deftp | 2174 | @end deftp |
2175 | 2175 | ||
2176 | @deftp {Data type} gcry_pk_verify_t | 2176 | @deftp {Data type} gcry_pk_verify_t |
2177 | Type for the `verify' function, defined as: gcry_err_code_t | 2177 | Type for the `verify' function, defined as: gcry_err_code_t |
2178 | (*gcry_pk_verify_t) (int algo, gcry_mpi_t hash, gcry_mpi_t *data, | 2178 | (*gcry_pk_verify_t) (int algo, gcry_mpi_t hash, gcry_mpi_t *data, |
2179 | gcry_mpi_t *pkey, int (*cmp) (void *, gcry_mpi_t), void *opaquev) | 2179 | gcry_mpi_t *pkey, int (*cmp) (void *, gcry_mpi_t), void *opaquev) |
2180 | @end deftp | 2180 | @end deftp |
2181 | 2181 | ||
2182 | @deftp {Data type} gcry_pk_get_nbits_t | 2182 | @deftp {Data type} gcry_pk_get_nbits_t |
2183 | Type for the `get_nbits' function, defined as: unsigned | 2183 | Type for the `get_nbits' function, defined as: unsigned |
2184 | (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey) | 2184 | (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey) |
2185 | @end deftp | 2185 | @end deftp |
2186 | 2186 | ||
2187 | @deftypefun gcry_error_t gcry_pk_register (gcry_pk_spec_t *@var{pubkey}, unsigned int *algorithm_id, gcry_module_t *@var{module}) | 2187 | @deftypefun gcry_error_t gcry_pk_register (gcry_pk_spec_t *@var{pubkey}, unsigned int *algorithm_id, gcry_module_t *@var{module}) |
2188 | 2188 | ||
2189 | Register a new public key module whose specification can be found in | 2189 | Register a new public key module whose specification can be found in |
2190 | @var{pubkey}. On success, a new algorithm ID is stored in | 2190 | @var{pubkey}. On success, a new algorithm ID is stored in |
2191 | @var{algorithm_id} and a pointer representing this module is stored | 2191 | @var{algorithm_id} and a pointer representing this module is stored |
2192 | in @var{module}. | 2192 | in @var{module}. |
2193 | @end deftypefun | 2193 | @end deftypefun |
2194 | 2194 | ||
2195 | @deftypefun void gcry_pk_unregister (gcry_module_t @var{module}) | 2195 | @deftypefun void gcry_pk_unregister (gcry_module_t @var{module}) |
2196 | Unregister the public key module identified by @var{module}, which | 2196 | Unregister the public key module identified by @var{module}, which |
2197 | must have been registered with gcry_pk_register. | 2197 | must have been registered with gcry_pk_register. |
2198 | @end deftypefun | 2198 | @end deftypefun |
2199 | 2199 | ||
2200 | @deftypefun gcry_error_t gcry_pk_list (int *@var{list}, int *@var{list_length}) | 2200 | @deftypefun gcry_error_t gcry_pk_list (int *@var{list}, int *@var{list_length}) |
2201 | Get a list consisting of the IDs of the loaded pubkey modules. If | 2201 | Get a list consisting of the IDs of the loaded pubkey modules. If |
2202 | @var{list} is zero, write the number of loaded pubkey modules to | 2202 | @var{list} is zero, write the number of loaded pubkey modules to |
2203 | @var{list_length} and return. If @var{list} is non-zero, the first | 2203 | @var{list_length} and return. If @var{list} is non-zero, the first |
2204 | *@var{list_length} algorithm IDs are stored in @var{list}, which must | 2204 | *@var{list_length} algorithm IDs are stored in @var{list}, which must |
2205 | be of according size. In case there are less pubkey modules than | 2205 | be of according size. In case there are less pubkey modules than |
2206 | *@var{list_length}, *@var{list_length} is updated to the correct | 2206 | *@var{list_length}, *@var{list_length} is updated to the correct |
2207 | number. | 2207 | number. |
2208 | @end deftypefun | 2208 | @end deftypefun |
2209 | 2209 | ||
2210 | @node Cryptographic Functions | 2210 | @node Cryptographic Functions |
2211 | @section Cryptographic Functions | 2211 | @section Cryptographic Functions |
2212 | 2212 | ||
2213 | @noindent | 2213 | @noindent |
2214 | Note, that we will in future allow to use keys without p,q and u | 2214 | Note, that we will in future allow to use keys without p,q and u |
2215 | specified and may also support other parameters for performance | 2215 | specified and may also support other parameters for performance |
2216 | reasons. | 2216 | reasons. |
2217 | 2217 | ||
2218 | @noindent | 2218 | @noindent |
2219 | 2219 | ||
2220 | Some functions operating on S-expressions support `flags', that | 2220 | Some functions operating on S-expressions support `flags', that |
2221 | influence the operation. These flags have to be listed in a | 2221 | influence the operation. These flags have to be listed in a |
2222 | sub-S-expression named `flags'; the following flags are known: | 2222 | sub-S-expression named `flags'; the following flags are known: |
2223 | 2223 | ||
2224 | @table @var | 2224 | @table @var |
2225 | @item pkcs1 | 2225 | @item pkcs1 |
2226 | Use PKCS#1 block type 2 padding. | 2226 | Use PKCS#1 block type 2 padding. |
2227 | @item no-blinding | 2227 | @item no-blinding |
2228 | Do not use a technique called `blinding', which is used by default in | 2228 | Do not use a technique called `blinding', which is used by default in |
2229 | order to prevent leaking of secret information. Blinding is only | 2229 | order to prevent leaking of secret information. Blinding is only |
2230 | implemented by RSA, but it might be implemented by other algorithms in | 2230 | implemented by RSA, but it might be implemented by other algorithms in |
2231 | the future as well, when necessary. | 2231 | the future as well, when necessary. |
2232 | @end table | 2232 | @end table |
2233 | 2233 | ||
2234 | @noindent | 2234 | @noindent |
2235 | Now that we know the key basics, we can carry on and explain how to | 2235 | Now that we know the key basics, we can carry on and explain how to |
2236 | encrypt and decrypt data. In almost all cases the data is a random | 2236 | encrypt and decrypt data. In almost all cases the data is a random |
2237 | session key which is in turn used for the actual encryption of the real | 2237 | session key which is in turn used for the actual encryption of the real |
2238 | data. There are 2 functions to do this: | 2238 | data. There are 2 functions to do this: |
2239 | 2239 | ||
2240 | @deftypefun gcry_error_t gcry_pk_encrypt (@w{gcry_sexp_t *@var{r_ciph},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{pkey}}) | 2240 | @deftypefun gcry_error_t gcry_pk_encrypt (@w{gcry_sexp_t *@var{r_ciph},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{pkey}}) |
2241 | 2241 | ||
2242 | Obviously a public key must be provided for encryption. It is | 2242 | Obviously a public key must be provided for encryption. It is |
2243 | expected as an appropriate S-expression (see above) in @var{pkey}. | 2243 | expected as an appropriate S-expression (see above) in @var{pkey}. |
2244 | The data to be encrypted can either be in the simple old format, which | 2244 | The data to be encrypted can either be in the simple old format, which |
2245 | is a very simple S-expression consisting only of one MPI, or it may be | 2245 | is a very simple S-expression consisting only of one MPI, or it may be |
2246 | a more complex S-expression which also allows to specify flags for | 2246 | a more complex S-expression which also allows to specify flags for |
2247 | operation, like e.g. padding rules. | 2247 | operation, like e.g. padding rules. |
2248 | 2248 | ||
2249 | @noindent | 2249 | @noindent |
2250 | If you don't want to let @acronym{Libgcrypt} handle the padding, you must pass an | 2250 | If you don't want to let @acronym{Libgcrypt} handle the padding, you must pass an |
2251 | appropriate MPI using this expression for @var{data}: | 2251 | appropriate MPI using this expression for @var{data}: |
2252 | 2252 | ||
2253 | @example | 2253 | @example |
2254 | (data | 2254 | (data |
2255 | (flags raw) | 2255 | (flags raw) |
2256 | (value @var{mpi})) | 2256 | (value @var{mpi})) |
2257 | @end example | 2257 | @end example |
2258 | 2258 | ||
2259 | @noindent | 2259 | @noindent |
2260 | This has the same semantics as the old style MPI only way. @var{MPI} is | 2260 | This has the same semantics as the old style MPI only way. @var{MPI} is |
2261 | the actual data, already padded appropriate for your protocol. Most | 2261 | the actual data, already padded appropriate for your protocol. Most |
2262 | systems however use PKCS#1 padding and so you can use this S-expression | 2262 | systems however use PKCS#1 padding and so you can use this S-expression |
2263 | for @var{data}: | 2263 | for @var{data}: |
2264 | 2264 | ||
2265 | @example | 2265 | @example |
2266 | (data | 2266 | (data |
2267 | (flags pkcs1) | 2267 | (flags pkcs1) |
2268 | (value @var{block})) | 2268 | (value @var{block})) |
2269 | @end example | 2269 | @end example |
2270 | 2270 | ||
2271 | @noindent | 2271 | @noindent |
2272 | Here, the "flags" list has the "pkcs1" flag which let the function know | 2272 | Here, the "flags" list has the "pkcs1" flag which let the function know |
2273 | that it should provide PKCS#1 block type 2 padding. The actual data to | 2273 | that it should provide PKCS#1 block type 2 padding. The actual data to |
2274 | be encrypted is passed as a string of octets in @var{block}. The | 2274 | be encrypted is passed as a string of octets in @var{block}. The |
2275 | function checks that this data actually can be used with the given key, | 2275 | function checks that this data actually can be used with the given key, |
2276 | does the padding and encrypts it. | 2276 | does the padding and encrypts it. |
2277 | 2277 | ||
2278 | If the function could successfully perform the encryption, the return | 2278 | If the function could successfully perform the encryption, the return |
2279 | value will be 0 and a a new S-expression with the encrypted result is | 2279 | value will be 0 and a a new S-expression with the encrypted result is |
2280 | allocated and assign to the variable at the address of @var{r_ciph}. | 2280 | allocated and assign to the variable at the address of @var{r_ciph}. |
2281 | The caller is responsible to release this value using | 2281 | The caller is responsible to release this value using |
2282 | @code{gcry_sexp_release}. In case of an error, an error code is | 2282 | @code{gcry_sexp_release}. In case of an error, an error code is |
2283 | returned and @var{r_ciph} will be set to @code{NULL}. | 2283 | returned and @var{r_ciph} will be set to @code{NULL}. |
2284 | 2284 | ||
2285 | @noindent | 2285 | @noindent |
2286 | The returned S-expression has this format when used with RSA: | 2286 | The returned S-expression has this format when used with RSA: |
2287 | 2287 | ||
2288 | @example | 2288 | @example |
2289 | (enc-val | 2289 | (enc-val |
2290 | (rsa | 2290 | (rsa |
2291 | (a @var{a-mpi}))) | 2291 | (a @var{a-mpi}))) |
2292 | @end example | 2292 | @end example |
2293 | 2293 | ||
2294 | @noindent | 2294 | @noindent |
2295 | Where @var{a-mpi} is an MPI with the result of the RSA operation. When | 2295 | Where @var{a-mpi} is an MPI with the result of the RSA operation. When |
2296 | using the ElGamal algorithm, the return value will have this format: | 2296 | using the ElGamal algorithm, the return value will have this format: |
2297 | 2297 | ||
2298 | @example | 2298 | @example |
2299 | (enc-val | 2299 | (enc-val |
2300 | (elg | 2300 | (elg |
2301 | (a @var{a-mpi}) | 2301 | (a @var{a-mpi}) |
2302 | (b @var{b-mpi}))) | 2302 | (b @var{b-mpi}))) |
2303 | @end example | 2303 | @end example |
2304 | 2304 | ||
2305 | @noindent | 2305 | @noindent |
2306 | Where @var{a-mpi} and @var{b-mpi} are MPIs with the result of the | 2306 | Where @var{a-mpi} and @var{b-mpi} are MPIs with the result of the |
2307 | ElGamal encryption operation. | 2307 | ElGamal encryption operation. |
2308 | @end deftypefun | 2308 | @end deftypefun |
2309 | @c end gcry_pk_encrypt | 2309 | @c end gcry_pk_encrypt |
2310 | 2310 | ||
2311 | @deftypefun gcry_error_t gcry_pk_decrypt (@w{gcry_sexp_t *@var{r_plain},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{skey}}) | 2311 | @deftypefun gcry_error_t gcry_pk_decrypt (@w{gcry_sexp_t *@var{r_plain},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{skey}}) |
2312 | 2312 | ||
2313 | Obviously a private key must be provided for decryption. It is expected | 2313 | Obviously a private key must be provided for decryption. It is expected |
2314 | as an appropriate S-expression (see above) in @var{skey}. The data to | 2314 | as an appropriate S-expression (see above) in @var{skey}. The data to |
2315 | be decrypted must match the format of the result as returned by | 2315 | be decrypted must match the format of the result as returned by |
2316 | @code{gcry_pk_encrypt}, but should be enlarged with a @code{flags} | 2316 | @code{gcry_pk_encrypt}, but should be enlarged with a @code{flags} |
2317 | element: | 2317 | element: |
2318 | 2318 | ||
2319 | @example | 2319 | @example |
2320 | (enc-val | 2320 | (enc-val |
2321 | (flags) | 2321 | (flags) |
2322 | (elg | 2322 | (elg |
2323 | (a @var{a-mpi}) | 2323 | (a @var{a-mpi}) |
2324 | (b @var{b-mpi}))) | 2324 | (b @var{b-mpi}))) |
2325 | @end example | 2325 | @end example |
2326 | 2326 | ||
2327 | @noindent | 2327 | @noindent |
2328 | Note, that this function currently does not know of any padding | 2328 | Note, that this function currently does not know of any padding |
2329 | methods and the caller must do any un-padding on his own. | 2329 | methods and the caller must do any un-padding on his own. |
2330 | 2330 | ||
2331 | @noindent | 2331 | @noindent |
2332 | The function returns 0 on success or an error code. The variable at the | 2332 | The function returns 0 on success or an error code. The variable at the |
2333 | address of @var{r_plain} will be set to NULL on error or receive the | 2333 | address of @var{r_plain} will be set to NULL on error or receive the |
2334 | decrypted value on success. The format of @var{r_plain} is a | 2334 | decrypted value on success. The format of @var{r_plain} is a |
2335 | simple S-expression part (i.e. not a valid one) with just one MPI if | 2335 | simple S-expression part (i.e. not a valid one) with just one MPI if |
2336 | there was no @code{flags} element in @var{data}; if at least an empty | 2336 | there was no @code{flags} element in @var{data}; if at least an empty |
2337 | @code{flags} is passed in @var{data}, the format is: | 2337 | @code{flags} is passed in @var{data}, the format is: |
2338 | 2338 | ||
2339 | @example | 2339 | @example |
2340 | (value @var{plaintext}) | 2340 | (value @var{plaintext}) |
2341 | @end example | 2341 | @end example |
2342 | @end deftypefun | 2342 | @end deftypefun |
2343 | @c end gcry_pk_decrypt | 2343 | @c end gcry_pk_decrypt |
2344 | 2344 | ||
2345 | 2345 | ||
2346 | Another operation commonly performed using public key cryptography is | 2346 | Another operation commonly performed using public key cryptography is |
2347 | signing data. In some sense this is even more important than | 2347 | signing data. In some sense this is even more important than |
2348 | encryption because digital signatures are an important instrument for | 2348 | encryption because digital signatures are an important instrument for |
2349 | key management. @acronym{Libgcrypt} supports digital signatures using | 2349 | key management. @acronym{Libgcrypt} supports digital signatures using |
2350 | 2 functions, similar to the encryption functions: | 2350 | 2 functions, similar to the encryption functions: |
2351 | 2351 | ||
2352 | @deftypefun gcry_error_t gcry_pk_sign (@w{gcry_sexp_t *@var{r_sig},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{skey}}) | 2352 | @deftypefun gcry_error_t gcry_pk_sign (@w{gcry_sexp_t *@var{r_sig},} @w{gcry_sexp_t @var{data},} @w{gcry_sexp_t @var{skey}}) |
2353 | 2353 | ||
2354 | This function creates a digital signature for @var{data} using the | 2354 | This function creates a digital signature for @var{data} using the |
2355 | private key @var{skey} and place it into the variable at the address of | 2355 | private key @var{skey} and place it into the variable at the address of |
2356 | @var{r_sig}. @var{data} may either be the simple old style S-expression | 2356 | @var{r_sig}. @var{data} may either be the simple old style S-expression |
2357 | with just one MPI or a modern and more versatile S-expression which | 2357 | with just one MPI or a modern and more versatile S-expression which |
2358 | allows to let @acronym{Libgcrypt} handle padding: | 2358 | allows to let @acronym{Libgcrypt} handle padding: |
2359 | 2359 | ||
2360 | @example | 2360 | @example |
2361 | (data | 2361 | (data |
2362 | (flags pkcs1) | 2362 | (flags pkcs1) |
2363 | (hash @var{hash-algo} @var{block})) | 2363 | (hash @var{hash-algo} @var{block})) |
2364 | @end example | 2364 | @end example |
2365 | 2365 | ||
2366 | @noindent | 2366 | @noindent |
2367 | This example requests to sign the data in @var{block} after applying | 2367 | This example requests to sign the data in @var{block} after applying |
2368 | PKCS#1 block type 1 style padding. @var{hash-algo} is a string with the | 2368 | PKCS#1 block type 1 style padding. @var{hash-algo} is a string with the |
2369 | hash algorithm to be encoded into the signature, this may be any hash | 2369 | hash algorithm to be encoded into the signature, this may be any hash |
2370 | algorithm name as supported by @acronym{Libgcrypt}. Most likely, this will be | 2370 | algorithm name as supported by @acronym{Libgcrypt}. Most likely, this will be |
2371 | "sha1", "rmd160" or "md5". It is obvious that the length of @var{block} | 2371 | "sha1", "rmd160" or "md5". It is obvious that the length of @var{block} |
2372 | must match the size of that message digests; the function checks that | 2372 | must match the size of that message digests; the function checks that |
2373 | this and other constraints are valid. | 2373 | this and other constraints are valid. |
2374 | 2374 | ||
2375 | @noindent | 2375 | @noindent |
2376 | If PKCS#1 padding is not required (because the caller does already | 2376 | If PKCS#1 padding is not required (because the caller does already |
2377 | provide a padded value), either the old format or better the following | 2377 | provide a padded value), either the old format or better the following |
2378 | format should be used: | 2378 | format should be used: |
2379 | 2379 | ||
2380 | @example | 2380 | @example |
2381 | (data | 2381 | (data |
2382 | (flags raw) | 2382 | (flags raw) |
2383 | (value @var{mpi})) | 2383 | (value @var{mpi})) |
2384 | @end example | 2384 | @end example |
2385 | 2385 | ||
2386 | @noindent | 2386 | @noindent |
2387 | Here, the data to be signed is directly given as an @var{MPI}. | 2387 | Here, the data to be signed is directly given as an @var{MPI}. |
2388 | 2388 | ||
2389 | @noindent | 2389 | @noindent |
2390 | The signature is returned as a newly allocated S-expression in | 2390 | The signature is returned as a newly allocated S-expression in |
2391 | @var{r_sig} using this format for RSA: | 2391 | @var{r_sig} using this format for RSA: |
2392 | 2392 | ||
2393 | @example | 2393 | @example |
2394 | (sig-val | 2394 | (sig-val |
2395 | (rsa | 2395 | (rsa |
2396 | (s @var{s-mpi}))) | 2396 | (s @var{s-mpi}))) |
2397 | @end example | 2397 | @end example |
2398 | 2398 | ||
2399 | Where @var{s-mpi} is the result of the RSA sign operation. For DSA the | 2399 | Where @var{s-mpi} is the result of the RSA sign operation. For DSA the |
2400 | S-expression returned is: | 2400 | S-expression returned is: |
2401 | 2401 | ||
2402 | @example | 2402 | @example |
2403 | (sig-val | 2403 | (sig-val |
2404 | (dsa | 2404 | (dsa |
2405 | (r @var{r-mpi}) | 2405 | (r @var{r-mpi}) |
2406 | (s @var{s-mpi}))) | 2406 | (s @var{s-mpi}))) |
2407 | @end example | 2407 | @end example |
2408 | 2408 | ||
2409 | Where @var{r-mpi} and @var{s-mpi} are the result of the DSA sign | 2409 | Where @var{r-mpi} and @var{s-mpi} are the result of the DSA sign |
2410 | operation. For ElGamal signing (which is slow, yields large numbers | 2410 | operation. For ElGamal signing (which is slow, yields large numbers |
2411 | and probably is not as secure as the other algorithms), the same format is | 2411 | and probably is not as secure as the other algorithms), the same format is |
2412 | used with "elg" replacing "dsa". | 2412 | used with "elg" replacing "dsa". |
2413 | @end deftypefun | 2413 | @end deftypefun |
2414 | @c end gcry_pk_sign | 2414 | @c end gcry_pk_sign |
2415 | 2415 | ||
2416 | @noindent | 2416 | @noindent |
2417 | The operation most commonly used is definitely the verification of a | 2417 | The operation most commonly used is definitely the verification of a |
2418 | signature. @acronym{Libgcrypt} provides this function: | 2418 | signature. @acronym{Libgcrypt} provides this function: |
2419 | 2419 | ||
2420 | @deftypefun gcry_error_t gcry_pk_verify (@w{gcry_sexp_t @var{sig}}, @w{gcry_sexp_t @var{data}}, @w{gcry_sexp_t @var{pkey}}) | 2420 | @deftypefun gcry_error_t gcry_pk_verify (@w{gcry_sexp_t @var{sig}}, @w{gcry_sexp_t @var{data}}, @w{gcry_sexp_t @var{pkey}}) |
2421 | 2421 | ||
2422 | This is used to check whether the signature @var{sig} matches the | 2422 | This is used to check whether the signature @var{sig} matches the |
2423 | @var{data}. The public key @var{pkey} must be provided to perform this | 2423 | @var{data}. The public key @var{pkey} must be provided to perform this |
2424 | verification. This function is similar in its parameters to | 2424 | verification. This function is similar in its parameters to |
2425 | @code{gcry_pk_sign} with the exceptions that the public key is used | 2425 | @code{gcry_pk_sign} with the exceptions that the public key is used |
2426 | instead of the private key and that no signature is created but a | 2426 | instead of the private key and that no signature is created but a |
2427 | signature, in a format as created by @code{gcry_pk_sign}, is passed to | 2427 | signature, in a format as created by @code{gcry_pk_sign}, is passed to |
2428 | the function in @var{sig}. | 2428 | the function in @var{sig}. |
2429 | 2429 | ||
2430 | @noindent | 2430 | @noindent |
2431 | The result is 0 for success (i.e. the data matches the signature), or an | 2431 | The result is 0 for success (i.e. the data matches the signature), or an |
2432 | error code where the most relevant code is @code{GCRYERR_BAD_SIGNATURE} | 2432 | error code where the most relevant code is @code{GCRYERR_BAD_SIGNATURE} |
2433 | to indicate that the signature does not match the provided data. | 2433 | to indicate that the signature does not match the provided data. |
2434 | 2434 | ||
2435 | @end deftypefun | 2435 | @end deftypefun |
2436 | @c end gcry_pk_verify | 2436 | @c end gcry_pk_verify |
2437 | 2437 | ||
2438 | @node General public-key related Functions | 2438 | @node General public-key related Functions |
2439 | @section General public-key related Functions | 2439 | @section General public-key related Functions |
2440 | 2440 | ||
2441 | @noindent | 2441 | @noindent |
2442 | A couple of utility functions are available to retrieve the length of | 2442 | A couple of utility functions are available to retrieve the length of |
2443 | the key, map algorithm identifiers and perform sanity checks: | 2443 | the key, map algorithm identifiers and perform sanity checks: |
2444 | 2444 | ||
2445 | @deftypefun {const char *} gcry_pk_algo_name (int @var{algo}) | 2445 | @deftypefun {const char *} gcry_pk_algo_name (int @var{algo}) |
2446 | 2446 | ||
2447 | Map the public key algorithm id @var{algo} to a string representation of | 2447 | Map the public key algorithm id @var{algo} to a string representation of |
2448 | the algorithm name. For unknown algorithms this functions returns an | 2448 | the algorithm name. For unknown algorithms this functions returns an |
2449 | empty string. | 2449 | empty string. |
2450 | @end deftypefun | 2450 | @end deftypefun |
2451 | 2451 | ||
2452 | @deftypefun int gcry_pk_map_name (const char *@var{name}) | 2452 | @deftypefun int gcry_pk_map_name (const char *@var{name}) |
2453 | 2453 | ||
2454 | Map the algorithm @var{name} to a public key algorithm Id. Returns 0 if | 2454 | Map the algorithm @var{name} to a public key algorithm Id. Returns 0 if |
2455 | the algorithm name is not known. | 2455 | the algorithm name is not known. |
2456 | @end deftypefun | 2456 | @end deftypefun |
2457 | 2457 | ||
2458 | @deftypefun int gcry_pk_test_algo (int @var{algo}) | 2458 | @deftypefun int gcry_pk_test_algo (int @var{algo}) |
2459 | 2459 | ||
2460 | Return 0 if the public key algorithm @var{algo} is available for use. | 2460 | Return 0 if the public key algorithm @var{algo} is available for use. |
2461 | Note, that this is implemented as a macro. | 2461 | Note, that this is implemented as a macro. |
2462 | @end deftypefun | 2462 | @end deftypefun |
2463 | 2463 | ||
2464 | 2464 | ||
2465 | @deftypefun {unsigned int} gcry_pk_get_nbits (gcry_sexp_t @var{key}) | 2465 | @deftypefun {unsigned int} gcry_pk_get_nbits (gcry_sexp_t @var{key}) |
2466 | 2466 | ||
2467 | Return what is commonly referred as the key length for the given | 2467 | Return what is commonly referred as the key length for the given |
2468 | public or private in @var{key}. | 2468 | public or private in @var{key}. |
2469 | @end deftypefun | 2469 | @end deftypefun |
2470 | 2470 | ||
2471 | @deftypefun {unsigned char *} gcry_pk_get_keygrip (@w{gcry_sexp_t @var{key}}, @w{unsigned char *@var{array}}) | 2471 | @deftypefun {unsigned char *} gcry_pk_get_keygrip (@w{gcry_sexp_t @var{key}}, @w{unsigned char *@var{array}}) |
2472 | 2472 | ||
2473 | Return the so called "keygrip" which is the SHA-1 hash of the public key | 2473 | Return the so called "keygrip" which is the SHA-1 hash of the public key |
2474 | parameters expressed in a way depended on the algorithm. @var{array} | 2474 | parameters expressed in a way depended on the algorithm. @var{array} |
2475 | must either provide space for 20 bytes or @code{NULL;}. In the latter | 2475 | must either provide space for 20 bytes or @code{NULL;}. In the latter |
2476 | case a newly allocated array of that size is returned. On success a | 2476 | case a newly allocated array of that size is returned. On success a |
2477 | pointer to the newly allocated space or to @var{array} is returned. | 2477 | pointer to the newly allocated space or to @var{array} is returned. |
2478 | @code{NULL} is returned to indicate an error which is most likely an unknown | 2478 | @code{NULL} is returned to indicate an error which is most likely an unknown |
2479 | algorithm or one where a "keygrip" has not yet been defined. | 2479 | algorithm or one where a "keygrip" has not yet been defined. |
2480 | The function accepts public or secret keys in @var{key}. | 2480 | The function accepts public or secret keys in @var{key}. |
2481 | @end deftypefun | 2481 | @end deftypefun |
2482 | 2482 | ||
2483 | @deftypefun gcry_error_t gcry_pk_testkey (gcry_sexp_t @var{key}) | 2483 | @deftypefun gcry_error_t gcry_pk_testkey (gcry_sexp_t @var{key}) |
2484 | 2484 | ||
2485 | Return zero if the private key @var{key} is `sane', an error code otherwise. | 2485 | Return zero if the private key @var{key} is `sane', an error code otherwise. |
2486 | Note, that it is not possible to chek the `saneness' of a public key. | 2486 | Note, that it is not possible to chek the `saneness' of a public key. |
2487 | 2487 | ||
2488 | @end deftypefun | 2488 | @end deftypefun |
2489 | 2489 | ||
2490 | 2490 | ||
2491 | @deftypefun int gcry_pk_algo_info (@w{int @var{algo}}, @w{int @var{what}}, @w{void *@var{buffer}}, @w{size_t *@var{nbytes}}) | 2491 | @deftypefun int gcry_pk_algo_info (@w{int @var{algo}}, @w{int @var{what}}, @w{void *@var{buffer}}, @w{size_t *@var{nbytes}}) |
2492 | 2492 | ||
2493 | Depending on the value of @var{what} return various information about | 2493 | Depending on the value of @var{what} return various information about |
2494 | the public key algorithm with the id @var{algo}. Note, that the | 2494 | the public key algorithm with the id @var{algo}. Note, that the |
2495 | function returns @code{-1} on error and the actual error code must be | 2495 | function returns @code{-1} on error and the actual error code must be |
2496 | retrieved using the function @code{gcry_errno}. The currently defined | 2496 | retrieved using the function @code{gcry_errno}. The currently defined |
2497 | values for @var{what} are: | 2497 | values for @var{what} are: |
2498 | 2498 | ||
2499 | @table @code | 2499 | @table @code |
2500 | @item GCRYCTL_TEST_ALGO: | 2500 | @item GCRYCTL_TEST_ALGO: |
2501 | Return 0 when the specified algorithm is available for use. | 2501 | Return 0 when the specified algorithm is available for use. |
2502 | @var{buffer} must be @code{NULL}, @var{nbytes} may be passed as | 2502 | @var{buffer} must be @code{NULL}, @var{nbytes} may be passed as |
2503 | @code{NULL} or point to a variable with the required usage of the | 2503 | @code{NULL} or point to a variable with the required usage of the |
2504 | algorithm. This may be 0 for "don't care" or the bit-wise OR of these | 2504 | algorithm. This may be 0 for "don't care" or the bit-wise OR of these |
2505 | flags: | 2505 | flags: |
2506 | 2506 | ||
2507 | @table @code | 2507 | @table @code |
2508 | @item GCRY_PK_USAGE_SIGN | 2508 | @item GCRY_PK_USAGE_SIGN |
2509 | Algorithm is usable for signing. | 2509 | Algorithm is usable for signing. |
2510 | @item GCRY_PK_USAGE_ENCR | 2510 | @item GCRY_PK_USAGE_ENCR |
2511 | Algorithm is usable for encryption. | 2511 | Algorithm is usable for encryption. |
2512 | @end table | 2512 | @end table |
2513 | 2513 | ||
2514 | @item GCRYCTL_GET_ALGO_USAGE: | 2514 | @item GCRYCTL_GET_ALGO_USAGE: |
2515 | Return the usage flags for the given algorithm. An invalid algorithm | 2515 | Return the usage flags for the given algorithm. An invalid algorithm |
2516 | return 0. Disabled algorithms are ignored here because we | 2516 | return 0. Disabled algorithms are ignored here because we |
2517 | want to know whether the algorithm is at all capable of a certain usage. | 2517 | want to know whether the algorithm is at all capable of a certain usage. |
2518 | 2518 | ||
2519 | @item GCRYCTL_GET_ALGO_NPKEY | 2519 | @item GCRYCTL_GET_ALGO_NPKEY |
2520 | Return the number of elements the public key for algorithm @var{algo} | 2520 | Return the number of elements the public key for algorithm @var{algo} |
2521 | consist of. Return 0 for an unknown algorithm. | 2521 | consist of. Return 0 for an unknown algorithm. |
2522 | 2522 | ||
2523 | @item GCRYCTL_GET_ALGO_NSKEY | 2523 | @item GCRYCTL_GET_ALGO_NSKEY |
2524 | Return the number of elements the private key for algorithm @var{algo} | 2524 | Return the number of elements the private key for algorithm @var{algo} |
2525 | consist of. Note that this value is always larger than that of the | 2525 | consist of. Note that this value is always larger than that of the |
2526 | public key. Return 0 for an unknown algorithm. | 2526 | public key. Return 0 for an unknown algorithm. |
2527 | 2527 | ||
2528 | @item GCRYCTL_GET_ALGO_NSIGN | 2528 | @item GCRYCTL_GET_ALGO_NSIGN |
2529 | Return the number of elements a signature created with the algorithm | 2529 | Return the number of elements a signature created with the algorithm |
2530 | @var{algo} consists of. Return 0 for an unknown algorithm or for an | 2530 | @var{algo} consists of. Return 0 for an unknown algorithm or for an |
2531 | algorithm not capable of creating signatures. | 2531 | algorithm not capable of creating signatures. |
2532 | 2532 | ||
2533 | @item GCRYCTL_GET_ALGO_NENC | 2533 | @item GCRYCTL_GET_ALGO_NENC |
2534 | Return the number of elements a encrypted message created with the algorithm | 2534 | Return the number of elements a encrypted message created with the algorithm |
2535 | @var{algo} consists of. Return 0 for an unknown algorithm or for an | 2535 | @var{algo} consists of. Return 0 for an unknown algorithm or for an |
2536 | algorithm not capable of encryption. | 2536 | algorithm not capable of encryption. |
2537 | @end table | 2537 | @end table |
2538 | 2538 | ||
2539 | @noindent | 2539 | @noindent |
2540 | Please note that parameters not required should be passed as @code{NULL}. | 2540 | Please note that parameters not required should be passed as @code{NULL}. |
2541 | @end deftypefun | 2541 | @end deftypefun |
2542 | @c end gcry_pk_algo_info | 2542 | @c end gcry_pk_algo_info |
2543 | 2543 | ||
2544 | 2544 | ||
2545 | @deftypefun gcry_error_t gcry_pk_ctl (@w{int @var{cmd}}, @w{void *@var{buffer}}, @w{size_t @var{buflen}}) | 2545 | @deftypefun gcry_error_t gcry_pk_ctl (@w{int @var{cmd}}, @w{void *@var{buffer}}, @w{size_t @var{buflen}}) |
2546 | 2546 | ||
2547 | This is a general purpose function to perform certain control | 2547 | This is a general purpose function to perform certain control |
2548 | operations. @var{cmd} controls what is to be done. The return value is | 2548 | operations. @var{cmd} controls what is to be done. The return value is |
2549 | 0 for success or an error code. Currently supported values for | 2549 | 0 for success or an error code. Currently supported values for |
2550 | @var{cmd} are: | 2550 | @var{cmd} are: |
2551 | 2551 | ||
2552 | @table @code | 2552 | @table @code |
2553 | @item GCRYCTL_DISABLE_ALGO | 2553 | @item GCRYCTL_DISABLE_ALGO |
2554 | Disable the algorithm given as an algorithm id in @var{buffer}. | 2554 | Disable the algorithm given as an algorithm id in @var{buffer}. |
2555 | @var{buffer} must point to an @code{int} variable with the algorithm id | 2555 | @var{buffer} must point to an @code{int} variable with the algorithm id |
2556 | and @var{buflen} must have the value @code{sizeof (int)}. | 2556 | and @var{buflen} must have the value @code{sizeof (int)}. |
2557 | 2557 | ||
2558 | @end table | 2558 | @end table |
2559 | @end deftypefun | 2559 | @end deftypefun |
2560 | @c end gcry_pk_ctl | 2560 | @c end gcry_pk_ctl |
2561 | 2561 | ||
2562 | @noindent | 2562 | @noindent |
2563 | @acronym{Libgcrypt} also provides a function for generating public key | 2563 | @acronym{Libgcrypt} also provides a function for generating public key |
2564 | pairs: | 2564 | pairs: |
2565 | 2565 | ||
2566 | @deftypefun gcry_error_t gcry_pk_genkey (@w{gcry_sexp_t *@var{r_key}}, @w{gcry_sexp_t @var{parms}}) | 2566 | @deftypefun gcry_error_t gcry_pk_genkey (@w{gcry_sexp_t *@var{r_key}}, @w{gcry_sexp_t @var{parms}}) |
2567 | 2567 | ||
2568 | This function create a new public key pair using information given in | 2568 | This function create a new public key pair using information given in |
2569 | the S-expression @var{parms} and stores the private and the public key | 2569 | the S-expression @var{parms} and stores the private and the public key |
2570 | in one new S-expression at the address given by @var{r_key}. In case of | 2570 | in one new S-expression at the address given by @var{r_key}. In case of |
2571 | an error, @var{r_key} is set to @code{NULL}. The return code is 0 for | 2571 | an error, @var{r_key} is set to @code{NULL}. The return code is 0 for |
2572 | success or an error code otherwise. | 2572 | success or an error code otherwise. |
2573 | 2573 | ||
2574 | @noindent | 2574 | @noindent |
2575 | Here is an example for @var{parms} for creating a 1024 bit RSA key: | 2575 | Here is an example for @var{parms} for creating a 1024 bit RSA key: |
2576 | 2576 | ||
2577 | @example | 2577 | @example |
2578 | (genkey | 2578 | (genkey |
2579 | (rsa | 2579 | (rsa |
2580 | (nbits 4:1024))) | 2580 | (nbits 4:1024))) |
2581 | @end example | 2581 | @end example |
2582 | 2582 | ||
2583 | @noindent | 2583 | @noindent |
2584 | To create an ElGamal key, substitute "elg" for "rsa" and to create a DSA | 2584 | To create an ElGamal key, substitute "elg" for "rsa" and to create a DSA |
2585 | key use "dsa". Valid ranges for the key length depend on the | 2585 | key use "dsa". Valid ranges for the key length depend on the |
2586 | algorithms; all commonly used key lengths are supported. Currently | 2586 | algorithms; all commonly used key lengths are supported. Currently |
2587 | supported parameters are: | 2587 | supported parameters are: |
2588 | 2588 | ||
2589 | @table @code | 2589 | @table @code |
2590 | @item nbits | 2590 | @item nbits |
2591 | This is always required to specify the length of the key. The argument | 2591 | This is always required to specify the length of the key. The argument |
2592 | is a string with a number in C-notation. | 2592 | is a string with a number in C-notation. |
2593 | 2593 | ||
2594 | @item rsa-use-e | 2594 | @item rsa-use-e |
2595 | This is only used with RSA to give a hint for the public exponent. The | 2595 | This is only used with RSA to give a hint for the public exponent. The |
2596 | value will be used as a base to test for a usable exponent. Some values | 2596 | value will be used as a base to test for a usable exponent. Some values |
2597 | are special: | 2597 | are special: |
2598 | 2598 | ||
2599 | @table @samp | 2599 | @table @samp |
2600 | @item 0 | 2600 | @item 0 |
2601 | Use a secure and fast value. This is currently the number 41. | 2601 | Use a secure and fast value. This is currently the number 41. |
2602 | @item 1 | 2602 | @item 1 |
2603 | Use a secure value as required by some specification. This is currently | 2603 | Use a secure value as required by some specification. This is currently |
2604 | the number 65537. | 2604 | the number 65537. |
2605 | @item 2 | 2605 | @item 2 |
2606 | Reserved | 2606 | Reserved |
2607 | @end table | 2607 | @end table |
2608 | 2608 | ||
2609 | @noindent | 2609 | @noindent |
2610 | If this parameter is not used, @acronym{Libgcrypt} uses for historic reasons | 2610 | If this parameter is not used, @acronym{Libgcrypt} uses for historic reasons |
2611 | 65537. | 2611 | 65537. |
2612 | 2612 | ||
2613 | @end table | 2613 | @end table |
2614 | @c end table of parameters | 2614 | @c end table of parameters |
2615 | 2615 | ||
2616 | @noindent | 2616 | @noindent |
2617 | The key pair is returned in a format depending on the algorithm. Both | 2617 | The key pair is returned in a format depending on the algorithm. Both |
2618 | private and public keys are returned in one container and may be | 2618 | private and public keys are returned in one container and may be |
2619 | accompanied by some miscellaneous information. | 2619 | accompanied by some miscellaneous information. |
2620 | 2620 | ||
2621 | @noindent | 2621 | @noindent |
2622 | As an example, here is what the ElGamal key generation returns: | 2622 | As an example, here is what the ElGamal key generation returns: |
2623 | 2623 | ||
2624 | @example | 2624 | @example |
2625 | (key-data | 2625 | (key-data |
2626 | (public-key | 2626 | (public-key |
2627 | (elg | 2627 | (elg |
2628 | (p @var{p-mpi}) | 2628 | (p @var{p-mpi}) |
2629 | (g @var{g-mpi}) | 2629 | (g @var{g-mpi}) |
2630 | (y @var{y-mpi}))) | 2630 | (y @var{y-mpi}))) |
2631 | (private-key | 2631 | (private-key |
2632 | (elg | 2632 | (elg |
2633 | (p @var{p-mpi}) | 2633 | (p @var{p-mpi}) |
2634 | (g @var{g-mpi}) | 2634 | (g @var{g-mpi}) |
2635 | (y @var{y-mpi}) | 2635 | (y @var{y-mpi}) |
2636 | (x @var{x-mpi}))) | 2636 | (x @var{x-mpi}))) |
2637 | (misc-key-info | 2637 | (misc-key-info |
2638 | (pm1-factors @var{n1 n2 ... nn}))) | 2638 | (pm1-factors @var{n1 n2 ... nn}))) |
2639 | @end example | 2639 | @end example |
2640 | 2640 | ||
2641 | @noindent | 2641 | @noindent |
2642 | As you can see, some of the information is duplicated, but this provides | 2642 | As you can see, some of the information is duplicated, but this provides |
2643 | an easy way to extract either the public or the private key. Note that | 2643 | an easy way to extract either the public or the private key. Note that |
2644 | the order of the elements is not defined, e.g. the private key may be | 2644 | the order of the elements is not defined, e.g. the private key may be |
2645 | stored before the public key. @var{n1 n2 ... nn} is a list of prime | 2645 | stored before the public key. @var{n1 n2 ... nn} is a list of prime |
2646 | numbers used to composite @var{p-mpi}; this is in general not a very | 2646 | numbers used to composite @var{p-mpi}; this is in general not a very |
2647 | useful information. | 2647 | useful information. |
2648 | @end deftypefun | 2648 | @end deftypefun |
2649 | @c end gcry_pk_genkey | 2649 | @c end gcry_pk_genkey |
2650 | 2650 | ||
2651 | @node Public Key cryptography (II) | 2651 | @node Public Key cryptography (II) |
2652 | @chapter Public Key cryptography (II) | 2652 | @chapter Public Key cryptography (II) |
2653 | 2653 | ||
2654 | This chapter documents the alternative interface to asymmetric | 2654 | This chapter documents the alternative interface to asymmetric |
2655 | cryptography (ac) that is not based on S-expressions, but on native C | 2655 | cryptography (ac) that is not based on S-expressions, but on native C |
2656 | data structures. As opposed to the pk interface described in the | 2656 | data structures. As opposed to the pk interface described in the |
2657 | former chapter, this one follows an open/use/close paradigm like other | 2657 | former chapter, this one follows an open/use/close paradigm like other |
2658 | building blocks of the library. | 2658 | building blocks of the library. |
2659 | 2659 | ||
2660 | @menu | 2660 | @menu |
2661 | * Available asymmetric algorithms:: List of algorithms supported by the library. | 2661 | * Available asymmetric algorithms:: List of algorithms supported by the library. |
2662 | * Working with sets of data:: How to work with sets of data. | 2662 | * Working with sets of data:: How to work with sets of data. |
2663 | * Working with handles:: How to use handles. | 2663 | * Working with handles:: How to use handles. |
2664 | * Working with keys:: How to work with keys. | 2664 | * Working with keys:: How to work with keys. |
2665 | * Using cryptographic functions:: How to perform cryptographic operations. | 2665 | * Using cryptographic functions:: How to perform cryptographic operations. |
2666 | * Handle-independent functions:: General functions independent of handles. | 2666 | * Handle-independent functions:: General functions independent of handles. |
2667 | @end menu | 2667 | @end menu |
2668 | 2668 | ||
2669 | @node Available asymmetric algorithms | 2669 | @node Available asymmetric algorithms |
2670 | @section Available asymmetric algorithms | 2670 | @section Available asymmetric algorithms |
2671 | 2671 | ||
2672 | @acronym{Libgcrypt} supports the RSA (Rivest-Shamir-Adleman) | 2672 | @acronym{Libgcrypt} supports the RSA (Rivest-Shamir-Adleman) |
2673 | algorithms as well as DSA (Digital Signature Algorithm) and ElGamal. | 2673 | algorithms as well as DSA (Digital Signature Algorithm) and ElGamal. |
2674 | The versatile interface allows to add more algorithms in the future. | 2674 | The versatile interface allows to add more algorithms in the future. |
2675 | 2675 | ||
2676 | @deftp {Data type} gcry_ac_id_t | 2676 | @deftp {Data type} gcry_ac_id_t |
2677 | 2677 | ||
2678 | The following constants are defined for this type: | 2678 | The following constants are defined for this type: |
2679 | 2679 | ||
2680 | @table @code | 2680 | @table @code |
2681 | @item GCRY_AC_RSA | 2681 | @item GCRY_AC_RSA |
2682 | Riven-Shamir-Adleman | 2682 | Riven-Shamir-Adleman |
2683 | @item GCRY_AC_DSA | 2683 | @item GCRY_AC_DSA |
2684 | Digital Signature Algorithm | 2684 | Digital Signature Algorithm |
2685 | @item GCRY_AC_ELG | 2685 | @item GCRY_AC_ELG |
2686 | ElGamal | 2686 | ElGamal |
2687 | @item GCRY_AC_ELG_E | 2687 | @item GCRY_AC_ELG_E |
2688 | ElGamal, encryption only. | 2688 | ElGamal, encryption only. |
2689 | @end table | 2689 | @end table |
2690 | @end deftp | 2690 | @end deftp |
2691 | 2691 | ||
2692 | @node Working with sets of data | 2692 | @node Working with sets of data |
2693 | @section Working with sets of data | 2693 | @section Working with sets of data |
2694 | 2694 | ||
2695 | In the context of this interface the term `data set' refers to a list | 2695 | In the context of this interface the term `data set' refers to a list |
2696 | of `named MPI values' that is used by functions performing | 2696 | of `named MPI values' that is used by functions performing |
2697 | cryptographic operations. | 2697 | cryptographic operations. |
2698 | 2698 | ||
2699 | Such data sets are used for representing keys, since keys simply | 2699 | Such data sets are used for representing keys, since keys simply |
2700 | consist of a variable amount of numbers. Furthermore some functions | 2700 | consist of a variable amount of numbers. Furthermore some functions |
2701 | return data sets to the caller that are to be provided to other | 2701 | return data sets to the caller that are to be provided to other |
2702 | functions. | 2702 | functions. |
2703 | 2703 | ||
2704 | This section documents the data types, symbols and functions that are | 2704 | This section documents the data types, symbols and functions that are |
2705 | relevant for working with such data sets. | 2705 | relevant for working with such data sets. |
2706 | 2706 | ||
2707 | @deftp {Data type} gcry_ac_data_t | 2707 | @deftp {Data type} gcry_ac_data_t |
2708 | A data set, that is simply a list of named MPI values. | 2708 | A data set, that is simply a list of named MPI values. |
2709 | @end deftp | 2709 | @end deftp |
2710 | 2710 | ||
2711 | The following flags are supported: | 2711 | The following flags are supported: |
2712 | 2712 | ||
2713 | @table @code | 2713 | @table @code |
2714 | @item GCRY_AC_FLAG_DEALLOC | 2714 | @item GCRY_AC_FLAG_DEALLOC |
2715 | Used for storing data in a data set. If given, the data will be | 2715 | Used for storing data in a data set. If given, the data will be |
2716 | released by the library. | 2716 | released by the library. |
2717 | 2717 | ||
2718 | @item GCRY_AC_FLAG_COPY | 2718 | @item GCRY_AC_FLAG_COPY |
2719 | Used for storing/retrieving data in/from a data set. If given, the | 2719 | Used for storing/retrieving data in/from a data set. If given, the |
2720 | library will create copies of the provided/contained data, which will | 2720 | library will create copies of the provided/contained data, which will |
2721 | then be given to the user/associated with the data set. | 2721 | then be given to the user/associated with the data set. |
2722 | @end table | 2722 | @end table |
2723 | 2723 | ||
2724 | @deftypefun gcry_error_t gcry_ac_data_new (gcry_ac_data_t *@var{data}) | 2724 | @deftypefun gcry_error_t gcry_ac_data_new (gcry_ac_data_t *@var{data}) |
2725 | Creates a new, empty data set and stores it in @var{data}. | 2725 | Creates a new, empty data set and stores it in @var{data}. |
2726 | @end deftypefun | 2726 | @end deftypefun |
2727 | 2727 | ||
2728 | @deftypefun void gcry_ac_data_destroy (gcry_ac_data_t @var{data}) | 2728 | @deftypefun void gcry_ac_data_destroy (gcry_ac_data_t @var{data}) |
2729 | Destroys the data set @var{data}. | 2729 | Destroys the data set @var{data}. |
2730 | @end deftypefun | 2730 | @end deftypefun |
2731 | 2731 | ||
2732 | @deftypefun gcry_error_t gcry_ac_data_set (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t @var{mpi}) | 2732 | @deftypefun gcry_error_t gcry_ac_data_set (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t @var{mpi}) |
2733 | Add the value @var{mpi} to @var{data} with the label @var{name}. If | 2733 | Add the value @var{mpi} to @var{data} with the label @var{name}. If |
2734 | @var{flags} contains GCRY_AC_FLAG_DATA_COPY, the data set will contain | 2734 | @var{flags} contains GCRY_AC_FLAG_DATA_COPY, the data set will contain |
2735 | copies of @var{name} and @var{mpi}. If @var{flags} contains | 2735 | copies of @var{name} and @var{mpi}. If @var{flags} contains |
2736 | GCRY_AC_FLAG_DATA_DEALLOC or GCRY_AC_FLAG_DATA_COPY, the values | 2736 | GCRY_AC_FLAG_DATA_DEALLOC or GCRY_AC_FLAG_DATA_COPY, the values |
2737 | contained in the data set will be deallocated when they are to be | 2737 | contained in the data set will be deallocated when they are to be |
2738 | removed from the data set. | 2738 | removed from the data set. |
2739 | @end deftypefun | 2739 | @end deftypefun |
2740 | 2740 | ||
2741 | @deftypefun gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *@var{data_cp}, gcry_ac_data_t @var{data}) | 2741 | @deftypefun gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *@var{data_cp}, gcry_ac_data_t @var{data}) |
2742 | Create a copy of the data set @var{data} and store it in @var{data_cp}. | 2742 | Create a copy of the data set @var{data} and store it in @var{data_cp}. |
2743 | @end deftypefun | 2743 | @end deftypefun |
2744 | 2744 | ||
2745 | @deftypefun unsigned int gcry_ac_data_length (gcry_ac_data_t @var{data}) | 2745 | @deftypefun unsigned int gcry_ac_data_length (gcry_ac_data_t @var{data}) |
2746 | Returns the number of named MPI values inside of the data set | 2746 | Returns the number of named MPI values inside of the data set |
2747 | @var{data}. | 2747 | @var{data}. |
2748 | @end deftypefun | 2748 | @end deftypefun |
2749 | 2749 | ||
2750 | @deftypefun gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t *@var{mpi}) | 2750 | @deftypefun gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t *@var{mpi}) |
2751 | Store the value labelled with @var{name} found in @var{data} in | 2751 | Store the value labelled with @var{name} found in @var{data} in |
2752 | @var{mpi}. If @var{flags} contains GCRY_AC_FLAG_COPY, store a copy of | 2752 | @var{mpi}. If @var{flags} contains GCRY_AC_FLAG_COPY, store a copy of |
2753 | the @var{mpi} value contained in the data set. @var{mpi} may be NULL. | 2753 | the @var{mpi} value contained in the data set. @var{mpi} may be NULL. |
2754 | @end deftypefun | 2754 | @end deftypefun |
2755 | 2755 | ||
2756 | @deftypefun gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t @var{data}, unsigned int flags, unsigned int @var{index}, const char **@var{name}, gcry_mpi_t *@var{mpi}) | 2756 | @deftypefun gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t @var{data}, unsigned int flags, unsigned int @var{index}, const char **@var{name}, gcry_mpi_t *@var{mpi}) |
2757 | Stores in @var{name} and @var{mpi} the named @var{mpi} value contained | 2757 | Stores in @var{name} and @var{mpi} the named @var{mpi} value contained |
2758 | in the data set @var{data} with the index @var{idx}. If @var{flags} | 2758 | in the data set @var{data} with the index @var{idx}. If @var{flags} |
2759 | contains GCRY_AC_FLAG_COPY, store copies of the values contained in | 2759 | contains GCRY_AC_FLAG_COPY, store copies of the values contained in |
2760 | the data set. @var{name} or @var{mpi} may be NULL. | 2760 | the data set. @var{name} or @var{mpi} may be NULL. |
2761 | @end deftypefun | 2761 | @end deftypefun |
2762 | 2762 | ||
2763 | @deftypefun void gcry_ac_data_clear (gcry_ac_data_t @var{data}) | 2763 | @deftypefun void gcry_ac_data_clear (gcry_ac_data_t @var{data}) |
2764 | Destroys any values contained in the data set @var{data}. | 2764 | Destroys any values contained in the data set @var{data}. |
2765 | @end deftypefun | 2765 | @end deftypefun |
2766 | 2766 | ||
2767 | @node Working with handles | 2767 | @node Working with handles |
2768 | @section Working with handles | 2768 | @section Working with handles |
2769 | 2769 | ||
2770 | In order to use an algorithm, an according handle must be created. | 2770 | In order to use an algorithm, an according handle must be created. |
2771 | This is done using the following function: | 2771 | This is done using the following function: |
2772 | 2772 | ||
2773 | @deftypefun gcry_error_t gcry_ac_open (gcry_ac_handle_t *@var{handle}, int @var{algorithm}, int @var{flags}) | 2773 | @deftypefun gcry_error_t gcry_ac_open (gcry_ac_handle_t *@var{handle}, int @var{algorithm}, int @var{flags}) |
2774 | 2774 | ||
2775 | Creates a new handle for the algorithm @var{algorithm} and stores it | 2775 | Creates a new handle for the algorithm @var{algorithm} and stores it |
2776 | in @var{handle}. @var{flags} is not used yet. | 2776 | in @var{handle}. @var{flags} is not used yet. |
2777 | 2777 | ||
2778 | @var{algorithm} must be a valid algorithm ID, see @xref{Available | 2778 | @var{algorithm} must be a valid algorithm ID, see @xref{Available |
2779 | algorithms}, for a list of supported algorithms and the according | 2779 | algorithms}, for a list of supported algorithms and the according |
2780 | constants. Besides using the listed constants directly, the functions | 2780 | constants. Besides using the listed constants directly, the functions |
2781 | @code{gcry_ac_name_to_id} may be used to convert the textual name of | 2781 | @code{gcry_ac_name_to_id} may be used to convert the textual name of |
2782 | an algorithm into the according numeric ID. | 2782 | an algorithm into the according numeric ID. |
2783 | @end deftypefun | 2783 | @end deftypefun |
2784 | 2784 | ||
2785 | @deftypefun void gcry_ac_close (gcry_ac_handle_t @var{handle}) | 2785 | @deftypefun void gcry_ac_close (gcry_ac_handle_t @var{handle}) |
2786 | Destroys the handle @var{handle}. | 2786 | Destroys the handle @var{handle}. |
2787 | @end deftypefun | 2787 | @end deftypefun |
2788 | 2788 | ||
2789 | @node Working with keys | 2789 | @node Working with keys |
2790 | @section Working with keys | 2790 | @section Working with keys |
2791 | 2791 | ||
2792 | @deftp {Data type} gcry_ac_key_type_t | 2792 | @deftp {Data type} gcry_ac_key_type_t |
2793 | Defined constants: | 2793 | Defined constants: |
2794 | 2794 | ||
2795 | @table @code | 2795 | @table @code |
2796 | @item GCRY_AC_KEY_TYPE_SECRET | 2796 | @item GCRY_AC_KEY_TYPE_SECRET |
2797 | Specifies a secret key. | 2797 | Specifies a secret key. |
2798 | @item GCRY_AC_KEY_TYPE_PUBLIC | 2798 | @item GCRY_AC_KEY_TYPE_PUBLIC |
2799 | Specifies a public key. | 2799 | Specifies a public key. |
2800 | @end table | 2800 | @end table |
2801 | @end deftp | 2801 | @end deftp |
2802 | 2802 | ||
2803 | @deftp {Data type} gcry_ac_key_t | 2803 | @deftp {Data type} gcry_ac_key_t |
2804 | This type represents a single `key', either a secret one or a public | 2804 | This type represents a single `key', either a secret one or a public |
2805 | one. | 2805 | one. |
2806 | @end deftp | 2806 | @end deftp |
2807 | 2807 | ||
2808 | @deftp {Data type} gcry_ac_key_pair_t | 2808 | @deftp {Data type} gcry_ac_key_pair_t |
2809 | This type represents a `key pair' containing a secret and a public key. | 2809 | This type represents a `key pair' containing a secret and a public key. |
2810 | @end deftp | 2810 | @end deftp |
2811 | 2811 | ||
2812 | Key data structures can be created in two different ways; a new key | 2812 | Key data structures can be created in two different ways; a new key |
2813 | pair can be generated, resulting in ready-to-use key. Alternatively a | 2813 | pair can be generated, resulting in ready-to-use key. Alternatively a |
2814 | key can be initialized from a given data set. | 2814 | key can be initialized from a given data set. |
2815 | 2815 | ||
2816 | @deftypefun gcry_error_t gcry_ac_key_init (gcry_ac_key_t *@var{key}, gcry_ac_handle_t @var{handle}, gcry_ac_key_type_t @var{type}, gcry_ac_data_t @var{data}) | 2816 | @deftypefun gcry_error_t gcry_ac_key_init (gcry_ac_key_t *@var{key}, gcry_ac_handle_t @var{handle}, gcry_ac_key_type_t @var{type}, gcry_ac_data_t @var{data}) |
2817 | Creates a new key of type @var{type}, consisting of the MPI values | 2817 | Creates a new key of type @var{type}, consisting of the MPI values |
2818 | contained in the data set @var{data} and stores it in @var{key}. | 2818 | contained in the data set @var{data} and stores it in @var{key}. |
2819 | @end deftypefun | 2819 | @end deftypefun |
2820 | 2820 | ||
2821 | @deftypefun gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t @var{handle}, unsigned int @var{nbits}, void *@var{key_spec}, gcry_ac_key_pair_t *@var{key_pair}, gcry_mpi_t **@var{misc_data}) | 2821 | @deftypefun gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t @var{handle}, unsigned int @var{nbits}, void *@var{key_spec}, gcry_ac_key_pair_t *@var{key_pair}, gcry_mpi_t **@var{misc_data}) |
2822 | 2822 | ||
2823 | Generates a new key pair via the handle @var{handle} of @var{NBITS} | 2823 | Generates a new key pair via the handle @var{handle} of @var{NBITS} |
2824 | bits and stores it in @var{key_pair}. | 2824 | bits and stores it in @var{key_pair}. |
2825 | 2825 | ||
2826 | In case non-standard settings are wanted, a pointer to a structure of | 2826 | In case non-standard settings are wanted, a pointer to a structure of |
2827 | type @code{gcry_ac_key_spec_<algorithm>_t}, matching the selected | 2827 | type @code{gcry_ac_key_spec_<algorithm>_t}, matching the selected |
2828 | algorithm, can be given as @var{key_spec}. @var{misc_data} is not | 2828 | algorithm, can be given as @var{key_spec}. @var{misc_data} is not |
2829 | used yet. Such a structure does only exist for RSA. A descriptions | 2829 | used yet. Such a structure does only exist for RSA. A descriptions |
2830 | of the members of the supported structures follows. | 2830 | of the members of the supported structures follows. |
2831 | 2831 | ||
2832 | @table @code | 2832 | @table @code |
2833 | @item gcry_ac_key_spec_rsa_t | 2833 | @item gcry_ac_key_spec_rsa_t |
2834 | @table @code | 2834 | @table @code |
2835 | @item gcry_mpi_t e | 2835 | @item gcry_mpi_t e |
2836 | Generate the key pair using a special @code{e}. The value of @code{e} | 2836 | Generate the key pair using a special @code{e}. The value of @code{e} |
2837 | has the following meanings: | 2837 | has the following meanings: |
2838 | @table @code | 2838 | @table @code |
2839 | @item = 0 | 2839 | @item = 0 |
2840 | Let @acronym{Libgcrypt} device what exponent should be used. | 2840 | Let @acronym{Libgcrypt} device what exponent should be used. |
2841 | @item = 1 | 2841 | @item = 1 |
2842 | Request the use of a ``secure'' exponent; this is required by some | 2842 | Request the use of a ``secure'' exponent; this is required by some |
2843 | specification to be 65537. | 2843 | specification to be 65537. |
2844 | @item > 2 | 2844 | @item > 2 |
2845 | Try starting at this value until a working exponent is found. Note, | 2845 | Try starting at this value until a working exponent is found. Note, |
2846 | that the current implementation leaks some information about the | 2846 | that the current implementation leaks some information about the |
2847 | private key because the incrementation used is not randomized. Thus, | 2847 | private key because the incrementation used is not randomized. Thus, |
2848 | this function will be changed in the future to return a random | 2848 | this function will be changed in the future to return a random |
2849 | exponent of the given size. | 2849 | exponent of the given size. |
2850 | @end table | 2850 | @end table |
2851 | @end table | 2851 | @end table |
2852 | @end table | 2852 | @end table |
2853 | 2853 | ||
2854 | Example code: | 2854 | Example code: |
2855 | @example | 2855 | @example |
2856 | @{ | 2856 | @{ |
2857 | gcry_ac_key_pair_t key_pair; | 2857 | gcry_ac_key_pair_t key_pair; |
2858 | gcry_ac_key_spec_rsa rsa_spec; | 2858 | gcry_ac_key_spec_rsa rsa_spec; |
2859 | 2859 | ||
2860 | rsa_spec.e = gcry_mpi_new (0); | 2860 | rsa_spec.e = gcry_mpi_new (0); |
2861 | gcry_mpi_set_ui (rsa_spec.e, 1) | 2861 | gcry_mpi_set_ui (rsa_spec.e, 1) |
2862 | 2862 | ||
2863 | err = gcry_ac_open (&handle, GCRY_AC_RSA, 0); | 2863 | err = gcry_ac_open (&handle, GCRY_AC_RSA, 0); |
2864 | assert (! err); | 2864 | assert (! err); |
2865 | 2865 | ||
2866 | err = gcry_ac_key_pair_generate (handle, &key_pair, 1024, (void *) &rsa_spec); | 2866 | err = gcry_ac_key_pair_generate (handle, &key_pair, 1024, (void *) &rsa_spec); |
2867 | assert (! err); | 2867 | assert (! err); |
2868 | @} | 2868 | @} |
2869 | @end example | 2869 | @end example |
2870 | @end deftypefun | 2870 | @end deftypefun |
2871 | 2871 | ||
2872 | 2872 | ||
2873 | @deftypefun gcry_ac_key_t gcry_ac_key_pair_extract (gcry_ac_key_pair_t @var{key_pair}, gcry_ac_key_type_t @var{which}) | 2873 | @deftypefun gcry_ac_key_t gcry_ac_key_pair_extract (gcry_ac_key_pair_t @var{key_pair}, gcry_ac_key_type_t @var{which}) |
2874 | Returns the key of type @var{which} out of the key pair | 2874 | Returns the key of type @var{which} out of the key pair |
2875 | @var{key_pair}. | 2875 | @var{key_pair}. |
2876 | @end deftypefun | 2876 | @end deftypefun |
2877 | 2877 | ||
2878 | @deftypefun void gcry_ac_key_destroy (gcry_ac_key_t @var{key}) | 2878 | @deftypefun void gcry_ac_key_destroy (gcry_ac_key_t @var{key}) |
2879 | Destroys the key @var{key}. | 2879 | Destroys the key @var{key}. |
2880 | @end deftypefun | 2880 | @end deftypefun |
2881 | 2881 | ||
2882 | @deftypefun void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t @var{key_pair}) | 2882 | @deftypefun void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t @var{key_pair}) |
2883 | Destroys the key pair @var{key_pair}. | 2883 | Destroys the key pair @var{key_pair}. |
2884 | @end deftypefun | 2884 | @end deftypefun |
2885 | 2885 | ||
2886 | @deftypefun gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t @var{key}) | 2886 | @deftypefun gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t @var{key}) |
2887 | Returns the data set contained in the key @var{key}. | 2887 | Returns the data set contained in the key @var{key}. |
2888 | @end deftypefun | 2888 | @end deftypefun |
2889 | 2889 | ||
2890 | @deftypefun gcry_error_t gcry_ac_key_test (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}) | 2890 | @deftypefun gcry_error_t gcry_ac_key_test (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}) |
2891 | Verifies that the private key @var{key} is sane via @var{handle}. | 2891 | Verifies that the private key @var{key} is sane via @var{handle}. |
2892 | @end deftypefun | 2892 | @end deftypefun |
2893 | 2893 | ||
2894 | @deftypefun gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned int *@var{nbits}) | 2894 | @deftypefun gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned int *@var{nbits}) |
2895 | Stores the number of bits of the key @var{key} in @var{nbits} via @var{handle}. | 2895 | Stores the number of bits of the key @var{key} in @var{nbits} via @var{handle}. |
2896 | @end deftypefun | 2896 | @end deftypefun |
2897 | 2897 | ||
2898 | @deftypefun gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned char *@var{key_grip}) | 2898 | @deftypefun gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned char *@var{key_grip}) |
2899 | Writes the 20 byte long key grip of the key @var{key} to | 2899 | Writes the 20 byte long key grip of the key @var{key} to |
2900 | @var{key_grip} via @var{handle}. | 2900 | @var{key_grip} via @var{handle}. |
2901 | @end deftypefun | 2901 | @end deftypefun |
2902 | 2902 | ||
2903 | @node Using cryptographic functions | 2903 | @node Using cryptographic functions |
2904 | @section Using cryptographic functions | 2904 | @section Using cryptographic functions |
2905 | 2905 | ||
2906 | The following flags might be relevant: | 2906 | The following flags might be relevant: |
2907 | 2907 | ||
2908 | @table @code | 2908 | @table @code |
2909 | @item GCRY_AC_FLAG_NO_BLINDING | 2909 | @item GCRY_AC_FLAG_NO_BLINDING |
2910 | Disable any blinding, which might be supported by the chosen | 2910 | Disable any blinding, which might be supported by the chosen |
2911 | algorithm; blinding is the default. | 2911 | algorithm; blinding is the default. |
2912 | @end table | 2912 | @end table |
2913 | 2913 | ||
2914 | @deftypefun gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t @var{handle}, unsigned int @var{flags}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data_plain}, gcry_ac_data_t **@var{data_encrypted}) | 2914 | @deftypefun gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t @var{handle}, unsigned int @var{flags}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data_plain}, gcry_ac_data_t **@var{data_encrypted}) |
2915 | Encrypts the plain text MPI value @var{data_plain} with the key public | 2915 | Encrypts the plain text MPI value @var{data_plain} with the key public |
2916 | @var{key} under the control of the flags @var{flags} and stores the | 2916 | @var{key} under the control of the flags @var{flags} and stores the |
2917 | resulting data set into @var{data_encrypted}. | 2917 | resulting data set into @var{data_encrypted}. |
2918 | @end deftypefun | 2918 | @end deftypefun |
2919 | 2919 | ||
2920 | @deftypefun gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t @var{handle}, unsigned int @var{flags}, gcry_ac_key_t @var{key}, gcry_mpi_t *@var{data_plain}, gcry_ac_data_t @var{data_encrypted}) | 2920 | @deftypefun gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t @var{handle}, unsigned int @var{flags}, gcry_ac_key_t @var{key}, gcry_mpi_t *@var{data_plain}, gcry_ac_data_t @var{data_encrypted}) |
2921 | Decrypts the encrypted data contained in the data set | 2921 | Decrypts the encrypted data contained in the data set |
2922 | @var{data_encrypted} with the secret key KEY under the control of the | 2922 | @var{data_encrypted} with the secret key KEY under the control of the |
2923 | flags @var{flags} and stores the resulting plain text MPI value in | 2923 | flags @var{flags} and stores the resulting plain text MPI value in |
2924 | @var{DATA_PLAIN}. | 2924 | @var{DATA_PLAIN}. |
2925 | @end deftypefun | 2925 | @end deftypefun |
2926 | 2926 | ||
2927 | @deftypefun gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data}, gcry_ac_data_t *@var{data_signature}) | 2927 | @deftypefun gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data}, gcry_ac_data_t *@var{data_signature}) |
2928 | Signs the data contained in @var{data} with the secret key @var{key} | 2928 | Signs the data contained in @var{data} with the secret key @var{key} |
2929 | and stores the resulting signature in the data set | 2929 | and stores the resulting signature in the data set |
2930 | @var{data_signature}. | 2930 | @var{data_signature}. |
2931 | @end deftypefun | 2931 | @end deftypefun |
2932 | 2932 | ||
2933 | @deftypefun gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data}, gcry_ac_data_t @var{data_signature}) | 2933 | @deftypefun gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, gcry_mpi_t @var{data}, gcry_ac_data_t @var{data_signature}) |
2934 | Verifies that the signature contained in the data set | 2934 | Verifies that the signature contained in the data set |
2935 | @var{data_signature} is indeed the result of signing the data | 2935 | @var{data_signature} is indeed the result of signing the data |
2936 | contained in @var{data} with the secret key belonging to the public | 2936 | contained in @var{data} with the secret key belonging to the public |
2937 | key @var{key}. | 2937 | key @var{key}. |
2938 | @end deftypefun | 2938 | @end deftypefun |
2939 | 2939 | ||
2940 | @node Handle-independent functions | 2940 | @node Handle-independent functions |
2941 | @section Handle-independent functions | 2941 | @section Handle-independent functions |
2942 | 2942 | ||
2943 | @deftypefun gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t @var{algorithm}, const char **@var{name}) | 2943 | @deftypefun gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t @var{algorithm}, const char **@var{name}) |
2944 | Stores the textual representation of the algorithm whose id is given | 2944 | Stores the textual representation of the algorithm whose id is given |
2945 | in @var{algorithm} in @var{name}. | 2945 | in @var{algorithm} in @var{name}. |
2946 | @end deftypefun | 2946 | @end deftypefun |
2947 | 2947 | ||
2948 | @deftypefun gcry_error_t gcry_ac_name_to_id (const char *@var{name}, gcry_ac_id_t *@var{algorithm}) | 2948 | @deftypefun gcry_error_t gcry_ac_name_to_id (const char *@var{name}, gcry_ac_id_t *@var{algorithm}) |
2949 | Stores the numeric ID of the algorithm whose textual representation is | 2949 | Stores the numeric ID of the algorithm whose textual representation is |
2950 | contained in @var{name} in @var{algorithm}. | 2950 | contained in @var{name} in @var{algorithm}. |
2951 | @end deftypefun | 2951 | @end deftypefun |
2952 | 2952 | ||
2953 | @c ********************************************************** | 2953 | @c ********************************************************** |
2954 | @c ******************* Random ***************************** | 2954 | @c ******************* Random ***************************** |
2955 | @c ********************************************************** | 2955 | @c ********************************************************** |
2956 | @node Random Numbers | 2956 | @node Random Numbers |
2957 | @chapter Random Numbers | 2957 | @chapter Random Numbers |
2958 | 2958 | ||
2959 | @menu | 2959 | @menu |
2960 | * Quality of random numbers:: @acronym{Libgcrypt} uses different quality levels. | 2960 | * Quality of random numbers:: @acronym{Libgcrypt} uses different quality levels. |
2961 | * Retrieving random numbers:: How to retrieve random numbers. | 2961 | * Retrieving random numbers:: How to retrieve random numbers. |
2962 | @end menu | 2962 | @end menu |
2963 | 2963 | ||
2964 | @node Quality of random numbers | 2964 | @node Quality of random numbers |
2965 | @section Quality of random numbers | 2965 | @section Quality of random numbers |
2966 | 2966 | ||
2967 | @acronym{Libgcypt} offers random numbers of different quality levels: | 2967 | @acronym{Libgcypt} offers random numbers of different quality levels: |
2968 | 2968 | ||
2969 | @deftp {Data type} enum gcry_random_level | 2969 | @deftp {Data type} enum gcry_random_level |
2970 | The constants for the random quality levels are of this type. | 2970 | The constants for the random quality levels are of this type. |
2971 | @end deftp | 2971 | @end deftp |
2972 | 2972 | ||
2973 | @table @code | 2973 | @table @code |
2974 | @item GCRY_WEAK_RANDOM | 2974 | @item GCRY_WEAK_RANDOM |
2975 | This should not anymore be used. It has recently been changed to an | 2975 | This should not anymore be used. It has recently been changed to an |
2976 | alias of GCRY_STRONG_RANDOM. Use @code{gcry_create_nonce} instead. | 2976 | alias of GCRY_STRONG_RANDOM. Use @code{gcry_create_nonce} instead. |
2977 | @item GCRY_STRONG_RANDOM | 2977 | @item GCRY_STRONG_RANDOM |
2978 | Use this level for e.g. session keys and similar purposes. | 2978 | Use this level for e.g. session keys and similar purposes. |
2979 | @item GCRY_VERY_STRONG_RANDOM | 2979 | @item GCRY_VERY_STRONG_RANDOM |
2980 | Use this level for e.g. key material. | 2980 | Use this level for e.g. key material. |
2981 | @end table | 2981 | @end table |
2982 | 2982 | ||
2983 | @node Retrieving random numbers | 2983 | @node Retrieving random numbers |
2984 | @section Retrieving random numbers | 2984 | @section Retrieving random numbers |
2985 | 2985 | ||
2986 | @deftypefun void gcry_randomize (unsigned char *@var{buffer}, size_t @var{length}, enum gcry_random_level @var{level}) | 2986 | @deftypefun void gcry_randomize (unsigned char *@var{buffer}, size_t @var{length}, enum gcry_random_level @var{level}) |
2987 | 2987 | ||
2988 | Fill @var{buffer} with @var{length} random bytes using a random quality | 2988 | Fill @var{buffer} with @var{length} random bytes using a random quality |
2989 | as defined by @var{level}. | 2989 | as defined by @var{level}. |
2990 | @end deftypefun | 2990 | @end deftypefun |
2991 | 2991 | ||
2992 | @deftypefun void * gcry_random_bytes (size_t @var{nbytes}, enum gcry_random_level @var{level}) | 2992 | @deftypefun void * gcry_random_bytes (size_t @var{nbytes}, enum gcry_random_level @var{level}) |
2993 | 2993 | ||
2994 | Allocate a memory block consisting of @var{nbytes} fresh random bytes | 2994 | Allocate a memory block consisting of @var{nbytes} fresh random bytes |
2995 | using a random quality as defined by @var{level}. | 2995 | using a random quality as defined by @var{level}. |
2996 | @end deftypefun | 2996 | @end deftypefun |
2997 | 2997 | ||
2998 | @deftypefun void * gcry_random_bytes_secure (size_t @var{nbytes}, enum gcry_random_level @var{level}) | 2998 | @deftypefun void * gcry_random_bytes_secure (size_t @var{nbytes}, enum gcry_random_level @var{level}) |
2999 | 2999 | ||
3000 | Allocate a memory block consisting of @var{nbytes} fresh random bytes | 3000 | Allocate a memory block consisting of @var{nbytes} fresh random bytes |
3001 | using a random quality as defined by @var{level}. This function | 3001 | using a random quality as defined by @var{level}. This function |
3002 | differs from @code{gcry_random_bytes} in that the returned buffer is | 3002 | differs from @code{gcry_random_bytes} in that the returned buffer is |
3003 | allocated in a ``secure'' area of the memory. | 3003 | allocated in a ``secure'' area of the memory. |
3004 | @end deftypefun | 3004 | @end deftypefun |
3005 | 3005 | ||
3006 | @deftypefun void gcry_create_nonce (void *@var{buffer}, size_t @var{length}) | 3006 | @deftypefun void gcry_create_nonce (void *@var{buffer}, size_t @var{length}) |
3007 | 3007 | ||
3008 | Fill @var{buffer} with @var{length} unpredictable bytes. This is | 3008 | Fill @var{buffer} with @var{length} unpredictable bytes. This is |
3009 | commonly called a nonce and may also be used for initialization | 3009 | commonly called a nonce and may also be used for initialization |
3010 | vectors and padding. This is an extra function nearly independent of | 3010 | vectors and padding. This is an extra function nearly independent of |
3011 | the other random function for 3 reasons: It better protects the | 3011 | the other random function for 3 reasons: It better protects the |
3012 | regular random generator's internal state, provides better performance | 3012 | regular random generator's internal state, provides better performance |
3013 | and does not drain the precious entropy pool. | 3013 | and does not drain the precious entropy pool. |
3014 | 3014 | ||
3015 | @end deftypefun | 3015 | @end deftypefun |
3016 | 3016 | ||
3017 | 3017 | ||
3018 | 3018 | ||
3019 | @c ********************************************************** | 3019 | @c ********************************************************** |
3020 | @c ******************* S-Expressions *********************** | 3020 | @c ******************* S-Expressions *********************** |
3021 | @c ********************************************************** | 3021 | @c ********************************************************** |
3022 | @node S-expressions | 3022 | @node S-expressions |
3023 | @chapter S-expressions | 3023 | @chapter S-expressions |
3024 | 3024 | ||
3025 | S-expressions are used by the public key functions to pass complex data | 3025 | S-expressions are used by the public key functions to pass complex data |
3026 | structures around. These LISP like objects are used by some | 3026 | structures around. These LISP like objects are used by some |
3027 | cryptographic protocols (cf. RFC-2692) and @acronym{Libgcrypt} provides functions | 3027 | cryptographic protocols (cf. RFC-2692) and @acronym{Libgcrypt} provides functions |
3028 | to parse and construct them. For detailed information, see | 3028 | to parse and construct them. For detailed information, see |
3029 | @cite{Ron Rivest, code and description of S-expressions, | 3029 | @cite{Ron Rivest, code and description of S-expressions, |
3030 | @uref{http://theory.lcs.mit.edu/~rivest/sexp.html}}. | 3030 | @uref{http://theory.lcs.mit.edu/~rivest/sexp.html}}. |
3031 | 3031 | ||
3032 | @menu | 3032 | @menu |
3033 | * Data types for S-expressions:: Data types related with S-expressions. | 3033 | * Data types for S-expressions:: Data types related with S-expressions. |
3034 | * Working with S-expressions:: How to work with S-expressions. | 3034 | * Working with S-expressions:: How to work with S-expressions. |
3035 | @end menu | 3035 | @end menu |
3036 | 3036 | ||
3037 | @node Data types for S-expressions | 3037 | @node Data types for S-expressions |
3038 | @section Data types for S-expressions | 3038 | @section Data types for S-expressions |
3039 | 3039 | ||
3040 | @deftp {Data type} gcry_sexp_t | 3040 | @deftp {Data type} gcry_sexp_t |
3041 | The @code{gcry_sexp_t} type describes an object with the @acronym{Libgcrypt} internal | 3041 | The @code{gcry_sexp_t} type describes an object with the @acronym{Libgcrypt} internal |
3042 | representation of an S-expression. | 3042 | representation of an S-expression. |
3043 | @end deftp | 3043 | @end deftp |
3044 | 3044 | ||
3045 | @node Working with S-expressions | 3045 | @node Working with S-expressions |
3046 | @section Working with S-expressions | 3046 | @section Working with S-expressions |
3047 | 3047 | ||
3048 | @noindent | 3048 | @noindent |
3049 | There are several functions to create an @acronym{Libgcrypt} S-expression object | 3049 | There are several functions to create an @acronym{Libgcrypt} S-expression object |
3050 | from its external representation or from a string template. There is | 3050 | from its external representation or from a string template. There is |
3051 | also a function to convert the internal representation back into one of | 3051 | also a function to convert the internal representation back into one of |
3052 | the external formats: | 3052 | the external formats: |
3053 | 3053 | ||
3054 | 3054 | ||
3055 | @deftypefun gcry_error_t gcry_sexp_new (@w{gcry_sexp_t *@var{r_sexp}}, @w{const void *@var{buffer}}, @w{size_t @var{length}}, @w{int @var{autodetect}}) | 3055 | @deftypefun gcry_error_t gcry_sexp_new (@w{gcry_sexp_t *@var{r_sexp}}, @w{const void *@var{buffer}}, @w{size_t @var{length}}, @w{int @var{autodetect}}) |
3056 | 3056 | ||
3057 | This is the generic function to create an new S-expression object from | 3057 | This is the generic function to create an new S-expression object from |
3058 | its external representation in @var{buffer} of @var{length} bytes. On | 3058 | its external representation in @var{buffer} of @var{length} bytes. On |
3059 | success the result is stored at the address given by @var{r_sexp}. | 3059 | success the result is stored at the address given by @var{r_sexp}. |
3060 | With @var{autodetect} set to 0, the data in @var{buffer} is expected to | 3060 | With @var{autodetect} set to 0, the data in @var{buffer} is expected to |
3061 | be in canonized format, with @var{autodetect} set to 1 the parses any of | 3061 | be in canonized format, with @var{autodetect} set to 1 the parses any of |
3062 | the defined external formats. If @var{buffer} does not hold a valid | 3062 | the defined external formats. If @var{buffer} does not hold a valid |
3063 | S-expression an error code is returned and @var{r_sexp} set to | 3063 | S-expression an error code is returned and @var{r_sexp} set to |
3064 | @code{NULL}. | 3064 | @code{NULL}. |
3065 | Note, that the caller is responsible for releasing the newly allocated | 3065 | Note, that the caller is responsible for releasing the newly allocated |
3066 | S-expression using @code{gcry_sexp_release}. | 3066 | S-expression using @code{gcry_sexp_release}. |
3067 | @end deftypefun | 3067 | @end deftypefun |
3068 | 3068 | ||
3069 | @deftypefun gcry_error_t gcry_sexp_create (@w{gcry_sexp_t *@var{r_sexp}}, @w{void *@var{buffer}}, @w{size_t @var{length}}, @w{int @var{autodetect}}, @w{void (*@var{freefnc})(void*)}) | 3069 | @deftypefun gcry_error_t gcry_sexp_create (@w{gcry_sexp_t *@var{r_sexp}}, @w{void *@var{buffer}}, @w{size_t @var{length}}, @w{int @var{autodetect}}, @w{void (*@var{freefnc})(void*)}) |
3070 | 3070 | ||
3071 | This function is identical to @code{gcry_sexp_new} but has an extra | 3071 | This function is identical to @code{gcry_sexp_new} but has an extra |
3072 | argument @var{freefnc}, which, when not set to @code{NULL}, is expected | 3072 | argument @var{freefnc}, which, when not set to @code{NULL}, is expected |
3073 | to be a function to release the @var{buffer}; most likely the standard | 3073 | to be a function to release the @var{buffer}; most likely the standard |
3074 | @code{free} function is used for this argument. This has the effect of | 3074 | @code{free} function is used for this argument. This has the effect of |
3075 | transferring the ownership of @var{buffer} to the created object in | 3075 | transferring the ownership of @var{buffer} to the created object in |
3076 | @var{r_sexp}. The advantage of using this function is that @acronym{Libgcrypt} | 3076 | @var{r_sexp}. The advantage of using this function is that @acronym{Libgcrypt} |
3077 | might decide to directly use the provided buffer and thus avoid extra | 3077 | might decide to directly use the provided buffer and thus avoid extra |
3078 | copying. | 3078 | copying. |
3079 | @end deftypefun | 3079 | @end deftypefun |
3080 | 3080 | ||
3081 | @deftypefun gcry_error_t gcry_sexp_sscan (@w{gcry_sexp_t *@var{r_sexp}}, @w{size_t *@var{erroff}}, @w{const char *@var{buffer}}, @w{size_t @var{length}}) | 3081 | @deftypefun gcry_error_t gcry_sexp_sscan (@w{gcry_sexp_t *@var{r_sexp}}, @w{size_t *@var{erroff}}, @w{const char *@var{buffer}}, @w{size_t @var{length}}) |
3082 | 3082 | ||
3083 | This is another variant of the above functions. It behaves nearly | 3083 | This is another variant of the above functions. It behaves nearly |
3084 | identical but provides an @var{erroff} argument which will receive the | 3084 | identical but provides an @var{erroff} argument which will receive the |
3085 | offset into the buffer where the parsing stopped on error. | 3085 | offset into the buffer where the parsing stopped on error. |
3086 | @end deftypefun | 3086 | @end deftypefun |
3087 | 3087 | ||
3088 | @deftypefun gcry_error_t gcry_sexp_build (@w{gcry_sexp_t *@var{r_sexp}}, @w{size_t *@var{erroff}}, @w{const char *@var{format}, ...}) | 3088 | @deftypefun gcry_error_t gcry_sexp_build (@w{gcry_sexp_t *@var{r_sexp}}, @w{size_t *@var{erroff}}, @w{const char *@var{format}, ...}) |
3089 | 3089 | ||
3090 | This function creates an internal S-expression from the string template | 3090 | This function creates an internal S-expression from the string template |
3091 | @var{format} and stores it at the address of @var{r_sexp}. If there is a | 3091 | @var{format} and stores it at the address of @var{r_sexp}. If there is a |
3092 | parsing error, the function returns an appropriate error code and stores | 3092 | parsing error, the function returns an appropriate error code and stores |
3093 | the offset into @var{format} where the parsing stopped in @var{erroff}. | 3093 | the offset into @var{format} where the parsing stopped in @var{erroff}. |
3094 | The function supports a couple of printf-like formatting characters and | 3094 | The function supports a couple of printf-like formatting characters and |
3095 | expects arguments for some of these escape sequences right after | 3095 | expects arguments for some of these escape sequences right after |
3096 | @var{format}. The following format characters are defined: | 3096 | @var{format}. The following format characters are defined: |
3097 | 3097 | ||
3098 | @table @samp | 3098 | @table @samp |
3099 | @item %m | 3099 | @item %m |
3100 | The next argument is expected to be of type @code{gcry_mpi_t} and a copy of | 3100 | The next argument is expected to be of type @code{gcry_mpi_t} and a copy of |
3101 | its value is inserted into the resulting S-expression. | 3101 | its value is inserted into the resulting S-expression. |
3102 | @item %s | 3102 | @item %s |
3103 | The next argument is expected to be of type @code{char *} and that | 3103 | The next argument is expected to be of type @code{char *} and that |
3104 | string is inserted into the resulting S-expression. | 3104 | string is inserted into the resulting S-expression. |
3105 | @item %d | 3105 | @item %d |
3106 | The next argument is expected to be of type @code{int} and its | 3106 | The next argument is expected to be of type @code{int} and its |
3107 | value ist inserted into the resulting S-expression. | 3107 | value ist inserted into the resulting S-expression. |
3108 | @item %b | 3108 | @item %b |
3109 | The next argument is expected to be of type @code{int} directly | 3109 | The next argument is expected to be of type @code{int} directly |
3110 | followed by an argument of type @code{char *}. This represents a | 3110 | followed by an argument of type @code{char *}. This represents a |
3111 | buffer of given length to be inserted into the resulting regular | 3111 | buffer of given length to be inserted into the resulting regular |
3112 | expression. | 3112 | expression. |
3113 | @end table | 3113 | @end table |
3114 | 3114 | ||
3115 | @noindent | 3115 | @noindent |
3116 | No other format characters are defined and would return an error. Note, | 3116 | No other format characters are defined and would return an error. Note, |
3117 | that the format character @samp{%%} does not exists, because a percent | 3117 | that the format character @samp{%%} does not exists, because a percent |
3118 | sign is not a valid character in an S-expression. | 3118 | sign is not a valid character in an S-expression. |
3119 | @end deftypefun | 3119 | @end deftypefun |
3120 | 3120 | ||
3121 | @deftypefun void gcry_sexp_release (@w{gcry_sexp_t @var{sexp}}) | 3121 | @deftypefun void gcry_sexp_release (@w{gcry_sexp_t @var{sexp}}) |
3122 | 3122 | ||
3123 | Release the S-expression object @var{sexp}. | 3123 | Release the S-expression object @var{sexp}. |
3124 | @end deftypefun | 3124 | @end deftypefun |
3125 | 3125 | ||
3126 | 3126 | ||
3127 | @noindent | 3127 | @noindent |
3128 | The next 2 functions are used to convert the internal representation | 3128 | The next 2 functions are used to convert the internal representation |
3129 | back into a regular external S-expression format and to show the | 3129 | back into a regular external S-expression format and to show the |
3130 | structure for debugging. | 3130 | structure for debugging. |
3131 | 3131 | ||
3132 | @deftypefun size_t gcry_sexp_sprint (@w{gcry_sexp_t @var{sexp}}, @w{int @var{mode}}, @w{void *@var{buffer}}, @w{size_t @var{maxlength}}) | 3132 | @deftypefun size_t gcry_sexp_sprint (@w{gcry_sexp_t @var{sexp}}, @w{int @var{mode}}, @w{void *@var{buffer}}, @w{size_t @var{maxlength}}) |
3133 | 3133 | ||
3134 | Copies the S-expression object @var{sexp} into @var{buffer} using the | 3134 | Copies the S-expression object @var{sexp} into @var{buffer} using the |
3135 | format specified in @var{mode}. @var{maxlength} must be set to the | 3135 | format specified in @var{mode}. @var{maxlength} must be set to the |
3136 | allocated length of @var{buffer}. The function returns the actual | 3136 | allocated length of @var{buffer}. The function returns the actual |
3137 | length of valid bytes put into @var{buffer} or 0 if the provided buffer | 3137 | length of valid bytes put into @var{buffer} or 0 if the provided buffer |
3138 | is too short. Passing @code{NULL} for @var{buffer} returns the required | 3138 | is too short. Passing @code{NULL} for @var{buffer} returns the required |
3139 | length for @var{buffer}. For convenience reasons an extra byte with | 3139 | length for @var{buffer}. For convenience reasons an extra byte with |
3140 | value 0 is appended to the buffer. | 3140 | value 0 is appended to the buffer. |
3141 | 3141 | ||
3142 | @noindent | 3142 | @noindent |
3143 | The following formats are supported: | 3143 | The following formats are supported: |
3144 | 3144 | ||
3145 | @table @code | 3145 | @table @code |
3146 | @item GCRYSEXP_FMT_DEFAULT | 3146 | @item GCRYSEXP_FMT_DEFAULT |
3147 | Returns a convenient external S-expression representation. | 3147 | Returns a convenient external S-expression representation. |
3148 | 3148 | ||
3149 | @item GCRYSEXP_FMT_CANON | 3149 | @item GCRYSEXP_FMT_CANON |
3150 | Return the S-expression in canonical format. | 3150 | Return the S-expression in canonical format. |
3151 | 3151 | ||
3152 | @item GCRYSEXP_FMT_BASE64 | 3152 | @item GCRYSEXP_FMT_BASE64 |
3153 | Not currently supported. | 3153 | Not currently supported. |
3154 | 3154 | ||
3155 | @item GCRYSEXP_FMT_ADVANCED | 3155 | @item GCRYSEXP_FMT_ADVANCED |
3156 | Returns the S-expression in advanced format. | 3156 | Returns the S-expression in advanced format. |
3157 | @end table | 3157 | @end table |
3158 | @end deftypefun | 3158 | @end deftypefun |
3159 | 3159 | ||
3160 | @deftypefun void gcry_sexp_dump (@w{gcry_sexp_t @var{sexp}}) | 3160 | @deftypefun void gcry_sexp_dump (@w{gcry_sexp_t @var{sexp}}) |
3161 | 3161 | ||
3162 | Dumps @var{sexp} in a format suitable for debugging to @acronym{Libgcrypt}'s | 3162 | Dumps @var{sexp} in a format suitable for debugging to @acronym{Libgcrypt}'s |
3163 | logging stream. | 3163 | logging stream. |
3164 | @end deftypefun | 3164 | @end deftypefun |
3165 | 3165 | ||
3166 | @noindent | 3166 | @noindent |
3167 | Often canonical encoding is used in the external representation. The | 3167 | Often canonical encoding is used in the external representation. The |
3168 | following function can be used to check for valid encoding and to learn | 3168 | following function can be used to check for valid encoding and to learn |
3169 | the length of the S-expression" | 3169 | the length of the S-expression" |
3170 | 3170 | ||
3171 | @deftypefun size_t gcry_sexp_canon_len (@w{const unsigned char *@var{buffer}}, @w{size_t @var{length}}, @w{size_t *@var{erroff}}, @w{int *@var{errcode}}) | 3171 | @deftypefun size_t gcry_sexp_canon_len (@w{const unsigned char *@var{buffer}}, @w{size_t @var{length}}, @w{size_t *@var{erroff}}, @w{int *@var{errcode}}) |
3172 | 3172 | ||
3173 | Scan the canonical encoded @var{buffer} with implicit length values and | 3173 | Scan the canonical encoded @var{buffer} with implicit length values and |
3174 | return the actual length this S-expression uses. For a valid S-expression | 3174 | return the actual length this S-expression uses. For a valid S-expression |
3175 | it should never return 0. If @var{length} is not 0, the maximum | 3175 | it should never return 0. If @var{length} is not 0, the maximum |
3176 | length to scan is given; this can be used for syntax checks of | 3176 | length to scan is given; this can be used for syntax checks of |
3177 | data passed from outside. @var{errcode} and @var{erroff} may both be | 3177 | data passed from outside. @var{errcode} and @var{erroff} may both be |
3178 | passed as @code{NULL}. | 3178 | passed as @code{NULL}. |
3179 | 3179 | ||
3180 | @end deftypefun | 3180 | @end deftypefun |
3181 | 3181 | ||
3182 | 3182 | ||
3183 | @noindent | 3183 | @noindent |
3184 | There are a couple of functions to parse S-expressions and retrieve | 3184 | There are a couple of functions to parse S-expressions and retrieve |
3185 | elements: | 3185 | elements: |
3186 | 3186 | ||
3187 | @deftypefun gcry_sexp_t gcry_sexp_find_token (@w{const gcry_sexp_t @var{list}}, @w{const char *@var{token}}, @w{size_t @var{toklen}}) | 3187 | @deftypefun gcry_sexp_t gcry_sexp_find_token (@w{const gcry_sexp_t @var{list}}, @w{const char *@var{token}}, @w{size_t @var{toklen}}) |
3188 | 3188 | ||
3189 | Scan the S-expression for a sublist with a type (the car of the list) | 3189 | Scan the S-expression for a sublist with a type (the car of the list) |
3190 | matching the string @var{token}. If @var{toklen} is not 0, the token is | 3190 | matching the string @var{token}. If @var{toklen} is not 0, the token is |
3191 | assumed to be raw memory of this length. The function returns a newly | 3191 | assumed to be raw memory of this length. The function returns a newly |
3192 | allocated S-expression consisting of the found sublist or @code{NULL} | 3192 | allocated S-expression consisting of the found sublist or @code{NULL} |
3193 | when not found. | 3193 | when not found. |
3194 | @end deftypefun | 3194 | @end deftypefun |
3195 | 3195 | ||
3196 | 3196 | ||
3197 | @deftypefun int gcry_sexp_length (@w{const gcry_sexp_t @var{list}}) | 3197 | @deftypefun int gcry_sexp_length (@w{const gcry_sexp_t @var{list}}) |
3198 | 3198 | ||
3199 | Return the length of the @var{list}. For a valid S-expression this | 3199 | Return the length of the @var{list}. For a valid S-expression this |
3200 | should be at least 1. | 3200 | should be at least 1. |
3201 | @end deftypefun | 3201 | @end deftypefun |
3202 | 3202 | ||
3203 | 3203 | ||
3204 | @deftypefun gcry_sexp_t gcry_sexp_nth (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}) | 3204 | @deftypefun gcry_sexp_t gcry_sexp_nth (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}) |
3205 | 3205 | ||
3206 | Create and return a new S-expression from the element with index @var{number} in | 3206 | Create and return a new S-expression from the element with index @var{number} in |
3207 | @var{list}. Note that the first element has the index 0. If there is | 3207 | @var{list}. Note that the first element has the index 0. If there is |
3208 | no such element, @code{NULL} is returned. | 3208 | no such element, @code{NULL} is returned. |
3209 | @end deftypefun | 3209 | @end deftypefun |
3210 | 3210 | ||
3211 | @deftypefun gcry_sexp_t gcry_sexp_car (@w{const gcry_sexp_t @var{list}}) | 3211 | @deftypefun gcry_sexp_t gcry_sexp_car (@w{const gcry_sexp_t @var{list}}) |
3212 | 3212 | ||
3213 | Create and return a new S-expression from the first element in | 3213 | Create and return a new S-expression from the first element in |
3214 | @var{list}; this called the "type" and should always exist and be a | 3214 | @var{list}; this called the "type" and should always exist and be a |
3215 | string. @code{NULL} is returned in case of a problem. | 3215 | string. @code{NULL} is returned in case of a problem. |
3216 | @end deftypefun | 3216 | @end deftypefun |
3217 | 3217 | ||
3218 | @deftypefun gcry_sexp_t gcry_sexp_cdr (@w{const gcry_sexp_t @var{list}}) | 3218 | @deftypefun gcry_sexp_t gcry_sexp_cdr (@w{const gcry_sexp_t @var{list}}) |
3219 | 3219 | ||
3220 | Create and return a new list form all elements except for the first one. | 3220 | Create and return a new list form all elements except for the first one. |
3221 | Note, that this function may return an invalid S-expression because it | 3221 | Note, that this function may return an invalid S-expression because it |
3222 | is not guaranteed, that the type exists and is a string. However, for | 3222 | is not guaranteed, that the type exists and is a string. However, for |
3223 | parsing a complex S-expression it might be useful for intermediate | 3223 | parsing a complex S-expression it might be useful for intermediate |
3224 | lists. Returns @code{NULL} on error. | 3224 | lists. Returns @code{NULL} on error. |
3225 | @end deftypefun | 3225 | @end deftypefun |
3226 | 3226 | ||
3227 | 3227 | ||
3228 | @deftypefun {const char *} gcry_sexp_nth_data (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{size_t *@var{datalen}}) | 3228 | @deftypefun {const char *} gcry_sexp_nth_data (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{size_t *@var{datalen}}) |
3229 | 3229 | ||
3230 | This function is used to get data from a @var{list}. A pointer to the | 3230 | This function is used to get data from a @var{list}. A pointer to the |
3231 | actual data with index @var{number} is returned and the length of this | 3231 | actual data with index @var{number} is returned and the length of this |
3232 | data will be stored to @var{datalen}. If there is no data at the given | 3232 | data will be stored to @var{datalen}. If there is no data at the given |
3233 | index or the index represents another list, @code{NULL} is returned. | 3233 | index or the index represents another list, @code{NULL} is returned. |
3234 | @strong{Take care:} The returned pointer is valid as long as @var{list} is | 3234 | @strong{Take care:} The returned pointer is valid as long as @var{list} is |
3235 | not modified or released. | 3235 | not modified or released. |
3236 | 3236 | ||
3237 | @noindent | 3237 | @noindent |
3238 | Here is an example on how to extract and print the surname (Meier) from | 3238 | Here is an example on how to extract and print the surname (Meier) from |
3239 | the S-expression @samp{(Name Otto Meier (address Burgplatz 3))}: | 3239 | the S-expression @samp{(Name Otto Meier (address Burgplatz 3))}: |
3240 | 3240 | ||
3241 | @example | 3241 | @example |
3242 | size_t len; | 3242 | size_t len; |
3243 | const char *name; | 3243 | const char *name; |
3244 | 3244 | ||
3245 | name = gcry_sexp_nth_data (list, 2, &len); | 3245 | name = gcry_sexp_nth_data (list, 2, &len); |
3246 | printf ("my name is %.*s\n", (int)len, name); | 3246 | printf ("my name is %.*s\n", (int)len, name); |
3247 | @end example | 3247 | @end example |
3248 | @end deftypefun | 3248 | @end deftypefun |
3249 | 3249 | ||
3250 | @deftypefun gcry_mpi_t gcry_sexp_nth_mpi (@w{gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{int @var{mpifmt}}) | 3250 | @deftypefun gcry_mpi_t gcry_sexp_nth_mpi (@w{gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{int @var{mpifmt}}) |
3251 | 3251 | ||
3252 | This function is used to get and convert data from a @var{list}. This | 3252 | This function is used to get and convert data from a @var{list}. This |
3253 | data is assumed to be an MPI stored in the format described by | 3253 | data is assumed to be an MPI stored in the format described by |
3254 | @var{mpifmt} and returned as a standard @acronym{Libgcrypt} MPI. The caller must | 3254 | @var{mpifmt} and returned as a standard @acronym{Libgcrypt} MPI. The caller must |
3255 | release this returned value using @code{gcry_mpi_release}. If there is | 3255 | release this returned value using @code{gcry_mpi_release}. If there is |
3256 | no data at the given index, the index represents a list or the value | 3256 | no data at the given index, the index represents a list or the value |
3257 | can't be converted to an MPI, @code{NULL} is returned. | 3257 | can't be converted to an MPI, @code{NULL} is returned. |
3258 | @end deftypefun | 3258 | @end deftypefun |
3259 | 3259 | ||
3260 | 3260 | ||
3261 | @c ********************************************************** | 3261 | @c ********************************************************** |
3262 | @c ******************* MPIs ******** *********************** | 3262 | @c ******************* MPIs ******** *********************** |
3263 | @c ********************************************************** | 3263 | @c ********************************************************** |
3264 | @node MPI library | 3264 | @node MPI library |
3265 | @chapter MPI library | 3265 | @chapter MPI library |
3266 | 3266 | ||
3267 | @menu | 3267 | @menu |
3268 | * Data types:: MPI related data types. | 3268 | * Data types:: MPI related data types. |
3269 | * Basic functions:: First steps with MPI numbers. | 3269 | * Basic functions:: First steps with MPI numbers. |
3270 | * MPI formats:: External representation of MPIs. | 3270 | * MPI formats:: External representation of MPIs. |
3271 | * Calculations:: Performing MPI calculations. | 3271 | * Calculations:: Performing MPI calculations. |
3272 | * Comparisons:: How to compare MPI values. | 3272 | * Comparisons:: How to compare MPI values. |
3273 | * Bit manipulations:: How to access single bits of MPI values. | 3273 | * Bit manipulations:: How to access single bits of MPI values. |
3274 | * Miscellaneous:: Miscellaneous MPI functions. | 3274 | * Miscellaneous:: Miscellaneous MPI functions. |
3275 | @end menu | 3275 | @end menu |
3276 | 3276 | ||
3277 | Public key cryptography is based on mathematics with large numbers. To | 3277 | Public key cryptography is based on mathematics with large numbers. To |
3278 | implement the public key functions, a library for handling these large | 3278 | implement the public key functions, a library for handling these large |
3279 | numbers is required. Because of the general usefulness of such a | 3279 | numbers is required. Because of the general usefulness of such a |
3280 | library, its interface is exposed by @acronym{Libgcrypt}. The implementation is | 3280 | library, its interface is exposed by @acronym{Libgcrypt}. The implementation is |
3281 | based on an old release of GNU Multi-Precision Library (GMP) but in the | 3281 | based on an old release of GNU Multi-Precision Library (GMP) but in the |
3282 | meantime heavily modified and stripped down to what is required for | 3282 | meantime heavily modified and stripped down to what is required for |
3283 | cryptography. For a lot of CPUs, high performance assembler | 3283 | cryptography. For a lot of CPUs, high performance assembler |
3284 | implementations of some very low level functions are used to gain much | 3284 | implementations of some very low level functions are used to gain much |
3285 | better performance than with the standard C implementation. | 3285 | better performance than with the standard C implementation. |
3286 | 3286 | ||
3287 | @noindent | 3287 | @noindent |
3288 | In the context of @acronym{Libgcrypt} and in most other applications, these large | 3288 | In the context of @acronym{Libgcrypt} and in most other applications, these large |
3289 | numbers are called MPIs (multi-precision-integers). | 3289 | numbers are called MPIs (multi-precision-integers). |
3290 | 3290 | ||
3291 | @node Data types | 3291 | @node Data types |
3292 | @section Data types | 3292 | @section Data types |
3293 | 3293 | ||
3294 | @deftp {Data type} gcry_mpi_t | 3294 | @deftp {Data type} gcry_mpi_t |
3295 | The @code{gcry_mpi_t} type represents an object to hold an MPI. | 3295 | The @code{gcry_mpi_t} type represents an object to hold an MPI. |
3296 | @end deftp | 3296 | @end deftp |
3297 | 3297 | ||
3298 | @node Basic functions | 3298 | @node Basic functions |
3299 | @section Basic functions | 3299 | @section Basic functions |
3300 | 3300 | ||
3301 | @noindent | 3301 | @noindent |
3302 | To work with MPIs, storage must be allocated and released for the | 3302 | To work with MPIs, storage must be allocated and released for the |
3303 | numbers. This can be done with one of these functions: | 3303 | numbers. This can be done with one of these functions: |
3304 | 3304 | ||
3305 | @deftypefun gcry_mpi_t gcry_mpi_new (@w{unsigned int @var{nbits}}) | 3305 | @deftypefun gcry_mpi_t gcry_mpi_new (@w{unsigned int @var{nbits}}) |
3306 | 3306 | ||
3307 | Allocate a new MPI object, initialize it to 0 and initially allocate | 3307 | Allocate a new MPI object, initialize it to 0 and initially allocate |
3308 | enough memory for a number of at least @var{nbits}. This pre-allocation is | 3308 | enough memory for a number of at least @var{nbits}. This pre-allocation is |
3309 | only a small performance issue and not actually necessary because | 3309 | only a small performance issue and not actually necessary because |
3310 | @acronym{Libgcrypt} automatically re-allocates the required memory. | 3310 | @acronym{Libgcrypt} automatically re-allocates the required memory. |
3311 | @end deftypefun | 3311 | @end deftypefun |
3312 | 3312 | ||
3313 | @deftypefun gcry_mpi_t gcry_mpi_snew (@w{unsigned int @var{nbits}}) | 3313 | @deftypefun gcry_mpi_t gcry_mpi_snew (@w{unsigned int @var{nbits}}) |
3314 | 3314 | ||
3315 | This is identical to @code{gcry_mpi_new} but allocates the MPI in the so | 3315 | This is identical to @code{gcry_mpi_new} but allocates the MPI in the so |
3316 | called "secure memory" which in turn will take care that all derived | 3316 | called "secure memory" which in turn will take care that all derived |
3317 | values will also be stored in this "secure memory". Use this for highly | 3317 | values will also be stored in this "secure memory". Use this for highly |
3318 | confidential data like private key parameters. | 3318 | confidential data like private key parameters. |
3319 | @end deftypefun | 3319 | @end deftypefun |
3320 | 3320 | ||
3321 | @deftypefun gcry_mpi_t gcry_mpi_copy (@w{const gcry_mpi_t @var{a}}) | 3321 | @deftypefun gcry_mpi_t gcry_mpi_copy (@w{const gcry_mpi_t @var{a}}) |
3322 | 3322 | ||
3323 | Create a new MPI as the exact copy of @var{a}. | 3323 | Create a new MPI as the exact copy of @var{a}. |
3324 | @end deftypefun | 3324 | @end deftypefun |
3325 | 3325 | ||
3326 | 3326 | ||
3327 | @deftypefun void gcry_mpi_release (@w{gcry_mpi_t @var{a}}) | 3327 | @deftypefun void gcry_mpi_release (@w{gcry_mpi_t @var{a}}) |
3328 | 3328 | ||
3329 | Release the MPI @var{a} and free all associated resources. Passing | 3329 | Release the MPI @var{a} and free all associated resources. Passing |
3330 | @code{NULL} is allowed and ignored. When a MPI stored in the "secure | 3330 | @code{NULL} is allowed and ignored. When a MPI stored in the "secure |
3331 | memory" is released, that memory gets wiped out immediately. | 3331 | memory" is released, that memory gets wiped out immediately. |
3332 | @end deftypefun | 3332 | @end deftypefun |
3333 | 3333 | ||
3334 | @noindent | 3334 | @noindent |
3335 | The simplest operations are used to assign a new value to an MPI: | 3335 | The simplest operations are used to assign a new value to an MPI: |
3336 | 3336 | ||
3337 | @deftypefun gcry_mpi_t gcry_mpi_set (@w{gcry_mpi_t @var{w}}, @w{const gcry_mpi_t @var{u}}) | 3337 | @deftypefun gcry_mpi_t gcry_mpi_set (@w{gcry_mpi_t @var{w}}, @w{const gcry_mpi_t @var{u}}) |
3338 | 3338 | ||
3339 | Assign the value of @var{u} to @var{w} and return @var{w}. If | 3339 | Assign the value of @var{u} to @var{w} and return @var{w}. If |
3340 | @code{NULL} is passed for @var{w}, a new MPI is allocated, set to the | 3340 | @code{NULL} is passed for @var{w}, a new MPI is allocated, set to the |
3341 | value of @var{u} and returned. | 3341 | value of @var{u} and returned. |
3342 | @end deftypefun | 3342 | @end deftypefun |
3343 | 3343 | ||
3344 | @deftypefun gcry_mpi_t gcry_mpi_set_ui (@w{gcry_mpi_t @var{w}}, @w{unsigned long @var{u}}) | 3344 | @deftypefun gcry_mpi_t gcry_mpi_set_ui (@w{gcry_mpi_t @var{w}}, @w{unsigned long @var{u}}) |
3345 | 3345 | ||
3346 | Assign the value of @var{u} to @var{w} and return @var{w}. If | 3346 | Assign the value of @var{u} to @var{w} and return @var{w}. If |
3347 | @code{NULL} is passed for @var{w}, a new MPI is allocated, set to the | 3347 | @code{NULL} is passed for @var{w}, a new MPI is allocated, set to the |
3348 | value of @var{u} and returned. This function takes an @code{unsigned | 3348 | value of @var{u} and returned. This function takes an @code{unsigned |
3349 | int} as type for @var{u} and thus it is only possible to set @var{w} to | 3349 | int} as type for @var{u} and thus it is only possible to set @var{w} to |
3350 | small values (usually up to the word size of the CPU). | 3350 | small values (usually up to the word size of the CPU). |
3351 | @end deftypefun | 3351 | @end deftypefun |
3352 | 3352 | ||
3353 | @deftypefun void gcry_mpi_swap (@w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{b}}) | 3353 | @deftypefun void gcry_mpi_swap (@w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{b}}) |
3354 | 3354 | ||
3355 | Swap the values of @var{a} and @var{b}. | 3355 | Swap the values of @var{a} and @var{b}. |
3356 | @end deftypefun | 3356 | @end deftypefun |
3357 | 3357 | ||
3358 | @node MPI formats | 3358 | @node MPI formats |
3359 | @section MPI formats | 3359 | @section MPI formats |
3360 | 3360 | ||
3361 | @noindent | 3361 | @noindent |
3362 | The following functions are used to convert between an external | 3362 | The following functions are used to convert between an external |
3363 | representation of an MPI and the internal one of @acronym{Libgcrypt}. | 3363 | representation of an MPI and the internal one of @acronym{Libgcrypt}. |
3364 | 3364 | ||
3365 | @deftypefun int gcry_mpi_scan (@w{gcry_mpi_t *@var{r_mpi}}, @w{enum gcry_mpi_format @var{format}}, @w{const void *@var{buffer}}, @w{size_t @var{buflen}}, @w{size_t *@var{nscanned}}) | 3365 | @deftypefun int gcry_mpi_scan (@w{gcry_mpi_t *@var{r_mpi}}, @w{enum gcry_mpi_format @var{format}}, @w{const void *@var{buffer}}, @w{size_t @var{buflen}}, @w{size_t *@var{nscanned}}) |
3366 | 3366 | ||
3367 | Convert the external representation of an integer stored in @var{buffer} | 3367 | Convert the external representation of an integer stored in @var{buffer} |
3368 | with a length of @var{buflen} into a newly created MPI returned which | 3368 | with a length of @var{buflen} into a newly created MPI returned which |
3369 | will be stored at the address of @var{r_mpi}. For certain formats the | 3369 | will be stored at the address of @var{r_mpi}. For certain formats the |
3370 | length argument is not required and may be passed as @code{0}. After a | 3370 | length argument is not required and may be passed as @code{0}. After a |
3371 | successful operation the variable @var{nscanned} receives the number of | 3371 | successful operation the variable @var{nscanned} receives the number of |
3372 | bytes actually scanned unless @var{nscanned} was given as | 3372 | bytes actually scanned unless @var{nscanned} was given as |
3373 | @code{NULL}. @var{format} describes the format of the MPI as stored in | 3373 | @code{NULL}. @var{format} describes the format of the MPI as stored in |
3374 | @var{buffer}: | 3374 | @var{buffer}: |
3375 | 3375 | ||
3376 | @table @code | 3376 | @table @code |
3377 | @item GCRYMPI_FMT_STD | 3377 | @item GCRYMPI_FMT_STD |
3378 | 2-complement stored without a length header. | 3378 | 2-complement stored without a length header. |
3379 | 3379 | ||
3380 | @item GCRYMPI_FMT_PGP | 3380 | @item GCRYMPI_FMT_PGP |
3381 | As used by OpenPGP (only defined as unsigned). This is basically | 3381 | As used by OpenPGP (only defined as unsigned). This is basically |
3382 | @code{GCRYMPI_FMT_STD} with a 2 byte big endian length header. | 3382 | @code{GCRYMPI_FMT_STD} with a 2 byte big endian length header. |
3383 | 3383 | ||
3384 | @item GCRYMPI_FMT_SSH | 3384 | @item GCRYMPI_FMT_SSH |
3385 | As used in the Secure Shell protocol. This is @code{GCRYMPI_FMT_STD} | 3385 | As used in the Secure Shell protocol. This is @code{GCRYMPI_FMT_STD} |
3386 | with a 4 byte big endian header. | 3386 | with a 4 byte big endian header. |
3387 | 3387 | ||
3388 | @item GCRYMPI_FMT_HEX | 3388 | @item GCRYMPI_FMT_HEX |
3389 | Stored as a C style string with each byte of the MPI encoded as 2 hex | 3389 | Stored as a C style string with each byte of the MPI encoded as 2 hex |
3390 | digits. | 3390 | digits. |
3391 | 3391 | ||
3392 | @item GCRYMPI_FMT_USG | 3392 | @item GCRYMPI_FMT_USG |
3393 | Simple unsigned integer. | 3393 | Simple unsigned integer. |
3394 | @end table | 3394 | @end table |
3395 | 3395 | ||
3396 | @noindent | 3396 | @noindent |
3397 | Note, that all of the above formats store the integer in big-endian | 3397 | Note, that all of the above formats store the integer in big-endian |
3398 | format (MSB first). | 3398 | format (MSB first). |
3399 | @end deftypefun | 3399 | @end deftypefun |
3400 | 3400 | ||
3401 | 3401 | ||
3402 | @deftypefun int gcry_mpi_print (@w{enum gcry_mpi_format @var{format}}, @w{unsigned char *@var{buffer}}, @w{size_t @var{buflen}}, @w{size_t *@var{nwritten}}, @w{const gcry_mpi_t @var{a}}) | 3402 | @deftypefun int gcry_mpi_print (@w{enum gcry_mpi_format @var{format}}, @w{unsigned char *@var{buffer}}, @w{size_t @var{buflen}}, @w{size_t *@var{nwritten}}, @w{const gcry_mpi_t @var{a}}) |
3403 | 3403 | ||
3404 | Convert the MPI @var{a} into an external representation described by | 3404 | Convert the MPI @var{a} into an external representation described by |
3405 | @var{format} (see above) and store it in the provided @var{buffer} | 3405 | @var{format} (see above) and store it in the provided @var{buffer} |
3406 | which has a usable length of at least the @var{buflen} bytes. If | 3406 | which has a usable length of at least the @var{buflen} bytes. If |
3407 | @var{nwritten} is not NULL, it will receive the number of bytes | 3407 | @var{nwritten} is not NULL, it will receive the number of bytes |
3408 | actually stored in @var{buffer} after a successful operation. | 3408 | actually stored in @var{buffer} after a successful operation. |
3409 | @end deftypefun | 3409 | @end deftypefun |
3410 | 3410 | ||
3411 | @deftypefun int gcry_mpi_aprint (@w{enum gcry_mpi_format @var{format}}, @w{unsigned char **@var{buffer}}, @w{size_t *@var{nbytes}}, @w{const gcry_mpi_t @var{a}}) | 3411 | @deftypefun int gcry_mpi_aprint (@w{enum gcry_mpi_format @var{format}}, @w{unsigned char **@var{buffer}}, @w{size_t *@var{nbytes}}, @w{const gcry_mpi_t @var{a}}) |
3412 | 3412 | ||
3413 | Convert the MPI @var{a} into an external representation described by | 3413 | Convert the MPI @var{a} into an external representation described by |
3414 | @var{format} (see above) and store it in a newly allocated buffer which | 3414 | @var{format} (see above) and store it in a newly allocated buffer which |
3415 | address will be stored in the variable @var{buffer} points to. The | 3415 | address will be stored in the variable @var{buffer} points to. The |
3416 | number of bytes stored in this buffer will be stored in the variable | 3416 | number of bytes stored in this buffer will be stored in the variable |
3417 | @var{nbytes} points to, unless @var{nbytes} is @code{NULL}. | 3417 | @var{nbytes} points to, unless @var{nbytes} is @code{NULL}. |
3418 | @end deftypefun | 3418 | @end deftypefun |
3419 | 3419 | ||
3420 | @deftypefun void gcry_mpi_dump (@w{const gcry_mpi_t @var{a}}) | 3420 | @deftypefun void gcry_mpi_dump (@w{const gcry_mpi_t @var{a}}) |
3421 | 3421 | ||
3422 | Dump the value of @var{a} in a format suitable for debugging to | 3422 | Dump the value of @var{a} in a format suitable for debugging to |
3423 | Libgcrypt's logging stream. Note that one leading space but no trailing | 3423 | Libgcrypt's logging stream. Note that one leading space but no trailing |
3424 | space or linefeed will be printed. It is okay to pass @code{NULL} for | 3424 | space or linefeed will be printed. It is okay to pass @code{NULL} for |
3425 | @var{a}. | 3425 | @var{a}. |
3426 | @end deftypefun | 3426 | @end deftypefun |
3427 | 3427 | ||
3428 | 3428 | ||
3429 | @node Calculations | 3429 | @node Calculations |
3430 | @section Calculations | 3430 | @section Calculations |
3431 | 3431 | ||
3432 | @noindent | 3432 | @noindent |
3433 | Basic arithmetic operations: | 3433 | Basic arithmetic operations: |
3434 | 3434 | ||
3435 | @deftypefun void gcry_mpi_add (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) | 3435 | @deftypefun void gcry_mpi_add (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) |
3436 | 3436 | ||
3437 | @math{@var{w} = @var{u} + @var{v}}. | 3437 | @math{@var{w} = @var{u} + @var{v}}. |
3438 | @end deftypefun | 3438 | @end deftypefun |
3439 | 3439 | ||
3440 | 3440 | ||
3441 | @deftypefun void gcry_mpi_add_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) | 3441 | @deftypefun void gcry_mpi_add_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) |
3442 | 3442 | ||
3443 | @math{@var{w} = @var{u} + @var{v}}. Note, that @var{v} is an unsigned integer. | 3443 | @math{@var{w} = @var{u} + @var{v}}. Note, that @var{v} is an unsigned integer. |
3444 | @end deftypefun | 3444 | @end deftypefun |
3445 | 3445 | ||
3446 | 3446 | ||
3447 | @deftypefun void gcry_mpi_addm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) | 3447 | @deftypefun void gcry_mpi_addm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) |
3448 | 3448 | ||
3449 | @math{@var{w} = @var{u} + @var{v} \bmod @var{m}}. | 3449 | @math{@var{w} = @var{u} + @var{v} \bmod @var{m}}. |
3450 | @end deftypefun | 3450 | @end deftypefun |
3451 | 3451 | ||
3452 | @deftypefun void gcry_mpi_sub (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) | 3452 | @deftypefun void gcry_mpi_sub (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) |
3453 | 3453 | ||
3454 | @math{@var{w} = @var{u} - @var{v}}. | 3454 | @math{@var{w} = @var{u} - @var{v}}. |
3455 | @end deftypefun | 3455 | @end deftypefun |
3456 | 3456 | ||
3457 | @deftypefun void gcry_mpi_sub_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) | 3457 | @deftypefun void gcry_mpi_sub_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) |
3458 | 3458 | ||
3459 | @math{@var{w} = @var{u} - @var{v}}. @var{v} is an unsigned integer. | 3459 | @math{@var{w} = @var{u} - @var{v}}. @var{v} is an unsigned integer. |
3460 | @end deftypefun | 3460 | @end deftypefun |
3461 | 3461 | ||
3462 | @deftypefun void gcry_mpi_subm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) | 3462 | @deftypefun void gcry_mpi_subm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) |
3463 | 3463 | ||
3464 | @math{@var{w} = @var{u} - @var{v} \bmod @var{m}}. | 3464 | @math{@var{w} = @var{u} - @var{v} \bmod @var{m}}. |
3465 | @end deftypefun | 3465 | @end deftypefun |
3466 | 3466 | ||
3467 | @deftypefun void gcry_mpi_mul (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) | 3467 | @deftypefun void gcry_mpi_mul (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}) |
3468 | 3468 | ||
3469 | @math{@var{w} = @var{u} * @var{v}}. | 3469 | @math{@var{w} = @var{u} * @var{v}}. |
3470 | @end deftypefun | 3470 | @end deftypefun |
3471 | 3471 | ||
3472 | @deftypefun void gcry_mpi_mul_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) | 3472 | @deftypefun void gcry_mpi_mul_ui (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) |
3473 | 3473 | ||
3474 | @math{@var{w} = @var{u} * @var{v}}. @var{v} is an unsigned integer. | 3474 | @math{@var{w} = @var{u} * @var{v}}. @var{v} is an unsigned integer. |
3475 | @end deftypefun | 3475 | @end deftypefun |
3476 | 3476 | ||
3477 | @deftypefun void gcry_mpi_mulm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) | 3477 | @deftypefun void gcry_mpi_mulm (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{gcry_mpi_t @var{v}}, @w{gcry_mpi_t @var{m}}) |
3478 | 3478 | ||
3479 | @math{@var{w} = @var{u} * @var{v} \bmod @var{m}}. | 3479 | @math{@var{w} = @var{u} * @var{v} \bmod @var{m}}. |
3480 | @end deftypefun | 3480 | @end deftypefun |
3481 | 3481 | ||
3482 | @deftypefun void gcry_mpi_mul_2exp (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{e}}) | 3482 | @deftypefun void gcry_mpi_mul_2exp (@w{gcry_mpi_t @var{w}}, @w{gcry_mpi_t @var{u}}, @w{unsigned long @var{e}}) |
3483 | 3483 | ||
3484 | @c FIXME: I am in need for a real TeX{info} guru: | 3484 | @c FIXME: I am in need for a real TeX{info} guru: |
3485 | @c I don't know why TeX can grok @var{e} here. | 3485 | @c I don't know why TeX can grok @var{e} here. |
3486 | @math{@var{w} = @var{u} * 2^e}. | 3486 | @math{@var{w} = @var{u} * 2^e}. |
3487 | @end deftypefun | 3487 | @end deftypefun |
3488 | 3488 | ||
3489 | @deftypefun void gcry_mpi_div (@w{gcry_mpi_t @var{q}}, @w{gcry_mpi_t @var{r}}, @w{gcry_mpi_t @var{dividend}}, @w{gcry_mpi_t @var{divisor}}, @w{int @var{round}}) | 3489 | @deftypefun void gcry_mpi_div (@w{gcry_mpi_t @var{q}}, @w{gcry_mpi_t @var{r}}, @w{gcry_mpi_t @var{dividend}}, @w{gcry_mpi_t @var{divisor}}, @w{int @var{round}}) |
3490 | 3490 | ||
3491 | @math{@var{q} = @var{dividend} / @var{divisor}}, @math{@var{r} = | 3491 | @math{@var{q} = @var{dividend} / @var{divisor}}, @math{@var{r} = |
3492 | @var{dividend} \bmod @var{divisor}}. @var{q} and @var{r} may be passed | 3492 | @var{dividend} \bmod @var{divisor}}. @var{q} and @var{r} may be passed |
3493 | as @code{NULL}. @var{round} should be negative or 0. | 3493 | as @code{NULL}. @var{round} should be negative or 0. |
3494 | @end deftypefun | 3494 | @end deftypefun |
3495 | 3495 | ||
3496 | @deftypefun void gcry_mpi_mod (@w{gcry_mpi_t @var{r}}, @w{gcry_mpi_t @var{dividend}}, @w{gcry_mpi_t @var{divisor}}) | 3496 | @deftypefun void gcry_mpi_mod (@w{gcry_mpi_t @var{r}}, @w{gcry_mpi_t @var{dividend}}, @w{gcry_mpi_t @var{divisor}}) |
3497 | 3497 | ||
3498 | @math{@var{r} = @var{dividend} \bmod @var{divisor}}. | 3498 | @math{@var{r} = @var{dividend} \bmod @var{divisor}}. |
3499 | @end deftypefun | 3499 | @end deftypefun |
3500 | 3500 | ||
3501 | @deftypefun void gcry_mpi_powm (@w{gcry_mpi_t @var{w}}, @w{const gcry_mpi_t @var{b}}, @w{const gcry_mpi_t @var{e}}, @w{const gcry_mpi_t @var{m}}) | 3501 | @deftypefun void gcry_mpi_powm (@w{gcry_mpi_t @var{w}}, @w{const gcry_mpi_t @var{b}}, @w{const gcry_mpi_t @var{e}}, @w{const gcry_mpi_t @var{m}}) |
3502 | 3502 | ||
3503 | @c I don't know why TeX can grok @var{e} here. | 3503 | @c I don't know why TeX can grok @var{e} here. |
3504 | @math{@var{w} = @var{b}^e \bmod @var{m}}. | 3504 | @math{@var{w} = @var{b}^e \bmod @var{m}}. |
3505 | @end deftypefun | 3505 | @end deftypefun |
3506 | 3506 | ||
3507 | @deftypefun int gcry_mpi_gcd (@w{gcry_mpi_t @var{g}}, @w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{b}}) | 3507 | @deftypefun int gcry_mpi_gcd (@w{gcry_mpi_t @var{g}}, @w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{b}}) |
3508 | 3508 | ||
3509 | Set @var{g} to the greatest common divisor of @var{a} and @var{b}. | 3509 | Set @var{g} to the greatest common divisor of @var{a} and @var{b}. |
3510 | Return true if the @var{g} is 1. | 3510 | Return true if the @var{g} is 1. |
3511 | @end deftypefun | 3511 | @end deftypefun |
3512 | 3512 | ||
3513 | @deftypefun int gcry_mpi_invm (@w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{m}}) | 3513 | @deftypefun int gcry_mpi_invm (@w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{a}}, @w{gcry_mpi_t @var{m}}) |
3514 | 3514 | ||
3515 | Set @var{x} to the multiplicative inverse of @math{@var{a} \bmod @var{m}}. | 3515 | Set @var{x} to the multiplicative inverse of @math{@var{a} \bmod @var{m}}. |
3516 | Return true if the inverse exists. | 3516 | Return true if the inverse exists. |
3517 | @end deftypefun | 3517 | @end deftypefun |
3518 | 3518 | ||
3519 | 3519 | ||
3520 | @node Comparisons | 3520 | @node Comparisons |
3521 | @section Comparisons | 3521 | @section Comparisons |
3522 | 3522 | ||
3523 | @noindent | 3523 | @noindent |
3524 | The next 2 functions are used to compare MPIs: | 3524 | The next 2 functions are used to compare MPIs: |
3525 | 3525 | ||
3526 | 3526 | ||
3527 | @deftypefun int gcry_mpi_cmp (@w{const gcry_mpi_t @var{u}}, @w{const gcry_mpi_t @var{v}}) | 3527 | @deftypefun int gcry_mpi_cmp (@w{const gcry_mpi_t @var{u}}, @w{const gcry_mpi_t @var{v}}) |
3528 | 3528 | ||
3529 | Compare the big integer number @var{u} and @var{v} returning 0 for | 3529 | Compare the big integer number @var{u} and @var{v} returning 0 for |
3530 | equality, a positive value for @var{u} > @var{v} and a negative for | 3530 | equality, a positive value for @var{u} > @var{v} and a negative for |
3531 | @var{u} < @var{v}. | 3531 | @var{u} < @var{v}. |
3532 | @end deftypefun | 3532 | @end deftypefun |
3533 | 3533 | ||
3534 | @deftypefun int gcry_mpi_cmp_ui (@w{const gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) | 3534 | @deftypefun int gcry_mpi_cmp_ui (@w{const gcry_mpi_t @var{u}}, @w{unsigned long @var{v}}) |
3535 | 3535 | ||
3536 | Compare the big integer number @var{u} with the unsigned integer @var{v} | 3536 | Compare the big integer number @var{u} with the unsigned integer @var{v} |
3537 | returning 0 for equality, a positive value for @var{u} > @var{v} and a | 3537 | returning 0 for equality, a positive value for @var{u} > @var{v} and a |
3538 | negative for @var{u} < @var{v}. | 3538 | negative for @var{u} < @var{v}. |
3539 | @end deftypefun | 3539 | @end deftypefun |
3540 | 3540 | ||
3541 | 3541 | ||
3542 | @node Bit manipulations | 3542 | @node Bit manipulations |
3543 | @section Bit manipulations | 3543 | @section Bit manipulations |
3544 | 3544 | ||
3545 | @noindent | 3545 | @noindent |
3546 | There are a couple of functions to get information on arbitrary bits | 3546 | There are a couple of functions to get information on arbitrary bits |
3547 | in an MPI and to set or clear them: | 3547 | in an MPI and to set or clear them: |
3548 | 3548 | ||
3549 | @deftypefun {unsigned int} gcry_mpi_get_nbits (@w{gcry_mpi_t @var{a}}) | 3549 | @deftypefun {unsigned int} gcry_mpi_get_nbits (@w{gcry_mpi_t @var{a}}) |
3550 | 3550 | ||
3551 | Return the number of bits required to represent @var{a}. | 3551 | Return the number of bits required to represent @var{a}. |
3552 | @end deftypefun | 3552 | @end deftypefun |
3553 | 3553 | ||
3554 | @deftypefun int gcry_mpi_test_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) | 3554 | @deftypefun int gcry_mpi_test_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) |
3555 | 3555 | ||
3556 | Return true if bit number @var{n} (counting from 0) is set in @var{a}. | 3556 | Return true if bit number @var{n} (counting from 0) is set in @var{a}. |
3557 | @end deftypefun | 3557 | @end deftypefun |
3558 | 3558 | ||
3559 | @deftypefun void gcry_mpi_set_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) | 3559 | @deftypefun void gcry_mpi_set_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) |
3560 | 3560 | ||
3561 | Set bit number @var{n} in @var{a}. | 3561 | Set bit number @var{n} in @var{a}. |
3562 | @end deftypefun | 3562 | @end deftypefun |
3563 | 3563 | ||
3564 | @deftypefun void gcry_mpi_clear_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) | 3564 | @deftypefun void gcry_mpi_clear_bit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) |
3565 | 3565 | ||
3566 | Clear bit number @var{n} in @var{a}. | 3566 | Clear bit number @var{n} in @var{a}. |
3567 | @end deftypefun | 3567 | @end deftypefun |
3568 | 3568 | ||
3569 | @deftypefun void gcry_mpi_set_highbit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) | 3569 | @deftypefun void gcry_mpi_set_highbit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) |
3570 | 3570 | ||
3571 | Set bit number @var{n} in @var{a} and clear all bits greater than @var{n}. | 3571 | Set bit number @var{n} in @var{a} and clear all bits greater than @var{n}. |
3572 | @end deftypefun | 3572 | @end deftypefun |
3573 | 3573 | ||
3574 | @deftypefun void gcry_mpi_clear_highbit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) | 3574 | @deftypefun void gcry_mpi_clear_highbit (@w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) |
3575 | 3575 | ||
3576 | Clear bit number @var{n} in @var{a} and all bits greater than @var{n}. | 3576 | Clear bit number @var{n} in @var{a} and all bits greater than @var{n}. |
3577 | @end deftypefun | 3577 | @end deftypefun |
3578 | 3578 | ||
3579 | @deftypefun void gcry_mpi_rshift (@w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) | 3579 | @deftypefun void gcry_mpi_rshift (@w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{a}}, @w{unsigned int @var{n}}) |
3580 | 3580 | ||
3581 | Shift the value of @var{a} by @var{n} bits to the right and store the | 3581 | Shift the value of @var{a} by @var{n} bits to the right and store the |
3582 | result in @var{x}. | 3582 | result in @var{x}. |
3583 | @end deftypefun | 3583 | @end deftypefun |
3584 | 3584 | ||
3585 | @node Miscellaneous | 3585 | @node Miscellaneous |
3586 | @section Miscellanous | 3586 | @section Miscellanous |
3587 | 3587 | ||
3588 | @deftypefun gcry_mpi_t gcry_mpi_set_opaque (@w{gcry_mpi_t @var{a}}, @w{void *@var{p}}, @w{unsigned int @var{nbits}}) | 3588 | @deftypefun gcry_mpi_t gcry_mpi_set_opaque (@w{gcry_mpi_t @var{a}}, @w{void *@var{p}}, @w{unsigned int @var{nbits}}) |
3589 | 3589 | ||
3590 | Store @var{nbits} of the value @var{p} points to in @var{a} and mark | 3590 | Store @var{nbits} of the value @var{p} points to in @var{a} and mark |
3591 | @var{a} as an opaque value (i.e. an value that can't be used for any | 3591 | @var{a} as an opaque value (i.e. an value that can't be used for any |
3592 | math calculation and is only used to store an arbitrary bit pattern in | 3592 | math calculation and is only used to store an arbitrary bit pattern in |
3593 | @var{a}). | 3593 | @var{a}). |
3594 | 3594 | ||
3595 | WARNING: Never use an opaque MPI for actual math operations. The only | 3595 | WARNING: Never use an opaque MPI for actual math operations. The only |
3596 | valid functions are gcry_mpi_get_opaque and gcry_mpi_release. Use | 3596 | valid functions are gcry_mpi_get_opaque and gcry_mpi_release. Use |
3597 | gcry_mpi_scan to convert a string of arbitrary bytes into an MPI. | 3597 | gcry_mpi_scan to convert a string of arbitrary bytes into an MPI. |
3598 | 3598 | ||
3599 | @end deftypefun | 3599 | @end deftypefun |
3600 | 3600 | ||
3601 | @deftypefun {void *} gcry_mpi_get_opaque (@w{gcry_mpi_t @var{a}}, @w{unsigned int *@var{nbits}}) | 3601 | @deftypefun {void *} gcry_mpi_get_opaque (@w{gcry_mpi_t @var{a}}, @w{unsigned int *@var{nbits}}) |
3602 | 3602 | ||
3603 | Return a pointer to an opaque value stored in @var{a} and return its | 3603 | Return a pointer to an opaque value stored in @var{a} and return its |
3604 | size in @var{nbits}. Note, that the returned pointer is still owned by | 3604 | size in @var{nbits}. Note, that the returned pointer is still owned by |
3605 | @var{a} and that the function should never be used for an non-opaque | 3605 | @var{a} and that the function should never be used for an non-opaque |
3606 | MPI. | 3606 | MPI. |
3607 | @end deftypefun | 3607 | @end deftypefun |
3608 | 3608 | ||
3609 | @deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) | 3609 | @deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) |
3610 | 3610 | ||
3611 | Set the @var{flag} for the MPI @var{a}. Currently only the flag | 3611 | Set the @var{flag} for the MPI @var{a}. Currently only the flag |
3612 | @code{GCRYMPI_FLAG_SECURE} is allowed to convert @var{a} into an MPI | 3612 | @code{GCRYMPI_FLAG_SECURE} is allowed to convert @var{a} into an MPI |
3613 | stored in "secure memory". | 3613 | stored in "secure memory". |
3614 | @end deftypefun | 3614 | @end deftypefun |
3615 | 3615 | ||
3616 | @deftypefun void gcry_mpi_clear_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) | 3616 | @deftypefun void gcry_mpi_clear_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) |
3617 | 3617 | ||
3618 | Clear @var{flag} for the big integer @var{a}. Note, that this function is | 3618 | Clear @var{flag} for the big integer @var{a}. Note, that this function is |
3619 | currently useless as no flags are allowed. | 3619 | currently useless as no flags are allowed. |
3620 | @end deftypefun | 3620 | @end deftypefun |
3621 | 3621 | ||
3622 | @deftypefun int gcry_mpi_get_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) | 3622 | @deftypefun int gcry_mpi_get_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) |
3623 | 3623 | ||
3624 | Return true when the @var{flag} is set for @var{a}. | 3624 | Return true when the @var{flag} is set for @var{a}. |
3625 | @end deftypefun | 3625 | @end deftypefun |
3626 | 3626 | ||
3627 | @deftypefun void gcry_mpi_randomize (@w{gcry_mpi_t @var{w}}, @w{unsigned int @var{nbits}}, @w{enum gcry_random_level @var{level}}) | 3627 | @deftypefun void gcry_mpi_randomize (@w{gcry_mpi_t @var{w}}, @w{unsigned int @var{nbits}}, @w{enum gcry_random_level @var{level}}) |
3628 | 3628 | ||
3629 | Set the big integer @var{w} to a random value of @var{nbits}, using | 3629 | Set the big integer @var{w} to a random value of @var{nbits}, using |
3630 | random data quality of level @var{level}. In case @var{nbits} is not | 3630 | random data quality of level @var{level}. In case @var{nbits} is not |
3631 | a multiple of a byte, @var{nbits} is rounded up to the next byte | 3631 | a multiple of a byte, @var{nbits} is rounded up to the next byte |
3632 | boundary. | 3632 | boundary. |
3633 | @end deftypefun | 3633 | @end deftypefun |
3634 | 3634 | ||
3635 | @node Utilities | 3635 | @node Utilities |
3636 | @chapter Utilities | 3636 | @chapter Utilities |
3637 | 3637 | ||
3638 | @menu | 3638 | @menu |
3639 | * Memory allocation:: Functions related with memory allocation. | 3639 | * Memory allocation:: Functions related with memory allocation. |
3640 | @end menu | 3640 | @end menu |
3641 | 3641 | ||
3642 | @node Memory allocation | 3642 | @node Memory allocation |
3643 | @section Memory allocation | 3643 | @section Memory allocation |
3644 | 3644 | ||
3645 | @deftypefun void *gcry_malloc (size_t @var{n}) | 3645 | @deftypefun void *gcry_malloc (size_t @var{n}) |
3646 | 3646 | ||
3647 | This function tries to allocate @var{n} bytes of memory. On success | 3647 | This function tries to allocate @var{n} bytes of memory. On success |
3648 | it returns a pointer to the memory area, in an out-of-core condition, | 3648 | it returns a pointer to the memory area, in an out-of-core condition, |
3649 | it returns NULL. | 3649 | it returns NULL. |
3650 | @end deftypefun | 3650 | @end deftypefun |
3651 | 3651 | ||
3652 | @deftypefun void *gcry_malloc_secure (size_t @var{n}) | 3652 | @deftypefun void *gcry_malloc_secure (size_t @var{n}) |
3653 | Like @code{gcry_malloc}, but uses secure memory. | 3653 | Like @code{gcry_malloc}, but uses secure memory. |
3654 | @end deftypefun | 3654 | @end deftypefun |
3655 | 3655 | ||
3656 | @deftypefun void *gcry_calloc (size_t @var{n}) | 3656 | @deftypefun void *gcry_calloc (size_t @var{n}) |
3657 | 3657 | ||
3658 | This function tries to allocate @var{n} bytes of cleared memory | 3658 | This function tries to allocate @var{n} bytes of cleared memory |
3659 | (i.e. memory that is initialized with zero bytes). On success it | 3659 | (i.e. memory that is initialized with zero bytes). On success it |
3660 | returns a pointer to the memory area, in an out-of-core condition, it | 3660 | returns a pointer to the memory area, in an out-of-core condition, it |
3661 | returns NULL. | 3661 | returns NULL. |
3662 | @end deftypefun | 3662 | @end deftypefun |
3663 | 3663 | ||
3664 | @deftypefun void *gcry_calloc_secure (size_t @var{n}) | 3664 | @deftypefun void *gcry_calloc_secure (size_t @var{n}) |
3665 | Like @code{gcry_calloc}, but uses secure memory. | 3665 | Like @code{gcry_calloc}, but uses secure memory. |
3666 | @end deftypefun | 3666 | @end deftypefun |
3667 | 3667 | ||
3668 | @deftypefun void *gcry_realloc (void *@var{p}, size_t @var{n}) | 3668 | @deftypefun void *gcry_realloc (void *@var{p}, size_t @var{n}) |
3669 | 3669 | ||
3670 | This function tries to resize the memory area pointed to by @var{p} to | 3670 | This function tries to resize the memory area pointed to by @var{p} to |
3671 | @var{n} bytes. On success it returns a pointer to the new memory | 3671 | @var{n} bytes. On success it returns a pointer to the new memory |
3672 | area, in an out-of-core condition, it returns NULL. Depending on | 3672 | area, in an out-of-core condition, it returns NULL. Depending on |
3673 | whether the memory pointed to by @var{p} is secure memory or not, | 3673 | whether the memory pointed to by @var{p} is secure memory or not, |
3674 | gcry_realloc tries to use secure memory as well. | 3674 | gcry_realloc tries to use secure memory as well. |
3675 | @end deftypefun | 3675 | @end deftypefun |
3676 | 3676 | ||
3677 | @deftypefun void gcry_free (void *@var{p}) | 3677 | @deftypefun void gcry_free (void *@var{p}) |
3678 | Release the memory area pointed to by @var{p}. | 3678 | Release the memory area pointed to by @var{p}. |
3679 | @end deftypefun | 3679 | @end deftypefun |
3680 | 3680 | ||
3681 | @c ********************************************************** | 3681 | @c ********************************************************** |
3682 | @c ******************* Appendices ************************* | 3682 | @c ******************* Appendices ************************* |
3683 | @c ********************************************************** | 3683 | @c ********************************************************** |
3684 | 3684 | ||
3685 | @include lgpl.texi | 3685 | @include lgpl.texi |
3686 | 3686 | ||
3687 | @include gpl.texi | 3687 | @include gpl.texi |
3688 | 3688 | ||
3689 | @node Concept Index | 3689 | @node Concept Index |
3690 | @unnumbered Concept Index | 3690 | @unnumbered Concept Index |
3691 | 3691 | ||
3692 | @printindex cp | 3692 | @printindex cp |
3693 | 3693 | ||
3694 | @node Function and Data Index | 3694 | @node Function and Data Index |
3695 | @unnumbered Function and Data Index | 3695 | @unnumbered Function and Data Index |
3696 | 3696 | ||
3697 | @printindex fn | 3697 | @printindex fn |
3698 | 3698 | ||
3699 | @bye | 3699 | @bye |
3700 | 3700 | ||
3701 | /* Version check should be the very first gcry call because it | 3701 | /* Version check should be the very first gcry call because it |
3702 | makes sure that constructor functions are run. */ | 3702 | makes sure that constructor functions are run. */ |
3703 | if (!gcry_check_version (GCRYPT_VERSION)) | 3703 | if (!gcry_check_version (GCRYPT_VERSION)) |
3704 | die ("version mismatch\n"); | 3704 | die ("version mismatch\n"); |
3705 | /* Many applications don't require secure memory, so they should | 3705 | /* Many applications don't require secure memory, so they should |
3706 | disable it right away. There won't be a problem unless one makes | 3706 | disable it right away. There won't be a problem unless one makes |
3707 | use of a feature which requires secure memory - in that case the | 3707 | use of a feature which requires secure memory - in that case the |
3708 | process would abort because the secmem is not initialized. */ | 3708 | process would abort because the secmem is not initialized. */ |
3709 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); | 3709 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); |
3710 | 3710 | ||
3711 | /* .. add whatever initialization you want, but better don't make calls | 3711 | /* .. add whatever initialization you want, but better don't make calls |
3712 | to libgcrypt from more than one thread ... */ | 3712 | to libgcrypt from more than one thread ... */ |
3713 | 3713 | ||
3714 | /* Tell Libgcrypt that initialization has completed. */ | 3714 | /* Tell Libgcrypt that initialization has completed. */ |
3715 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 3715 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
3716 | 3716 | ||
3717 | 3717 | ||
3718 | If you require secure memory, this code should be used: | 3718 | If you require secure memory, this code should be used: |
3719 | 3719 | ||
3720 | if (!gcry_check_version (GCRYPT_VERSION)) | 3720 | if (!gcry_check_version (GCRYPT_VERSION)) |
3721 | die ("version mismatch\n"); | 3721 | die ("version mismatch\n"); |
3722 | /* We don't want to see any warnings, e.g. because we have not yet | 3722 | /* We don't want to see any warnings, e.g. because we have not yet |
3723 | parsed options which might be used to suppress such warnings */ | 3723 | parsed options which might be used to suppress such warnings */ |
3724 | gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); | 3724 | gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); |
3725 | 3725 | ||
3726 | /* ... */ | 3726 | /* ... */ |
3727 | 3727 | ||
3728 | /* Allocate a pool of 16k secure memory. This also drops priviliges | 3728 | /* Allocate a pool of 16k secure memory. This also drops priviliges |
3729 | on some systems. */ | 3729 | on some systems. */ |
3730 | gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); | 3730 | gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); |
3731 | 3731 | ||
3732 | /* It is now okay to let Libgcrypt complain when there was/is a problem | 3732 | /* It is now okay to let Libgcrypt complain when there was/is a problem |
3733 | with the secure memory. */ | 3733 | with the secure memory. */ |
3734 | gcry_control (GCRYCTL_RESUME_SECMEM_WARN); | 3734 | gcry_control (GCRYCTL_RESUME_SECMEM_WARN); |
3735 | 3735 | ||
3736 | /* Tell Libgcrypt that initialization has completed. */ | 3736 | /* Tell Libgcrypt that initialization has completed. */ |
3737 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 3737 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
3738 | 3738 | ||
3739 | 3739 | ||
3740 | This sounds a bit complicated but has the advantage that the caller | 3740 | This sounds a bit complicated but has the advantage that the caller |
3741 | must decide whether he wants secure memory or not - there is no | 3741 | must decide whether he wants secure memory or not - there is no |
3742 | default. | 3742 | default. |
3743 | 3743 | ||
3744 | It is important that this initialization is not done by a library but | 3744 | It is important that this initialization is not done by a library but |
3745 | in the application. The library might want to check for finished | 3745 | in the application. The library might want to check for finished |
3746 | initialization using: | 3746 | initialization using: |
3747 | 3747 | ||
3748 | if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) | 3748 | if (!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) |
3749 | return MYLIB_ERROR_LIBGCRYPT_NOT_INITIALIZED; | 3749 | return MYLIB_ERROR_LIBGCRYPT_NOT_INITIALIZED; |
3750 | 3750 | ||
3751 | 3751 | ||
3752 | @c LocalWords: int HD | 3752 | @c LocalWords: int HD |
3753 | 3753 | ||
3754 | 3754 | ||
3755 | 3755 | ||
3756 | 3756 | ||