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