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