Botan  2.13.0
Crypto and TLS for C++11
ffi.h
Go to the documentation of this file.
1 /*
2 * FFI (C89 API)
3 * (C) 2015,2017 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_FFI_H_
9 #define BOTAN_FFI_H_
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /*
16 This header exports some of botan's functionality via a C89 interface. This API
17 is uesd by the Python, OCaml, Rust and Ruby bindings via those languages
18 respective ctypes/FFI libraries.
19 
20 The API is intended to be as easy as possible to call from other
21 languages, which often have easy ways to call C, because C. But some C
22 code is easier to deal with than others, so to make things easy this
23 API follows a few simple rules:
24 
25 - All interactions are via pointers to opaque structs. No need to worry about
26  structure padding issues and the like.
27 
28 - All functions return an int error code (except the version calls, which are
29  assumed to always have something to say).
30 
31 - Use simple types: size_t for lengths, const char* NULL terminated strings,
32  uint8_t for binary.
33 
34 - No ownership of memory transfers across the API boundary. The API will
35  consume data from const pointers, and will produce output by writing to
36  buffers provided by (and allocated by) the caller.
37 
38 - If exporting a value (a string or a blob) the function takes a pointer to the
39  output array and a read/write pointer to the length. If the length is insufficient, an
40  error is returned. So passing nullptr/0 allows querying the final value.
41 
42  Note this does not apply to all functions, like `botan_hash_final`
43  which is not idempotent and are documented specially. But it's a
44  general theory of operation.
45 
46  TODO:
47  - Doxygen comments for all functions/params
48  - TLS
49 */
50 
51 #include <botan/build.h>
52 #include <stdint.h>
53 #include <stddef.h>
54 
55 /**
56 * Error codes
57 *
58 * If you add a new value here be sure to also add it in
59 * botan_error_description
60 */
64 
67 
69 
74 
81 
84 
88 
90 };
91 
92 /**
93 * Convert an error code into a string. Returns "Unknown error"
94 * if the error code is not a known one.
95 */
96 BOTAN_PUBLIC_API(2,8) const char* botan_error_description(int err);
97 
98 /**
99 * Return the version of the currently supported FFI API. This is
100 * expressed in the form YYYYMMDD of the release date of this version
101 * of the API.
102 */
103 BOTAN_PUBLIC_API(2,0) uint32_t botan_ffi_api_version(void);
104 
105 /**
106 * Return 0 (ok) if the version given is one this library supports.
107 * botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.
108 */
109 BOTAN_PUBLIC_API(2,0) int botan_ffi_supports_api(uint32_t api_version);
110 
111 /**
112 * Return a free-form version string, e.g., 2.0.0
113 */
114 BOTAN_PUBLIC_API(2,0) const char* botan_version_string(void);
115 
116 /**
117 * Return the major version of the library
118 */
119 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_major(void);
120 
121 /**
122 * Return the minor version of the library
123 */
124 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_minor(void);
125 
126 /**
127 * Return the patch version of the library
128 */
129 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_patch(void);
130 
131 /**
132 * Return the date this version was released as
133 * an integer, or 0 if an unreleased version
134 */
135 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_datestamp(void);
136 
137 /**
138 * Returns 0 if x[0..len] == y[0..len], or otherwise -1
139 */
140 BOTAN_PUBLIC_API(2,3) int botan_constant_time_compare(const uint8_t* x, const uint8_t* y, size_t len);
141 
142 /**
143 * Deprecated equivalent to botan_constant_time_compare
144 */
145 BOTAN_PUBLIC_API(2,0) int botan_same_mem(const uint8_t* x, const uint8_t* y, size_t len);
146 
147 /**
148 * Clear out memory using a system specific approach to bypass elision by the
149 * compiler (currently using RtlSecureZeroMemory or tricks with volatile pointers).
150 */
151 BOTAN_PUBLIC_API(2,2) int botan_scrub_mem(void* mem, size_t bytes);
152 
153 #define BOTAN_FFI_HEX_LOWER_CASE 1
154 
155 /**
156 * Perform hex encoding
157 * @param x is some binary data
158 * @param len length of x in bytes
159 * @param out an array of at least x*2 bytes
160 * @param flags flags out be upper or lower case?
161 * @return 0 on success, 1 on failure
162 */
163 BOTAN_PUBLIC_API(2,0) int botan_hex_encode(const uint8_t* x, size_t len, char* out, uint32_t flags);
164 
165 /**
166 * Perform hex decoding
167 * @param hex_str a string of hex chars (whitespace is ignored)
168 * @param in_len the length of hex_str
169 * @param out the output buffer should be at least strlen(hex_str)/2 bytes
170 * @param out_len the size of out
171 */
172 BOTAN_PUBLIC_API(2,3) int botan_hex_decode(const char* hex_str, size_t in_len, uint8_t* out, size_t* out_len);
173 
174 /**
175 * Perform base64 encoding
176 */
177 BOTAN_PUBLIC_API(2,3) int botan_base64_encode(const uint8_t* x, size_t len, char* out, size_t* out_len);
178 
179 
180 /**
181 * Perform base64 decoding
182 */
183 BOTAN_PUBLIC_API(2,3) int botan_base64_decode(const char* base64_str, size_t in_len,
184  uint8_t* out, size_t* out_len);
185 
186 /**
187 * RNG type
188 */
189 typedef struct botan_rng_struct* botan_rng_t;
190 
191 /**
192 * Initialize a random number generator object
193 * @param rng rng object
194 * @param rng_type type of the rng, possible values:
195 * "system": system RNG
196 * "user": userspace RNG
197 * "user-threadsafe": userspace RNG, with internal locking
198 * "rdrand": directly read RDRAND
199 * Set rng_type to null to let the library choose some default.
200 */
201 BOTAN_PUBLIC_API(2,0) int botan_rng_init(botan_rng_t* rng, const char* rng_type);
202 
203 /**
204 * Get random bytes from a random number generator
205 * @param rng rng object
206 * @param out output buffer of size out_len
207 * @param out_len number of requested bytes
208 * @return 0 on success, negative on failure
209 */
210 BOTAN_PUBLIC_API(2,0) int botan_rng_get(botan_rng_t rng, uint8_t* out, size_t out_len);
211 
212 /**
213 * Reseed a random number generator
214 * Uses the System_RNG as a seed generator.
215 *
216 * @param rng rng object
217 * @param bits number of bits to to reseed with
218 * @return 0 on success, a negative value on failure
219 */
220 BOTAN_PUBLIC_API(2,0) int botan_rng_reseed(botan_rng_t rng, size_t bits);
221 
222 /**
223 * Reseed a random number generator
224 *
225 * @param rng rng object
226 * @param source_rng the rng that will be read from
227 * @param bits number of bits to to reseed with
228 * @return 0 on success, a negative value on failure
229 */
230 BOTAN_PUBLIC_API(2,8) int botan_rng_reseed_from_rng(botan_rng_t rng,
231  botan_rng_t source_rng,
232  size_t bits);
233 
234 /**
235 * Add some seed material to a random number generator
236 *
237 * @param rng rng object
238 * @param entropy the data to add
239 * @param entropy_len length of entropy buffer
240 * @return 0 on success, a negative value on failure
241 */
242 BOTAN_PUBLIC_API(2,8) int botan_rng_add_entropy(botan_rng_t rng,
243  const uint8_t* entropy,
244  size_t entropy_len);
245 
246 /**
247 * Frees all resources of the random number generator object
248 * @param rng rng object
249 * @return 0 if success, error if invalid object handle
250 */
251 BOTAN_PUBLIC_API(2,0) int botan_rng_destroy(botan_rng_t rng);
252 
253 /*
254 * Hash type
255 */
256 typedef struct botan_hash_struct* botan_hash_t;
257 
258 /**
259 * Initialize a hash function object
260 * @param hash hash object
261 * @param hash_name name of the hash function, e.g., "SHA-384"
262 * @param flags should be 0 in current API revision, all other uses are reserved
263 * and return BOTAN_FFI_ERROR_BAD_FLAG
264 */
265 BOTAN_PUBLIC_API(2,0) int botan_hash_init(botan_hash_t* hash, const char* hash_name, uint32_t flags);
266 
267 /**
268 * Copy the state of a hash function object
269 * @param dest destination hash object
270 * @param source source hash object
271 * @return 0 on success, a negative value on failure
272 */
273 BOTAN_PUBLIC_API(2,2) int botan_hash_copy_state(botan_hash_t *dest, const botan_hash_t source);
274 
275 /**
276 * Writes the output length of the hash function to *output_length
277 * @param hash hash object
278 * @param output_length output buffer to hold the hash function output length
279 * @return 0 on success, a negative value on failure
280 */
281 BOTAN_PUBLIC_API(2,0) int botan_hash_output_length(botan_hash_t hash, size_t* output_length);
282 
283 /**
284 * Writes the block size of the hash function to *block_size
285 * @param hash hash object
286 * @param block_size output buffer to hold the hash function output length
287 * @return 0 on success, a negative value on failure
288 */
289 BOTAN_PUBLIC_API(2,2) int botan_hash_block_size(botan_hash_t hash, size_t* block_size);
290 
291 /**
292 * Send more input to the hash function
293 * @param hash hash object
294 * @param in input buffer
295 * @param in_len number of bytes to read from the input buffer
296 * @return 0 on success, a negative value on failure
297 */
298 BOTAN_PUBLIC_API(2,0) int botan_hash_update(botan_hash_t hash, const uint8_t* in, size_t in_len);
299 
300 /**
301 * Finalizes the hash computation and writes the output to
302 * out[0:botan_hash_output_length()] then reinitializes for computing
303 * another digest as if botan_hash_clear had been called.
304 * @param hash hash object
305 * @param out output buffer
306 * @return 0 on success, a negative value on failure
307 */
308 BOTAN_PUBLIC_API(2,0) int botan_hash_final(botan_hash_t hash, uint8_t out[]);
309 
310 /**
311 * Reinitializes the state of the hash computation. A hash can
312 * be computed (with update/final) immediately.
313 * @param hash hash object
314 * @return 0 on success, a negative value on failure
315 */
316 BOTAN_PUBLIC_API(2,0) int botan_hash_clear(botan_hash_t hash);
317 
318 /**
319 * Frees all resources of the hash object
320 * @param hash hash object
321 * @return 0 if success, error if invalid object handle
322 */
323 BOTAN_PUBLIC_API(2,0) int botan_hash_destroy(botan_hash_t hash);
324 
325 /**
326 * Get the name of this hash function
327 * @param hash the object to read
328 * @param name output buffer
329 * @param name_len on input, the length of buffer, on success the number of bytes written
330 */
331 BOTAN_PUBLIC_API(2,8) int botan_hash_name(botan_hash_t hash, char* name, size_t* name_len);
332 
333 /*
334 * Message Authentication type
335 */
336 typedef struct botan_mac_struct* botan_mac_t;
337 
338 /**
339 * Initialize a message authentication code object
340 * @param mac mac object
341 * @param mac_name name of the hash function, e.g., "HMAC(SHA-384)"
342 * @param flags should be 0 in current API revision, all other uses are reserved
343 * and return a negative value (error code)
344 * @return 0 on success, a negative value on failure
345 */
346 BOTAN_PUBLIC_API(2,0) int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags);
347 
348 /**
349 * Writes the output length of the message authentication code to *output_length
350 * @param mac mac object
351 * @param output_length output buffer to hold the MAC output length
352 * @return 0 on success, a negative value on failure
353 */
354 BOTAN_PUBLIC_API(2,0) int botan_mac_output_length(botan_mac_t mac, size_t* output_length);
355 
356 /**
357 * Sets the key on the MAC
358 * @param mac mac object
359 * @param key buffer holding the key
360 * @param key_len size of the key buffer in bytes
361 * @return 0 on success, a negative value on failure
362 */
363 BOTAN_PUBLIC_API(2,0) int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len);
364 
365 /**
366 * Send more input to the message authentication code
367 * @param mac mac object
368 * @param buf input buffer
369 * @param len number of bytes to read from the input buffer
370 * @return 0 on success, a negative value on failure
371 */
372 BOTAN_PUBLIC_API(2,0) int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len);
373 
374 /**
375 * Finalizes the MAC computation and writes the output to
376 * out[0:botan_mac_output_length()] then reinitializes for computing
377 * another MAC as if botan_mac_clear had been called.
378 * @param mac mac object
379 * @param out output buffer
380 * @return 0 on success, a negative value on failure
381 */
382 BOTAN_PUBLIC_API(2,0) int botan_mac_final(botan_mac_t mac, uint8_t out[]);
383 
384 /**
385 * Reinitializes the state of the MAC computation. A MAC can
386 * be computed (with update/final) immediately.
387 * @param mac mac object
388 * @return 0 on success, a negative value on failure
389 */
390 BOTAN_PUBLIC_API(2,0) int botan_mac_clear(botan_mac_t mac);
391 
392 /**
393 * Get the name of this MAC
394 * @param mac the object to read
395 * @param name output buffer
396 * @param name_len on input, the length of buffer, on success the number of bytes written
397 */
398 BOTAN_PUBLIC_API(2,8) int botan_mac_name(botan_mac_t mac, char* name, size_t* name_len);
399 
400 /**
401 * Get the key length limits of this auth code
402 * @param mac the object to read
403 * @param out_minimum_keylength if non-NULL, will be set to minimum keylength of MAC
404 * @param out_maximum_keylength if non-NULL, will be set to maximum keylength of MAC
405 * @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys
406 */
407 BOTAN_PUBLIC_API(2,8) int botan_mac_get_keyspec(botan_mac_t mac,
408  size_t* out_minimum_keylength,
409  size_t* out_maximum_keylength,
410  size_t* out_keylength_modulo);
411 
412 /**
413 * Frees all resources of the MAC object
414 * @param mac mac object
415 * @return 0 if success, error if invalid object handle
416 */
417 BOTAN_PUBLIC_API(2,0) int botan_mac_destroy(botan_mac_t mac);
418 
419 /*
420 * Cipher modes
421 */
422 typedef struct botan_cipher_struct* botan_cipher_t;
423 
424 #define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION 1
425 #define BOTAN_CIPHER_INIT_FLAG_ENCRYPT 0
426 #define BOTAN_CIPHER_INIT_FLAG_DECRYPT 1
427 
428 /**
429 * Initialize a cipher object
430 */
431 BOTAN_PUBLIC_API(2,0) int botan_cipher_init(botan_cipher_t* cipher, const char* name, uint32_t flags);
432 
433 /**
434 * Return the name of the cipher object
435 */
436 BOTAN_PUBLIC_API(2,8) int botan_cipher_name(botan_cipher_t cipher, char* name, size_t* name_len);
437 
438 /**
439 * Return the output length of this cipher, for a particular input length.
440 */
441 BOTAN_PUBLIC_API(2,8) int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t* out_len);
442 
443 /**
444 * Return if the specified nonce length is valid for this cipher
445 */
446 BOTAN_PUBLIC_API(2,0) int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl);
447 
448 /**
449 * Get the tag length of the cipher (0 for non-AEAD modes)
450 */
451 BOTAN_PUBLIC_API(2,0) int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t* tag_size);
452 
453 /**
454 * Get the default nonce length of this cipher
455 */
456 BOTAN_PUBLIC_API(2,0) int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t* nl);
457 
458 /**
459 * Return the update granularity of the cipher; botan_cipher_update must be
460 * called with blocks of this size, except for the final.
461 */
462 BOTAN_PUBLIC_API(2,0) int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t* ug);
463 
464 /**
465 * Get information about the key lengths. Prefer botan_cipher_get_keyspec
466 */
467 BOTAN_PUBLIC_API(2,0) int botan_cipher_query_keylen(botan_cipher_t,
468  size_t* out_minimum_keylength,
469  size_t* out_maximum_keylength);
470 
471 /**
472 * Get information about the supported key lengths.
473 */
474 BOTAN_PUBLIC_API(2,8) int botan_cipher_get_keyspec(botan_cipher_t,
475  size_t* min_keylen,
476  size_t* max_keylen,
477  size_t* mod_keylen);
478 
479 /**
480 * Set the key for this cipher object
481 */
482 BOTAN_PUBLIC_API(2,0) int botan_cipher_set_key(botan_cipher_t cipher,
483  const uint8_t* key, size_t key_len);
484 
485 /**
486 * Reset the message specific state for this cipher.
487 * Without resetting the keys, this resets the nonce, and any state
488 * associated with any message bits that have been processed so far.
489 *
490 * It is conceptually equivalent to calling botan_cipher_clear followed
491 * by botan_cipher_set_key with the original key.
492 */
493 BOTAN_PUBLIC_API(2,8) int botan_cipher_reset(botan_cipher_t cipher);
494 
495 /**
496 * Set the associated data. Will fail if cipher is not an AEAD
497 */
498 BOTAN_PUBLIC_API(2,0) int botan_cipher_set_associated_data(botan_cipher_t cipher,
499  const uint8_t* ad, size_t ad_len);
500 
501 /**
502 * Begin processing a new message using the provided nonce
503 */
504 BOTAN_PUBLIC_API(2,0) int botan_cipher_start(botan_cipher_t cipher,
505  const uint8_t* nonce, size_t nonce_len);
506 
507 #define BOTAN_CIPHER_UPDATE_FLAG_FINAL (1U << 0)
508 
509 /**
510 * Encrypt some data
511 */
512 BOTAN_PUBLIC_API(2,0) int botan_cipher_update(botan_cipher_t cipher,
513  uint32_t flags,
514  uint8_t output[],
515  size_t output_size,
516  size_t* output_written,
517  const uint8_t input_bytes[],
518  size_t input_size,
519  size_t* input_consumed);
520 
521 /**
522 * Reset the key, nonce, AD and all other state on this cipher object
523 */
524 BOTAN_PUBLIC_API(2,0) int botan_cipher_clear(botan_cipher_t hash);
525 
526 /**
527 * Destroy the cipher object
528 * @return 0 if success, error if invalid object handle
529 */
530 BOTAN_PUBLIC_API(2,0) int botan_cipher_destroy(botan_cipher_t cipher);
531 
532 /*
533 * Derive a key from a passphrase for a number of iterations
534 * @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
535 * @param out buffer to store the derived key, must be of out_len bytes
536 * @param out_len the desired length of the key to produce
537 * @param passphrase the password to derive the key from
538 * @param salt a randomly chosen salt
539 * @param salt_len length of salt in bytes
540 * @param iterations the number of iterations to use (use 10K or more)
541 * @return 0 on success, a negative value on failure
542 *
543 * Deprecated: use
544 * botan_pwdhash(pbkdf_algo, iterations, 0, 0, out, out_len,
545 * passphrase, 0, salt, salt_len);
546 */
547 BOTAN_PUBLIC_API(2,0) int
548 BOTAN_DEPRECATED("Use botan_pwdhash")
549 botan_pbkdf(const char* pbkdf_algo,
550  uint8_t out[], size_t out_len,
551  const char* passphrase,
552  const uint8_t salt[], size_t salt_len,
553  size_t iterations);
554 
555 /**
556 * Derive a key from a passphrase, running until msec time has elapsed.
557 * @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
558 * @param out buffer to store the derived key, must be of out_len bytes
559 * @param out_len the desired length of the key to produce
560 * @param passphrase the password to derive the key from
561 * @param salt a randomly chosen salt
562 * @param salt_len length of salt in bytes
563 * @param milliseconds_to_run if iterations is zero, then instead the PBKDF is
564 * run until milliseconds_to_run milliseconds has passed
565 * @param out_iterations_used set to the number iterations executed
566 * @return 0 on success, a negative value on failure
567 *
568 * Deprecated: use
569 *
570 * botan_pwdhash_timed(pbkdf_algo,
571 * static_cast<uint32_t>(ms_to_run),
572 * iterations_used,
573 * nullptr,
574 * nullptr,
575 * out, out_len,
576 * password, 0,
577 * salt, salt_len);
578 */
579 BOTAN_PUBLIC_API(2,0) int botan_pbkdf_timed(const char* pbkdf_algo,
580  uint8_t out[], size_t out_len,
581  const char* passphrase,
582  const uint8_t salt[], size_t salt_len,
583  size_t milliseconds_to_run,
584  size_t* out_iterations_used);
585 
586 
587 /*
588 * Derive a key from a passphrase
589 * @param algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)" or "Scrypt"
590 * @param param1 the first PBKDF algorithm parameter
591 * @param param2 the second PBKDF algorithm parameter (may be zero if unneeded)
592 * @param param3 the third PBKDF algorithm parameter (may be zero if unneeded)
593 * @param out buffer to store the derived key, must be of out_len bytes
594 * @param out_len the desired length of the key to produce
595 * @param passphrase the password to derive the key from
596 * @param passphrase_len if > 0, specifies length of password. If len == 0, then
597 * strlen will be called on passphrase to compute the length.
598 * @param salt a randomly chosen salt
599 * @param salt_len length of salt in bytes
600 * @return 0 on success, a negative value on failure
601 */
603  const char* algo,
604  size_t param1,
605  size_t param2,
606  size_t param3,
607  uint8_t out[],
608  size_t out_len,
609  const char* passphrase,
610  size_t passphrase_len,
611  const uint8_t salt[],
612  size_t salt_len);
613 
614 /*
615 * Derive a key from a passphrase
616 * @param pbkdf_algo PBKDF algorithm, e.g., "Scrypt" or "PBKDF2(SHA-256)"
617 * @param msec the desired runtime in milliseconds
618 * @param param1 will be set to the first password hash parameter
619 * @param param2 will be set to the second password hash parameter
620 * @param param3 will be set to the third password hash parameter
621 * @param out buffer to store the derived key, must be of out_len bytes
622 * @param out_len the desired length of the key to produce
623 * @param passphrase the password to derive the key from
624 * @param passphrase_len if > 0, specifies length of password. If len == 0, then
625 * strlen will be called on passphrase to compute the length.
626 * @param salt a randomly chosen salt
627 * @param salt_len length of salt in bytes
628 * @return 0 on success, a negative value on failure
629 */
630 int BOTAN_PUBLIC_API(2,8) botan_pwdhash_timed(
631  const char* algo,
632  uint32_t msec,
633  size_t* param1,
634  size_t* param2,
635  size_t* param3,
636  uint8_t out[],
637  size_t out_len,
638  const char* passphrase,
639  size_t passphrase_len,
640  const uint8_t salt[],
641  size_t salt_len);
642 
643 /**
644 * Derive a key using scrypt
645 * Deprecated; use
646 * botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
647 */
648 BOTAN_PUBLIC_API(2,8) int
649 BOTAN_DEPRECATED("Use botan_pwdhash")
650 botan_scrypt(uint8_t out[], size_t out_len,
651  const char* passphrase,
652  const uint8_t salt[], size_t salt_len,
653  size_t N, size_t r, size_t p);
654 
655 /**
656 * Derive a key
657 * @param kdf_algo KDF algorithm, e.g., "SP800-56C"
658 * @param out buffer holding the derived key, must be of length out_len
659 * @param out_len the desired output length in bytes
660 * @param secret the secret input
661 * @param secret_len size of secret in bytes
662 * @param salt a diversifier
663 * @param salt_len size of salt in bytes
664 * @param label purpose for the derived keying material
665 * @param label_len size of label in bytes
666 * @return 0 on success, a negative value on failure
667 */
668 BOTAN_PUBLIC_API(2,0) int botan_kdf(const char* kdf_algo,
669  uint8_t out[], size_t out_len,
670  const uint8_t secret[], size_t secret_len,
671  const uint8_t salt[], size_t salt_len,
672  const uint8_t label[], size_t label_len);
673 
674 /*
675 * Raw Block Cipher (PRP) interface
676 */
677 typedef struct botan_block_cipher_struct* botan_block_cipher_t;
678 
679 /**
680 * Initialize a block cipher object
681 */
682 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_init(botan_block_cipher_t* bc,
683  const char* cipher_name);
684 
685 /**
686 * Destroy a block cipher object
687 * @return 0 if success, error if invalid object handle
688 */
689 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_destroy(botan_block_cipher_t bc);
690 
691 /**
692 * Reinitializes the block cipher
693 * @return 0 on success, a negative value on failure
694 */
695 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_clear(botan_block_cipher_t bc);
696 
697 /**
698 * Set the key for a block cipher instance
699 */
700 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_set_key(botan_block_cipher_t bc,
701  const uint8_t key[], size_t len);
702 
703 /**
704 * Return the positive block size of this block cipher, or negative to
705 * indicate an error
706 */
707 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_block_size(botan_block_cipher_t bc);
708 
709 /**
710 * Encrypt one or more blocks with the cipher
711 */
712 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc,
713  const uint8_t in[],
714  uint8_t out[],
715  size_t blocks);
716 
717 /**
718 * Decrypt one or more blocks with the cipher
719 */
720 BOTAN_PUBLIC_API(2,1) int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc,
721  const uint8_t in[],
722  uint8_t out[],
723  size_t blocks);
724 
725 /**
726 * Get the name of this block cipher
727 * @param cipher the object to read
728 * @param name output buffer
729 * @param name_len on input, the length of buffer, on success the number of bytes written
730 */
731 BOTAN_PUBLIC_API(2,8) int botan_block_cipher_name(botan_block_cipher_t cipher,
732  char* name, size_t* name_len);
733 
734 
735 /**
736 * Get the key length limits of this block cipher
737 * @param cipher the object to read
738 * @param out_minimum_keylength if non-NULL, will be set to minimum keylength of cipher
739 * @param out_maximum_keylength if non-NULL, will be set to maximum keylength of cipher
740 * @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys
741 */
742 BOTAN_PUBLIC_API(2,8) int botan_block_cipher_get_keyspec(botan_block_cipher_t cipher,
743  size_t* out_minimum_keylength,
744  size_t* out_maximum_keylength,
745  size_t* out_keylength_modulo);
746 
747 /*
748 * Multiple precision integers (MPI)
749 */
750 typedef struct botan_mp_struct* botan_mp_t;
751 
752 /**
753 * Initialize an MPI
754 */
755 BOTAN_PUBLIC_API(2,1) int botan_mp_init(botan_mp_t* mp);
756 
757 /**
758 * Destroy (deallocate) an MPI
759 * @return 0 if success, error if invalid object handle
760 */
761 BOTAN_PUBLIC_API(2,1) int botan_mp_destroy(botan_mp_t mp);
762 
763 /**
764 * Convert the MPI to a hex string. Writes botan_mp_num_bytes(mp)*2 + 1 bytes
765 */
766 BOTAN_PUBLIC_API(2,1) int botan_mp_to_hex(const botan_mp_t mp, char* out);
767 
768 /**
769 * Convert the MPI to a string. Currently base == 10 and base == 16 are supported.
770 */
771 BOTAN_PUBLIC_API(2,1) int botan_mp_to_str(const botan_mp_t mp, uint8_t base, char* out, size_t* out_len);
772 
773 /**
774 * Set the MPI to zero
775 */
776 BOTAN_PUBLIC_API(2,1) int botan_mp_clear(botan_mp_t mp);
777 
778 /**
779 * Set the MPI value from an int
780 */
781 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_int(botan_mp_t mp, int initial_value);
782 
783 /**
784 * Set the MPI value from another MP object
785 */
786 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_mp(botan_mp_t dest, const botan_mp_t source);
787 
788 /**
789 * Set the MPI value from a string
790 */
791 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_str(botan_mp_t dest, const char* str);
792 
793 /**
794 * Set the MPI value from a string with arbitrary radix.
795 * For arbitrary being 10 or 16.
796 */
797 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_radix_str(botan_mp_t dest, const char* str, size_t radix);
798 
799 /**
800 * Return the number of significant bits in the MPI
801 */
802 BOTAN_PUBLIC_API(2,1) int botan_mp_num_bits(const botan_mp_t n, size_t* bits);
803 
804 /**
805 * Return the number of significant bytes in the MPI
806 */
807 BOTAN_PUBLIC_API(2,1) int botan_mp_num_bytes(const botan_mp_t n, size_t* bytes);
808 
809 /*
810 * Convert the MPI to a big-endian binary string. Writes botan_mp_num_bytes to vec
811 */
812 BOTAN_PUBLIC_API(2,1) int botan_mp_to_bin(const botan_mp_t mp, uint8_t vec[]);
813 
814 /*
815 * Set an MP to the big-endian binary value
816 */
817 BOTAN_PUBLIC_API(2,1) int botan_mp_from_bin(const botan_mp_t mp, const uint8_t vec[], size_t vec_len);
818 
819 /*
820 * Convert the MPI to a uint32_t, if possible. Fails if MPI is negative or too large.
821 */
822 BOTAN_PUBLIC_API(2,1) int botan_mp_to_uint32(const botan_mp_t mp, uint32_t* val);
823 
824 /**
825 * This function should have been named mp_is_non_negative. Returns 1
826 * iff mp is greater than *or equal to* zero. Use botan_mp_is_negative
827 * to detect negative numbers, botan_mp_is_zero to check for zero.
828 */
829 BOTAN_PUBLIC_API(2,1) int botan_mp_is_positive(const botan_mp_t mp);
830 
831 /**
832 * Return 1 iff mp is less than 0
833 */
834 BOTAN_PUBLIC_API(2,1) int botan_mp_is_negative(const botan_mp_t mp);
835 
836 BOTAN_PUBLIC_API(2,1) int botan_mp_flip_sign(botan_mp_t mp);
837 
838 BOTAN_PUBLIC_API(2,1) int botan_mp_is_zero(const botan_mp_t mp);
839 
840 BOTAN_PUBLIC_API(2,1) BOTAN_DEPRECATED("Use botan_mp_get_bit(0)")
841 int botan_mp_is_odd(const botan_mp_t mp);
842 BOTAN_PUBLIC_API(2,1) BOTAN_DEPRECATED("Use botan_mp_get_bit(0)")
843 int botan_mp_is_even(const botan_mp_t mp);
844 
845 BOTAN_PUBLIC_API(2,8) int botan_mp_add_u32(botan_mp_t result, const botan_mp_t x, uint32_t y);
846 BOTAN_PUBLIC_API(2,8) int botan_mp_sub_u32(botan_mp_t result, const botan_mp_t x, uint32_t y);
847 
848 BOTAN_PUBLIC_API(2,1) int botan_mp_add(botan_mp_t result, const botan_mp_t x, const botan_mp_t y);
849 BOTAN_PUBLIC_API(2,1) int botan_mp_sub(botan_mp_t result, const botan_mp_t x, const botan_mp_t y);
850 BOTAN_PUBLIC_API(2,1) int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y);
851 
852 BOTAN_PUBLIC_API(2,1) int botan_mp_div(botan_mp_t quotient,
853  botan_mp_t remainder,
854  const botan_mp_t x, const botan_mp_t y);
855 
856 BOTAN_PUBLIC_API(2,1) int botan_mp_mod_mul(botan_mp_t result, const botan_mp_t x,
857  const botan_mp_t y, const botan_mp_t mod);
858 
859 /*
860 * Returns 0 if x != y
861 * Returns 1 if x == y
862 * Returns negative number on error
863 */
864 BOTAN_PUBLIC_API(2,1) int botan_mp_equal(const botan_mp_t x, const botan_mp_t y);
865 
866 /*
867 * Sets *result to comparison result:
868 * -1 if x < y, 0 if x == y, 1 if x > y
869 * Returns negative number on error or zero on success
870 */
871 BOTAN_PUBLIC_API(2,1) int botan_mp_cmp(int* result, const botan_mp_t x, const botan_mp_t y);
872 
873 /*
874 * Swap two botan_mp_t
875 */
876 BOTAN_PUBLIC_API(2,1) int botan_mp_swap(botan_mp_t x, botan_mp_t y);
877 
878 /* Return (base^exponent) % modulus */
879 BOTAN_PUBLIC_API(2,1) int botan_mp_powmod(botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus);
880 
881 BOTAN_PUBLIC_API(2,1) int botan_mp_lshift(botan_mp_t out, const botan_mp_t in, size_t shift);
882 BOTAN_PUBLIC_API(2,1) int botan_mp_rshift(botan_mp_t out, const botan_mp_t in, size_t shift);
883 
884 BOTAN_PUBLIC_API(2,1) int botan_mp_mod_inverse(botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus);
885 
886 BOTAN_PUBLIC_API(2,1) int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits);
887 
888 BOTAN_PUBLIC_API(2,1) int botan_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng,
889  const botan_mp_t lower_bound, const botan_mp_t upper_bound);
890 
891 BOTAN_PUBLIC_API(2,1) int botan_mp_gcd(botan_mp_t out, const botan_mp_t x, const botan_mp_t y);
892 
893 /**
894 * Returns 0 if n is not prime
895 * Returns 1 if n is prime
896 * Returns negative number on error
897 */
898 BOTAN_PUBLIC_API(2,1) int botan_mp_is_prime(const botan_mp_t n, botan_rng_t rng, size_t test_prob);
899 
900 /**
901 * Returns 0 if specified bit of n is not set
902 * Returns 1 if specified bit of n is set
903 * Returns negative number on error
904 */
905 BOTAN_PUBLIC_API(2,1) int botan_mp_get_bit(const botan_mp_t n, size_t bit);
906 
907 /**
908 * Set the specified bit
909 */
910 BOTAN_PUBLIC_API(2,1) int botan_mp_set_bit(botan_mp_t n, size_t bit);
911 
912 /**
913 * Clear the specified bit
914 */
915 BOTAN_PUBLIC_API(2,1) int botan_mp_clear_bit(botan_mp_t n, size_t bit);
916 
917 /* Bcrypt password hashing */
918 
919 /**
920 * Create a password hash using Bcrypt
921 * @param out buffer holding the password hash, should be of length 64 bytes
922 * @param out_len the desired output length in bytes
923 * @param password the password
924 * @param rng a random number generator
925 * @param work_factor how much work to do to slow down guessing attacks
926 * @param flags should be 0 in current API revision, all other uses are reserved
927 * and return BOTAN_FFI_ERROR_BAD_FLAG
928 * @return 0 on success, a negative value on failure
929 
930 * Output is formatted bcrypt $2a$...
931 */
932 BOTAN_PUBLIC_API(2,0) int botan_bcrypt_generate(uint8_t* out, size_t* out_len,
933  const char* password,
934  botan_rng_t rng,
935  size_t work_factor,
936  uint32_t flags);
937 
938 /**
939 * Check a previously created password hash
940 * @param pass the password to check against
941 * @param hash the stored hash to check against
942 * @return 0 if if this password/hash combination is valid,
943 * 1 if the combination is not valid (but otherwise well formed),
944 * negative on error
945 */
946 BOTAN_PUBLIC_API(2,0) int botan_bcrypt_is_valid(const char* pass, const char* hash);
947 
948 /*
949 * Public/private key creation, import, ...
950 */
951 typedef struct botan_privkey_struct* botan_privkey_t;
952 
953 /**
954 * Create a new private key
955 * @param key the new object will be placed here
956 * @param algo_name something like "RSA" or "ECDSA"
957 * @param algo_params is specific to the algorithm. For RSA, specifies
958 * the modulus bit length. For ECC is the name of the curve.
959 * @param rng a random number generator
960 */
961 BOTAN_PUBLIC_API(2,0) int botan_privkey_create(botan_privkey_t* key,
962  const char* algo_name,
963  const char* algo_params,
964  botan_rng_t rng);
965 
966 #define BOTAN_CHECK_KEY_EXPENSIVE_TESTS 1
967 
968 BOTAN_PUBLIC_API(2,0) int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags);
969 
970 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_create")
971 int botan_privkey_create_rsa(botan_privkey_t* key, botan_rng_t rng, size_t n_bits);
972 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_create")
973 int botan_privkey_create_ecdsa(botan_privkey_t* key, botan_rng_t rng, const char* params);
974 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_create")
975 int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, const char* params);
976 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_create")
977 int botan_privkey_create_mceliece(botan_privkey_t* key, botan_rng_t rng, size_t n, size_t t);
978 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_create")
979 int botan_privkey_create_dh(botan_privkey_t* key, botan_rng_t rng, const char* param);
980 
981 /**
982  * Generates DSA key pair. Gives to a caller control over key length
983  * and order of a subgroup 'q'.
984  *
985  * @param key handler to the resulting key
986  * @param rng initialized PRNG
987  * @param pbits length of the key in bits. Must be between in range (1024, 3072)
988  * and multiple of 64. Bit size of the prime 'p'
989  * @param qbits order of the subgroup. Must be in range (160, 256) and multiple
990  * of 8
991  *
992  * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
993  * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
994  * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
995  * `qbits'
996  * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
997  *
998 */
999 BOTAN_PUBLIC_API(2,5) int botan_privkey_create_dsa(
1000  botan_privkey_t* key,
1001  botan_rng_t rng,
1002  size_t pbits,
1003  size_t qbits);
1004 
1005 /**
1006  * Generates ElGamal key pair. Caller has a control over key length
1007  * and order of a subgroup 'q'. Function is able to use two types of
1008  * primes:
1009  * * if pbits-1 == qbits then safe primes are used for key generation
1010  * * otherwise generation uses group of prime order
1011  *
1012  * @param key handler to the resulting key
1013  * @param rng initialized PRNG
1014  * @param pbits length of the key in bits. Must be at least 1024
1015  * @param qbits order of the subgroup. Must be at least 160
1016  *
1017  * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
1018  * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
1019  * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
1020  * `qbits'
1021  * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
1022  *
1023 */
1024 BOTAN_PUBLIC_API(2,5) int botan_privkey_create_elgamal(
1025  botan_privkey_t* key,
1026  botan_rng_t rng,
1027  size_t pbits,
1028  size_t qbits);
1029 
1030 /**
1031 * Input currently assumed to be PKCS #8 structure;
1032 * Set password to NULL to indicate no encryption expected
1033 * Starting in 2.8.0, the rng parameter is unused and may be set to null
1034 */
1035 BOTAN_PUBLIC_API(2,0) int botan_privkey_load(botan_privkey_t* key,
1036  botan_rng_t rng,
1037  const uint8_t bits[], size_t len,
1038  const char* password);
1039 
1040 /**
1041 * @return 0 if success, error if invalid object handle
1042 */
1043 BOTAN_PUBLIC_API(2,0) int botan_privkey_destroy(botan_privkey_t key);
1044 
1045 #define BOTAN_PRIVKEY_EXPORT_FLAG_DER 0
1046 #define BOTAN_PRIVKEY_EXPORT_FLAG_PEM 1
1047 
1048 /**
1049 * On input *out_len is number of bytes in out[]
1050 * On output *out_len is number of bytes written (or required)
1051 * If out is not big enough no output is written, *out_len is set and 1 is returned
1052 * Returns 0 on success and sets
1053 * If some other error occurs a negative integer is returned.
1054 */
1055 BOTAN_PUBLIC_API(2,0) int botan_privkey_export(botan_privkey_t key,
1056  uint8_t out[], size_t* out_len,
1057  uint32_t flags);
1058 
1059 BOTAN_PUBLIC_API(2,8) int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t* out_len);
1060 
1061 /**
1062 * Set encryption_algo to NULL or "" to have the library choose a default (recommended)
1063 */
1064 BOTAN_DEPRECATED("Use botan_privkey_export_encrypted_pbkdf_{msec,iter}")
1065 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_encrypted(botan_privkey_t key,
1066  uint8_t out[], size_t* out_len,
1067  botan_rng_t rng,
1068  const char* passphrase,
1069  const char* encryption_algo,
1070  uint32_t flags);
1071 
1072 /*
1073 * Export a private key, running PBKDF for specified amount of time
1074 * @param key the private key to export
1075 */
1076 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_encrypted_pbkdf_msec(botan_privkey_t key,
1077  uint8_t out[], size_t* out_len,
1078  botan_rng_t rng,
1079  const char* passphrase,
1080  uint32_t pbkdf_msec_runtime,
1081  size_t* pbkdf_iterations_out,
1082  const char* cipher_algo,
1083  const char* pbkdf_algo,
1084  uint32_t flags);
1085 
1086 /**
1087 * Export a private key using the specified number of iterations.
1088 */
1089 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key,
1090  uint8_t out[], size_t* out_len,
1091  botan_rng_t rng,
1092  const char* passphrase,
1093  size_t pbkdf_iterations,
1094  const char* cipher_algo,
1095  const char* pbkdf_algo,
1096  uint32_t flags);
1097 
1098 typedef struct botan_pubkey_struct* botan_pubkey_t;
1099 
1100 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t len);
1101 
1102 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_pubkey(botan_pubkey_t* out, botan_privkey_t in);
1103 
1104 BOTAN_PUBLIC_API(2,0) int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags);
1105 
1106 BOTAN_PUBLIC_API(2,0) int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len);
1107 
1108 /**
1109 * Returns 0 if key is valid, negative if invalid key or some other error
1110 */
1111 BOTAN_PUBLIC_API(2,0) int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags);
1112 
1113 BOTAN_PUBLIC_API(2,0) int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate);
1114 
1115 BOTAN_PUBLIC_API(2,0) int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash,
1116  uint8_t out[], size_t* out_len);
1117 
1118 /**
1119 * @return 0 if success, error if invalid object handle
1120 */
1121 BOTAN_PUBLIC_API(2,0) int botan_pubkey_destroy(botan_pubkey_t key);
1122 
1123 /*
1124 * Get arbitrary named fields from public or privat keys
1125 */
1126 BOTAN_PUBLIC_API(2,0) int botan_pubkey_get_field(botan_mp_t output,
1127  botan_pubkey_t key,
1128  const char* field_name);
1129 
1130 BOTAN_PUBLIC_API(2,0) int botan_privkey_get_field(botan_mp_t output,
1131  botan_privkey_t key,
1132  const char* field_name);
1133 
1134 /*
1135 * Algorithm specific key operations: RSA
1136 */
1137 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_rsa(botan_privkey_t* key,
1138  botan_mp_t p,
1139  botan_mp_t q,
1140  botan_mp_t e);
1141 
1142 BOTAN_PUBLIC_API(2,8) int botan_privkey_load_rsa_pkcs1(botan_privkey_t* key,
1143  const uint8_t bits[],
1144  size_t len);
1145 
1146 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_get_field")
1147 int botan_privkey_rsa_get_p(botan_mp_t p, botan_privkey_t rsa_key);
1148 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_get_field")
1149 int botan_privkey_rsa_get_q(botan_mp_t q, botan_privkey_t rsa_key);
1150 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_get_field")
1151 int botan_privkey_rsa_get_d(botan_mp_t d, botan_privkey_t rsa_key);
1152 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_get_field")
1153 int botan_privkey_rsa_get_n(botan_mp_t n, botan_privkey_t rsa_key);
1154 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_get_field")
1155 int botan_privkey_rsa_get_e(botan_mp_t e, botan_privkey_t rsa_key);
1156 
1157 BOTAN_PUBLIC_API(2,8) int botan_privkey_rsa_get_privkey(botan_privkey_t rsa_key,
1158  uint8_t out[], size_t* out_len,
1159  uint32_t flags);
1160 
1161 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_rsa(botan_pubkey_t* key,
1162  botan_mp_t n,
1163  botan_mp_t e);
1164 
1165 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_pubkey_get_field")
1166 int botan_pubkey_rsa_get_e(botan_mp_t e, botan_pubkey_t rsa_key);
1167 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_pubkey_get_field")
1168 int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t rsa_key);
1169 
1170 /*
1171 * Algorithm specific key operations: DSA
1172 */
1173 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_dsa(botan_privkey_t* key,
1174  botan_mp_t p,
1175  botan_mp_t q,
1176  botan_mp_t g,
1177  botan_mp_t x);
1178 
1179 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_dsa(botan_pubkey_t* key,
1180  botan_mp_t p,
1181  botan_mp_t q,
1182  botan_mp_t g,
1183  botan_mp_t y);
1184 
1185 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_privkey_get_field")
1186 int botan_privkey_dsa_get_x(botan_mp_t n, botan_privkey_t key);
1187 
1188 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_pubkey_get_field")
1189 int botan_pubkey_dsa_get_p(botan_mp_t p, botan_pubkey_t key);
1190 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_pubkey_get_field")
1191 int botan_pubkey_dsa_get_q(botan_mp_t q, botan_pubkey_t key);
1192 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_pubkey_get_field")
1193 int botan_pubkey_dsa_get_g(botan_mp_t d, botan_pubkey_t key);
1194 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Use botan_pubkey_get_field")
1195 int botan_pubkey_dsa_get_y(botan_mp_t y, botan_pubkey_t key);
1196 
1197 /*
1198 * Loads Diffie Hellman private key
1199 *
1200 * @param key variable populated with key material
1201 * @param p prime order of a Z_p group
1202 * @param g group generator
1203 * @param x private key
1204 *
1205 * @pre key is NULL on input
1206 * @post function allocates memory and assigns to `key'
1207 *
1208 * @return 0 on success, a negative value on failure
1209 */
1210 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_dh(botan_privkey_t* key,
1211  botan_mp_t p,
1212  botan_mp_t g,
1213  botan_mp_t x);
1214 /**
1215 * Loads Diffie Hellman public key
1216 *
1217 * @param key variable populated with key material
1218 * @param p prime order of a Z_p group
1219 * @param g group generator
1220 * @param y public key
1221 *
1222 * @pre key is NULL on input
1223 * @post function allocates memory and assigns to `key'
1224 *
1225 * @return 0 on success, a negative value on failure
1226 */
1227 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_dh(botan_pubkey_t* key,
1228  botan_mp_t p,
1229  botan_mp_t g,
1230  botan_mp_t y);
1231 
1232 /*
1233 * Algorithm specific key operations: ElGamal
1234 */
1235 
1236 /**
1237 * Loads ElGamal public key
1238 * @param key variable populated with key material
1239 * @param p prime order of a Z_p group
1240 * @param g group generator
1241 * @param y public key
1242 *
1243 * @pre key is NULL on input
1244 * @post function allocates memory and assigns to `key'
1245 *
1246 * @return 0 on success, a negative value on failure
1247 */
1248 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_elgamal(botan_pubkey_t* key,
1249  botan_mp_t p,
1250  botan_mp_t g,
1251  botan_mp_t y);
1252 
1253 /**
1254 * Loads ElGamal private key
1255 *
1256 * @param key variable populated with key material
1257 * @param p prime order of a Z_p group
1258 * @param g group generator
1259 * @param x private key
1260 *
1261 * @pre key is NULL on input
1262 * @post function allocates memory and assigns to `key'
1263 *
1264 * @return 0 on success, a negative value on failure
1265 */
1266 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_elgamal(botan_privkey_t* key,
1267  botan_mp_t p,
1268  botan_mp_t g,
1269  botan_mp_t x);
1270 
1271 /*
1272 * Algorithm specific key operations: Ed25519
1273 */
1274 
1275 BOTAN_PUBLIC_API(2,2) int botan_privkey_load_ed25519(botan_privkey_t* key,
1276  const uint8_t privkey[32]);
1277 
1278 BOTAN_PUBLIC_API(2,2) int botan_pubkey_load_ed25519(botan_pubkey_t* key,
1279  const uint8_t pubkey[32]);
1280 
1281 BOTAN_PUBLIC_API(2,2) int botan_privkey_ed25519_get_privkey(botan_privkey_t key,
1282  uint8_t output[64]);
1283 
1284 BOTAN_PUBLIC_API(2,2) int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key,
1285  uint8_t pubkey[32]);
1286 
1287 /*
1288 * Algorithm specific key operations: X25519
1289 */
1290 
1291 BOTAN_PUBLIC_API(2,8) int botan_privkey_load_x25519(botan_privkey_t* key,
1292  const uint8_t privkey[32]);
1293 
1294 BOTAN_PUBLIC_API(2,8) int botan_pubkey_load_x25519(botan_pubkey_t* key,
1295  const uint8_t pubkey[32]);
1296 
1297 BOTAN_PUBLIC_API(2,8) int botan_privkey_x25519_get_privkey(botan_privkey_t key,
1298  uint8_t output[32]);
1299 
1300 BOTAN_PUBLIC_API(2,8) int botan_pubkey_x25519_get_pubkey(botan_pubkey_t key,
1301  uint8_t pubkey[32]);
1302 
1303 /*
1304 * Algorithm specific key operations: ECDSA and ECDH
1305 */
1306 BOTAN_PUBLIC_API(2,2)
1307 int botan_privkey_load_ecdsa(botan_privkey_t* key,
1308  const botan_mp_t scalar,
1309  const char* curve_name);
1310 
1311 BOTAN_PUBLIC_API(2,2)
1312 int botan_pubkey_load_ecdsa(botan_pubkey_t* key,
1313  const botan_mp_t public_x,
1314  const botan_mp_t public_y,
1315  const char* curve_name);
1316 
1317 BOTAN_PUBLIC_API(2,2)
1318 int botan_pubkey_load_ecdh(botan_pubkey_t* key,
1319  const botan_mp_t public_x,
1320  const botan_mp_t public_y,
1321  const char* curve_name);
1322 
1323 BOTAN_PUBLIC_API(2,2)
1324 int botan_privkey_load_ecdh(botan_privkey_t* key,
1325  const botan_mp_t scalar,
1326  const char* curve_name);
1327 
1328 BOTAN_PUBLIC_API(2,2)
1329 int botan_pubkey_load_sm2(botan_pubkey_t* key,
1330  const botan_mp_t public_x,
1331  const botan_mp_t public_y,
1332  const char* curve_name);
1333 
1334 BOTAN_PUBLIC_API(2,2)
1335 int botan_privkey_load_sm2(botan_privkey_t* key,
1336  const botan_mp_t scalar,
1337  const char* curve_name);
1338 
1339 BOTAN_PUBLIC_API(2,2) BOTAN_DEPRECATED("Use botan_pubkey_load_sm2")
1340 int botan_pubkey_load_sm2_enc(botan_pubkey_t* key,
1341  const botan_mp_t public_x,
1342  const botan_mp_t public_y,
1343  const char* curve_name);
1344 
1345 BOTAN_PUBLIC_API(2,2) BOTAN_DEPRECATED("Use botan_privkey_load_sm2")
1346 int botan_privkey_load_sm2_enc(botan_privkey_t* key,
1347  const botan_mp_t scalar,
1348  const char* curve_name);
1349 
1350 BOTAN_PUBLIC_API(2,3)
1351 int botan_pubkey_sm2_compute_za(uint8_t out[],
1352  size_t* out_len,
1353  const char* ident,
1354  const char* hash_algo,
1355  const botan_pubkey_t key);
1356 
1357 /*
1358 * Public Key Encryption
1359 */
1360 typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t;
1361 
1362 BOTAN_PUBLIC_API(2,0) int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t* op,
1363  botan_pubkey_t key,
1364  const char* padding,
1365  uint32_t flags);
1366 
1367 /**
1368 * @return 0 if success, error if invalid object handle
1369 */
1370 BOTAN_PUBLIC_API(2,0) int botan_pk_op_encrypt_destroy(botan_pk_op_encrypt_t op);
1371 
1372 BOTAN_PUBLIC_API(2,8) int botan_pk_op_encrypt_output_length(botan_pk_op_encrypt_t op,
1373  size_t ptext_len,
1374  size_t* ctext_len);
1375 
1376 BOTAN_PUBLIC_API(2,0) int botan_pk_op_encrypt(botan_pk_op_encrypt_t op,
1377  botan_rng_t rng,
1378  uint8_t out[],
1379  size_t* out_len,
1380  const uint8_t plaintext[],
1381  size_t plaintext_len);
1382 
1383 /*
1384 * Public Key Decryption
1385 */
1386 typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t;
1387 
1388 BOTAN_PUBLIC_API(2,0) int botan_pk_op_decrypt_create(botan_pk_op_decrypt_t* op,
1389  botan_privkey_t key,
1390  const char* padding,
1391  uint32_t flags);
1392 
1393 /**
1394 * @return 0 if success, error if invalid object handle
1395 */
1396 BOTAN_PUBLIC_API(2,0) int botan_pk_op_decrypt_destroy(botan_pk_op_decrypt_t op);
1397 
1398 BOTAN_PUBLIC_API(2,8) int botan_pk_op_decrypt_output_length(botan_pk_op_decrypt_t op,
1399  size_t ctext_len,
1400  size_t* ptext_len);
1401 
1402 BOTAN_PUBLIC_API(2,0) int botan_pk_op_decrypt(botan_pk_op_decrypt_t op,
1403  uint8_t out[], size_t* out_len,
1404  const uint8_t ciphertext[], size_t ciphertext_len);
1405 
1406 /*
1407 * Signature Generation
1408 */
1409 typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t;
1410 
1411 BOTAN_PUBLIC_API(2,0)
1412 int botan_pk_op_sign_create(botan_pk_op_sign_t* op,
1413  botan_privkey_t key,
1414  const char* hash_and_padding,
1415  uint32_t flags);
1416 
1417 /**
1418 * @return 0 if success, error if invalid object handle
1419 */
1420 BOTAN_PUBLIC_API(2,0) int botan_pk_op_sign_destroy(botan_pk_op_sign_t op);
1421 
1422 BOTAN_PUBLIC_API(2,8) int botan_pk_op_sign_output_length(botan_pk_op_sign_t op, size_t* olen);
1423 
1424 BOTAN_PUBLIC_API(2,0) int botan_pk_op_sign_update(botan_pk_op_sign_t op, const uint8_t in[], size_t in_len);
1425 
1426 BOTAN_PUBLIC_API(2,0)
1427 int botan_pk_op_sign_finish(botan_pk_op_sign_t op, botan_rng_t rng,
1428  uint8_t sig[], size_t* sig_len);
1429 
1430 /*
1431 * Signature Verification
1432 */
1433 typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t;
1434 
1435 BOTAN_PUBLIC_API(2,0)
1436 int botan_pk_op_verify_create(botan_pk_op_verify_t* op,
1437  botan_pubkey_t key,
1438  const char* hash_and_padding,
1439  uint32_t flags);
1440 
1441 /**
1442 * @return 0 if success, error if invalid object handle
1443 */
1444 BOTAN_PUBLIC_API(2,0) int botan_pk_op_verify_destroy(botan_pk_op_verify_t op);
1445 
1446 BOTAN_PUBLIC_API(2,0) int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_len);
1447 BOTAN_PUBLIC_API(2,0) int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len);
1448 
1449 /*
1450 * Key Agreement
1451 */
1452 typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t;
1453 
1454 BOTAN_PUBLIC_API(2,0)
1455 int botan_pk_op_key_agreement_create(botan_pk_op_ka_t* op,
1456  botan_privkey_t key,
1457  const char* kdf,
1458  uint32_t flags);
1459 
1460 /**
1461 * @return 0 if success, error if invalid object handle
1462 */
1463 BOTAN_PUBLIC_API(2,0) int botan_pk_op_key_agreement_destroy(botan_pk_op_ka_t op);
1464 
1465 BOTAN_PUBLIC_API(2,0) int botan_pk_op_key_agreement_export_public(botan_privkey_t key,
1466  uint8_t out[], size_t* out_len);
1467 
1468 BOTAN_PUBLIC_API(2,8) int botan_pk_op_key_agreement_size(botan_pk_op_ka_t op, size_t* out_len);
1469 
1470 BOTAN_PUBLIC_API(2,0)
1471 int botan_pk_op_key_agreement(botan_pk_op_ka_t op,
1472  uint8_t out[], size_t* out_len,
1473  const uint8_t other_key[], size_t other_key_len,
1474  const uint8_t salt[], size_t salt_len);
1475 
1476 BOTAN_PUBLIC_API(2,0) int botan_pkcs_hash_id(const char* hash_name, uint8_t pkcs_id[], size_t* pkcs_id_len);
1477 
1478 
1479 /*
1480 *
1481 * @param mce_key must be a McEliece key
1482 * ct_len should be pt_len + n/8 + a few?
1483 */
1484 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Poorly specified, avoid in new code")
1485 int botan_mceies_encrypt(botan_pubkey_t mce_key,
1486  botan_rng_t rng,
1487  const char* aead,
1488  const uint8_t pt[], size_t pt_len,
1489  const uint8_t ad[], size_t ad_len,
1490  uint8_t ct[], size_t* ct_len);
1491 
1492 BOTAN_PUBLIC_API(2,0) BOTAN_DEPRECATED("Poorly specified, avoid in new code")
1493 int botan_mceies_decrypt(botan_privkey_t mce_key,
1494  const char* aead,
1495  const uint8_t ct[], size_t ct_len,
1496  const uint8_t ad[], size_t ad_len,
1497  uint8_t pt[], size_t* pt_len);
1498 
1499 /*
1500 * X.509 certificates
1501 **************************/
1502 
1503 typedef struct botan_x509_cert_struct* botan_x509_cert_t;
1504 
1505 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_load(botan_x509_cert_t* cert_obj, const uint8_t cert[], size_t cert_len);
1506 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* filename);
1507 
1508 /**
1509 * @return 0 if success, error if invalid object handle
1510 */
1511 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_destroy(botan_x509_cert_t cert);
1512 
1513 BOTAN_PUBLIC_API(2,8) int botan_x509_cert_dup(botan_x509_cert_t* new_cert, botan_x509_cert_t cert);
1514 
1515 /* Prefer botan_x509_cert_not_before and botan_x509_cert_not_after */
1516 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* out_len);
1517 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* out_len);
1518 
1519 BOTAN_PUBLIC_API(2,8) int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t* time_since_epoch);
1520 BOTAN_PUBLIC_API(2,8) int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t* time_since_epoch);
1521 
1522 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char* hash, uint8_t out[], size_t* out_len);
1523 
1524 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1525 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1526 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1527 
1528 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert,
1529  uint8_t out[], size_t* out_len);
1530 
1531 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t* key);
1532 
1533 BOTAN_PUBLIC_API(2,0)
1534 int botan_x509_cert_get_issuer_dn(botan_x509_cert_t cert,
1535  const char* key, size_t index,
1536  uint8_t out[], size_t* out_len);
1537 
1538 BOTAN_PUBLIC_API(2,0)
1539 int botan_x509_cert_get_subject_dn(botan_x509_cert_t cert,
1540  const char* key, size_t index,
1541  uint8_t out[], size_t* out_len);
1542 
1543 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_len);
1544 
1545 /* Must match values of Key_Constraints in key_constraints.h */
1546 enum botan_x509_cert_key_constraints {
1547  NO_CONSTRAINTS = 0,
1548  DIGITAL_SIGNATURE = 32768,
1549  NON_REPUDIATION = 16384,
1550  KEY_ENCIPHERMENT = 8192,
1551  DATA_ENCIPHERMENT = 4096,
1552  KEY_AGREEMENT = 2048,
1553  KEY_CERT_SIGN = 1024,
1554  CRL_SIGN = 512,
1555  ENCIPHER_ONLY = 256,
1556  DECIPHER_ONLY = 128
1557 };
1558 
1559 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage);
1560 
1561 /**
1562 * Check if the certificate matches the specified hostname via alternative name or CN match.
1563 * RFC 5280 wildcards also supported.
1564 */
1565 BOTAN_PUBLIC_API(2,5) int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname);
1566 
1567 /**
1568 * Returns 0 if the validation was successful, 1 if validation failed,
1569 * and negative on error. A status code with details is written to
1570 * *validation_result
1571 *
1572 * Intermediates or trusted lists can be null
1573 * Trusted path can be null
1574 */
1575 BOTAN_PUBLIC_API(2,8) int botan_x509_cert_verify(
1576  int* validation_result,
1577  botan_x509_cert_t cert,
1578  const botan_x509_cert_t* intermediates,
1579  size_t intermediates_len,
1580  const botan_x509_cert_t* trusted,
1581  size_t trusted_len,
1582  const char* trusted_path,
1583  size_t required_strength,
1584  const char* hostname,
1585  uint64_t reference_time);
1586 
1587 /**
1588 * Returns a pointer to a static character string explaining the status code,
1589 * or else NULL if unknown.
1590 */
1591 BOTAN_PUBLIC_API(2,8) const char* botan_x509_cert_validation_status(int code);
1592 
1593 /*
1594 * X.509 CRL
1595 **************************/
1596 
1597 typedef struct botan_x509_crl_struct* botan_x509_crl_t;
1598 
1599 BOTAN_PUBLIC_API(2,13) int botan_x509_crl_load_file(botan_x509_crl_t* crl_obj, const char* crl_path);
1600 BOTAN_PUBLIC_API(2,13) int botan_x509_crl_load(botan_x509_crl_t* crl_obj, const uint8_t crl_bits[], size_t crl_bits_len);
1601 
1602 BOTAN_PUBLIC_API(2,13) int botan_x509_crl_destroy(botan_x509_crl_t crl);
1603 
1604 /**
1605  * Given a CRL and a certificate,
1606  * check if the certificate is revoked on that particular CRL
1607  */
1608 BOTAN_PUBLIC_API(2,13) int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert);
1609 
1610 /**
1611  * Different flavor of `botan_x509_cert_verify`, supports revocation lists.
1612  * CRLs are passed as an array, same as intermediates and trusted CAs
1613  */
1614 BOTAN_PUBLIC_API(2,13) int botan_x509_cert_verify_with_crl(
1615  int* validation_result,
1616  botan_x509_cert_t cert,
1617  const botan_x509_cert_t* intermediates,
1618  size_t intermediates_len,
1619  const botan_x509_cert_t* trusted,
1620  size_t trusted_len,
1621  const botan_x509_crl_t* crls,
1622  size_t crls_len,
1623  const char* trusted_path,
1624  size_t required_strength,
1625  const char* hostname,
1626  uint64_t reference_time);
1627 
1628 /**
1629  * Key wrapping as per RFC 3394
1630  */
1631 BOTAN_PUBLIC_API(2,2)
1632 int botan_key_wrap3394(const uint8_t key[], size_t key_len,
1633  const uint8_t kek[], size_t kek_len,
1634  uint8_t wrapped_key[], size_t *wrapped_key_len);
1635 
1636 BOTAN_PUBLIC_API(2,2)
1637 int botan_key_unwrap3394(const uint8_t wrapped_key[], size_t wrapped_key_len,
1638  const uint8_t kek[], size_t kek_len,
1639  uint8_t key[], size_t *key_len);
1640 
1641 /**
1642 * HOTP
1643 */
1644 
1645 typedef struct botan_hotp_struct* botan_hotp_t;
1646 
1647 /**
1648 * Initialize a HOTP instance
1649 */
1650 BOTAN_PUBLIC_API(2,8)
1651 int botan_hotp_init(botan_hotp_t* hotp,
1652  const uint8_t key[], size_t key_len,
1653  const char* hash_algo,
1654  size_t digits);
1655 
1656 /**
1657 * Destroy a HOTP instance
1658 * @return 0 if success, error if invalid object handle
1659 */
1660 BOTAN_PUBLIC_API(2,8)
1661 int botan_hotp_destroy(botan_hotp_t hotp);
1662 
1663 /**
1664 * Generate a HOTP code for the provided counter
1665 */
1666 BOTAN_PUBLIC_API(2,8)
1667 int botan_hotp_generate(botan_hotp_t hotp,
1668  uint32_t* hotp_code,
1669  uint64_t hotp_counter);
1670 
1671 /**
1672 * Verify a HOTP code
1673 */
1674 BOTAN_PUBLIC_API(2,8)
1675 int botan_hotp_check(botan_hotp_t hotp,
1676  uint64_t* next_hotp_counter,
1677  uint32_t hotp_code,
1678  uint64_t hotp_counter,
1679  size_t resync_range);
1680 
1681 
1682 /**
1683 * TOTP
1684 */
1685 
1686 typedef struct botan_totp_struct* botan_totp_t;
1687 
1688 /**
1689 * Initialize a TOTP instance
1690 */
1691 BOTAN_PUBLIC_API(2,8)
1692 int botan_totp_init(botan_totp_t* totp,
1693  const uint8_t key[], size_t key_len,
1694  const char* hash_algo,
1695  size_t digits,
1696  size_t time_step);
1697 
1698 /**
1699 * Destroy a TOTP instance
1700 * @return 0 if success, error if invalid object handle
1701 */
1702 BOTAN_PUBLIC_API(2,8)
1703 int botan_totp_destroy(botan_totp_t totp);
1704 
1705 /**
1706 * Generate a TOTP code for the provided timestamp
1707 * @param totp the TOTP object
1708 * @param totp_code the OTP code will be written here
1709 * @param timestamp the current local timestamp
1710 */
1711 BOTAN_PUBLIC_API(2,8)
1712 int botan_totp_generate(botan_totp_t totp,
1713  uint32_t* totp_code,
1714  uint64_t timestamp);
1715 
1716 /**
1717 * Verify a TOTP code
1718 * @param totp the TOTP object
1719 * @param totp_code the presented OTP
1720 * @param timestamp the current local timestamp
1721 * @param acceptable_clock_drift specifies the acceptable amount
1722 * of clock drift (in terms of time steps) between the two hosts.
1723 */
1724 BOTAN_PUBLIC_API(2,8)
1725 int botan_totp_check(botan_totp_t totp,
1726  uint32_t totp_code,
1727  uint64_t timestamp,
1728  size_t acceptable_clock_drift);
1729 
1730 
1731 /**
1732 * Format Preserving Encryption
1733 */
1734 
1735 typedef struct botan_fpe_struct* botan_fpe_t;
1736 
1737 #define BOTAN_FPE_FLAG_FE1_COMPAT_MODE 1
1738 
1739 BOTAN_PUBLIC_API(2,8)
1740 int botan_fpe_fe1_init(botan_fpe_t* fpe, botan_mp_t n,
1741  const uint8_t key[], size_t key_len,
1742  size_t rounds, uint32_t flags);
1743 
1744 /**
1745 * @return 0 if success, error if invalid object handle
1746 */
1747 BOTAN_PUBLIC_API(2,8)
1748 int botan_fpe_destroy(botan_fpe_t fpe);
1749 
1750 BOTAN_PUBLIC_API(2,8)
1751 int botan_fpe_encrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len);
1752 
1753 BOTAN_PUBLIC_API(2,8)
1754 int botan_fpe_decrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len);
1755 
1756 #ifdef __cplusplus
1757 }
1758 #endif
1759 
1760 #endif
int botan_mp_init(botan_mp_t *mp)
Definition: ffi_mp.cpp:20
int botan_cipher_query_keylen(botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
Definition: ffi_cipher.cpp:57
int botan_cipher_init(botan_cipher_t *cipher, const char *name, uint32_t flags)
Definition: ffi_cipher.cpp:21
int botan_mp_to_str(const botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
Definition: ffi_mp.cpp:107
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition: ffi_pkey.cpp:165
int botan_hash_clear(botan_hash_t hash)
Definition: ffi_hash.cpp:53
int botan_cipher_update(botan_cipher_t cipher, uint32_t flags, uint8_t output[], size_t output_size, size_t *output_written, const uint8_t input_bytes[], size_t input_size, size_t *input_consumed)
Definition: ffi_cipher.cpp:99
int botan_block_cipher_init(botan_block_cipher_t *bc, const char *cipher_name)
Definition: ffi_block.cpp:17
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition: ffi.cpp:237
uint32_t botan_version_datestamp(void)
Definition: ffi.cpp:235
int botan_privkey_create_rsa(botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
int botan_mp_clear(botan_mp_t mp)
Definition: ffi_mp.cpp:31
int botan_mp_sub_u32(botan_mp_t result, const botan_mp_t x, uint32_t y)
Definition: ffi_mp.cpp:169
int botan_base64_decode(const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition: ffi.cpp:278
int botan_kdf(const char *kdf_algo, uint8_t out[], size_t out_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len)
Definition: ffi_kdf.cpp:129
int botan_cipher_name(botan_cipher_t cipher, char *name, size_t *name_len)
Definition: ffi_cipher.cpp:227
int botan_mp_flip_sign(botan_mp_t mp)
Definition: ffi_mp.cpp:89
int botan_mp_to_uint32(const botan_mp_t mp, uint32_t *val)
Definition: ffi_mp.cpp:125
int botan_pubkey_load_sm2(botan_pubkey_t *key, const botan_mp_t public_x, const botan_mp_t public_y, const char *curve_name)
int botan_mp_equal(const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:200
int botan_hash_block_size(botan_hash_t hash, size_t *block_size)
Definition: ffi_hash.cpp:46
int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], size_t len)
Definition: ffi_block.cpp:50
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
BOTAN_FFI_ERROR
Definition: ffi.h:61
int botan_privkey_create_elgamal(botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
int botan_mp_is_negative(const botan_mp_t mp)
Definition: ffi_mp.cpp:79
Flags flags(Flag flags)
Definition: p11.h:858
int botan_block_cipher_get_keyspec(botan_block_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
Definition: ffi_block.cpp:97
int botan_mac_final(botan_mac_t mac, uint8_t out[])
Definition: ffi_mac.cpp:59
int botan_mac_name(botan_mac_t mac, char *name, size_t *name_len)
Definition: ffi_mac.cpp:64
int botan_mac_init(botan_mac_t *mac, const char *mac_name, uint32_t flags)
Definition: ffi_mac.cpp:17
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name)
int botan_mp_set_from_mp(botan_mp_t dest, const botan_mp_t source)
Definition: ffi_mp.cpp:74
int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t *out_len)
Definition: ffi_cipher.cpp:49
int botan_same_mem(const uint8_t *x, const uint8_t *y, size_t len)
Definition: ffi.cpp:242
int botan_mp_destroy(botan_mp_t mp)
Definition: ffi_mp.cpp:134
int botan_hash_copy_state(botan_hash_t *dest, const botan_hash_t source)
Definition: ffi_hash.cpp:76
int botan_rng_add_entropy(botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
Definition: ffi_rng.cpp:81
int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits)
Definition: ffi_mp.cpp:260
int botan_mp_add_u32(botan_mp_t result, const botan_mp_t x, uint32_t y)
Definition: ffi_mp.cpp:159
int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t *ug)
Definition: ffi_cipher.cpp:217
int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
Definition: ffi_cipher.cpp:191
int botan_pwdhash(const char *algo, size_t param1, size_t param2, size_t param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:52
int botan_mp_to_bin(const botan_mp_t mp, uint8_t vec[])
Definition: ffi_mp.cpp:120
int botan_block_cipher_destroy(botan_block_cipher_t bc)
Definition: ffi_block.cpp:37
int botan_privkey_create_mceliece(botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
int botan_bcrypt_generate(uint8_t *out, size_t *out_len, const char *password, botan_rng_t rng, size_t work_factor, uint32_t flags)
Definition: ffi_kdf.cpp:153
int botan_mac_destroy(botan_mac_t mac)
Definition: ffi_mac.cpp:34
int botan_hash_name(botan_hash_t hash, char *name, size_t *name_len)
Definition: ffi_hash.cpp:82
int botan_mp_set_from_radix_str(botan_mp_t dest, const char *str, size_t radix)
Definition: ffi_mp.cpp:56
struct botan_mac_struct * botan_mac_t
Definition: ffi.h:336
int botan_block_cipher_clear(botan_block_cipher_t bc)
Definition: ffi_block.cpp:42
int botan_mp_set_bit(botan_mp_t n, size_t bit)
Definition: ffi_mp.cpp:292
int botan_mp_mod_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y, const botan_mp_t mod)
Definition: ffi_mp.cpp:252
int botan_mac_set_key(botan_mac_t mac, const uint8_t *key, size_t key_len)
Definition: ffi_mac.cpp:39
int botan_rng_destroy(botan_rng_t rng)
Definition: ffi_rng.cpp:66
int botan_base64_encode(const uint8_t *x, size_t len, char *out, size_t *out_len)
Definition: ffi.cpp:270
int botan_mp_is_positive(const botan_mp_t mp)
Definition: ffi_mp.cpp:84
int botan_cipher_reset(botan_cipher_t cipher)
Definition: ffi_cipher.cpp:44
int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t *out_len)
Definition: ffi_pkey.cpp:126
std::string name
int botan_mac_output_length(botan_mac_t mac, size_t *output_length)
Definition: ffi_mac.cpp:44
int botan_hash_update(botan_hash_t hash, const uint8_t *in, size_t in_len)
Definition: ffi_hash.cpp:58
struct botan_mp_struct * botan_mp_t
Definition: ffi.h:750
int botan_mp_swap(botan_mp_t x, botan_mp_t y)
Definition: ffi_mp.cpp:225
int botan_hash_final(botan_hash_t hash, uint8_t out[])
Definition: ffi_hash.cpp:69
int botan_hash_output_length(botan_hash_t hash, size_t *output_length)
Definition: ffi_hash.cpp:39
int botan_mp_rshift(botan_mp_t out, const botan_mp_t in, size_t shift)
Definition: ffi_mp.cpp:242
int botan_pbkdf_timed(const char *pbkdf_algo, uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t milliseconds_to_run, size_t *out_iterations_used)
Definition: ffi_kdf.cpp:35
int botan_mp_is_even(const botan_mp_t mp)
Definition: ffi_mp.cpp:215
int botan_mp_get_bit(const botan_mp_t n, size_t bit)
Definition: ffi_mp.cpp:287
int botan_hex_encode(const uint8_t *x, size_t len, char *out, uint32_t flags)
Definition: ffi.cpp:253
int botan_mp_to_hex(const botan_mp_t mp, char *out)
Definition: ffi_mp.cpp:99
uint32_t botan_ffi_api_version(void)
Definition: ffi.cpp:196
struct botan_hash_struct * botan_hash_t
Definition: ffi.h:256
int botan_privkey_create_ecdh(botan_privkey_t *key, botan_rng_t rng, const char *params)
int botan_rng_init(botan_rng_t *rng, const char *rng_type)
Definition: ffi_rng.cpp:21
int botan_mp_sub(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:149
int botan_cipher_destroy(botan_cipher_t cipher)
Definition: ffi_cipher.cpp:34
int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t *key, size_t key_len)
Definition: ffi_cipher.cpp:82
int botan_hash_init(botan_hash_t *hash, const char *hash_name, uint32_t flags)
Definition: ffi_hash.cpp:17
int botan_mac_update(botan_mac_t mac, const uint8_t *buf, size_t len)
Definition: ffi_mac.cpp:54
int botan_hex_decode(const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition: ffi.cpp:262
size_t salt_len
Definition: x509_obj.cpp:25
int botan_hash_destroy(botan_hash_t hash)
Definition: ffi_hash.cpp:34
int botan_pwdhash_timed(const char *algo, uint32_t msec, size_t *param1, size_t *param2, size_t *param3, uint8_t out[], size_t out_len, const char *passphrase, size_t passphrase_len, const uint8_t salt[], size_t salt_len)
Definition: ffi_kdf.cpp:86
int botan_scrypt(uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
Definition: ffi_kdf.cpp:142
int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
Definition: ffi_block.cpp:78
int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl)
Definition: ffi_cipher.cpp:205
int botan_cipher_get_keyspec(botan_cipher_t, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
Definition: ffi_cipher.cpp:67
int botan_mp_set_from_int(botan_mp_t mp, int initial_value)
Definition: ffi_mp.cpp:36
struct botan_privkey_struct * botan_privkey_t
Definition: ffi.h:951
int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t *tag_size)
Definition: ffi_cipher.cpp:222
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition: ffi_pkey.cpp:26
int botan_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng, const botan_mp_t lower_bound, const botan_mp_t upper_bound)
Definition: ffi_mp.cpp:266
int botan_mp_is_zero(const botan_mp_t mp)
Definition: ffi_mp.cpp:205
int botan_privkey_create_dh(botan_privkey_t *key, botan_rng_t rng, const char *param)
int botan_mp_is_prime(const botan_mp_t n, botan_rng_t rng, size_t test_prob)
Definition: ffi_mp.cpp:281
int botan_rng_reseed(botan_rng_t rng, size_t bits)
Definition: ffi_rng.cpp:76
int botan_privkey_create_ecdsa(botan_privkey_t *key, botan_rng_t rng, const char *params)
int botan_mp_num_bytes(const botan_mp_t n, size_t *bytes)
Definition: ffi_mp.cpp:307
struct botan_block_cipher_struct * botan_block_cipher_t
Definition: ffi.h:677
int botan_block_cipher_name(botan_block_cipher_t cipher, char *name, size_t *name_len)
Definition: ffi_block.cpp:88
int botan_cipher_start(botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
Definition: ffi_cipher.cpp:88
int botan_privkey_load(botan_privkey_t *key, botan_rng_t rng, const uint8_t bits[], size_t len, const char *password)
Definition: ffi_pkey.cpp:57
int botan_scrub_mem(void *mem, size_t bytes)
Definition: ffi.cpp:247
int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks)
Definition: ffi_block.cpp:68
const char * botan_version_string(void)
Definition: ffi.cpp:227
int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:179
uint32_t botan_version_patch(void)
Definition: ffi.cpp:234
int botan_block_cipher_block_size(botan_block_cipher_t bc)
Definition: ffi_block.cpp:62
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name)
int botan_mac_get_keyspec(botan_mac_t mac, size_t *out_minimum_keylength, size_t *out_maximum_keylength, size_t *out_keylength_modulo)
Definition: ffi_mac.cpp:70
int botan_cipher_clear(botan_cipher_t hash)
Definition: ffi_cipher.cpp:39
int botan_mp_is_odd(const botan_mp_t mp)
Definition: ffi_mp.cpp:210
int botan_mp_mod_inverse(botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
Definition: ffi_mp.cpp:247
int botan_mp_add(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:139
int botan_mp_lshift(botan_mp_t out, const botan_mp_t in, size_t shift)
Definition: ffi_mp.cpp:237
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
Definition: ffi_pkey.cpp:145
int botan_mp_cmp(int *result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:220
int botan_privkey_create_dsa(botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:189
int botan_bcrypt_is_valid(const char *pass, const char *hash)
Definition: ffi_kdf.cpp:178
int botan_mac_clear(botan_mac_t mac)
Definition: ffi_mac.cpp:49
int botan_rng_get(botan_rng_t rng, uint8_t *out, size_t out_len)
Definition: ffi_rng.cpp:71
struct botan_cipher_struct * botan_cipher_t
Definition: ffi.h:422
int botan_mp_powmod(botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus)
Definition: ffi_mp.cpp:231
int botan_pbkdf(const char *pbkdf_algo, uint8_t out[], size_t out_len, const char *passphrase, const uint8_t salt[], size_t salt_len, size_t iterations)
Definition: ffi_kdf.cpp:22
int botan_mp_from_bin(const botan_mp_t mp, const uint8_t vec[], size_t vec_len)
Definition: ffi_mp.cpp:94
const char * botan_error_description(int err)
Definition: ffi.cpp:125
int botan_ffi_supports_api(uint32_t api_version)
Definition: ffi.cpp:201
int botan_mp_clear_bit(botan_mp_t n, size_t bit)
Definition: ffi_mp.cpp:297
int botan_mp_num_bits(const botan_mp_t n, size_t *bits)
Definition: ffi_mp.cpp:302
int botan_rng_reseed_from_rng(botan_rng_t rng, botan_rng_t source_rng, size_t bits)
Definition: ffi_rng.cpp:86
MechanismType hash
int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t *nl)
Definition: ffi_cipher.cpp:212
int botan_privkey_load_sm2(botan_privkey_t *key, const botan_mp_t scalar, const char *curve_name)
struct botan_rng_struct * botan_rng_t
Definition: ffi.h:189
uint32_t botan_version_major(void)
Definition: ffi.cpp:232
int botan_mp_set_from_str(botan_mp_t dest, const char *str)
Definition: ffi_mp.cpp:51
uint32_t botan_version_minor(void)
Definition: ffi.cpp:233
int botan_privkey_destroy(botan_privkey_t key)
Definition: ffi_pkey.cpp:88
int botan_mp_gcd(botan_mp_t out, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:275