Botan  2.7.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
17 interface. This API is uesd by the Python and OCaml bindings via those
18 languages respective ctypes 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  variables provided 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 The API is not currently documented, nor should it be considered
47 stable. It is buggy as heck, most likely, and error handling is a
48 mess. However the goal is to provide a long term API usable for
49 language bindings, or for use by systems written in C. Suggestions on
50 how to provide the cleanest API for such users would be most welcome.
51 
52 * TODO:
53 * - Better error reporting
54 * - User callback for exception logging?
55 * - Doxygen comments for all functions/params
56 * - X.509 certs and PKIX path validation goo
57 * - TLS
58 */
59 
60 #include <botan/build.h>
61 #include <stdint.h>
62 #include <stddef.h>
63 
64 /**
65 * Error codes
66 */
70 
73 
81 
83 };
84 
85 /**
86 * Convert an error code into a string. Returns "Unknown error"
87 * if the error code is not a known one.
88 */
89 const char* botan_error_description(int err);
90 
91 /**
92 * Return the version of the currently supported FFI API. This is
93 * expressed in the form YYYYMMDD of the release date of this version
94 * of the API.
95 */
97 
98 /**
99 * Return 0 (ok) if the version given is one this library supports.
100 * botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.
101 */
102 BOTAN_PUBLIC_API(2,0) int botan_ffi_supports_api(uint32_t api_version);
103 
104 /**
105 * Return a free-form version string, e.g., 2.0.0
106 */
107 BOTAN_PUBLIC_API(2,0) const char* botan_version_string();
108 
109 /**
110 * Return the major version of the library
111 */
112 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_major();
113 
114 /**
115 * Return the minor version of the library
116 */
117 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_minor();
118 
119 /**
120 * Return the patch version of the library
121 */
122 BOTAN_PUBLIC_API(2,0) uint32_t botan_version_patch();
123 
124 /**
125 * Return the date this version was released as
126 * an integer, or 0 if an unreleased version
127 */
129 
130 /**
131 * Returns 0 if x[0..len] == y[0..len], or otherwise -1
132 */
133 BOTAN_PUBLIC_API(2,3) int botan_constant_time_compare(const uint8_t* x, const uint8_t* y, size_t len);
134 
135 /**
136 * Deprecated equivalent to botan_constant_time_compare
137 */
138 BOTAN_PUBLIC_API(2,0) int botan_same_mem(const uint8_t* x, const uint8_t* y, size_t len);
139 
140 /**
141 * Clear out memory using a system specific approach to bypass elision by the
142 * compiler (currently using RtlSecureZeroMemory or tricks with volatile pointers).
143 */
144 BOTAN_PUBLIC_API(2,2) int botan_scrub_mem(void* mem, size_t bytes);
145 
146 #define BOTAN_FFI_HEX_LOWER_CASE 1
147 
148 /**
149 * Perform hex encoding
150 * @param x is some binary data
151 * @param len length of x in bytes
152 * @param out an array of at least x*2 bytes
153 * @param flags flags out be upper or lower case?
154 * @return 0 on success, 1 on failure
155 */
156 BOTAN_PUBLIC_API(2,0) int botan_hex_encode(const uint8_t* x, size_t len, char* out, uint32_t flags);
157 
158 /**
159 * Perform hex decoding
160 * @param hex_str a string of hex chars (whitespace is ignored)
161 * @param in_len the length of hex_str
162 * @param out the output buffer should be at least strlen(hex_str)/2 bytes
163 * @param out_len the size of out
164 */
165 BOTAN_PUBLIC_API(2,3) int botan_hex_decode(const char* hex_str, size_t in_len, uint8_t* out, size_t* out_len);
166 
167 /**
168 * Perform base64 encoding
169 */
170 BOTAN_PUBLIC_API(2,3) int botan_base64_encode(const uint8_t* x, size_t len, char* out, size_t* out_len);
171 
172 
173 /**
174 * Perform base64 decoding
175 */
176 BOTAN_PUBLIC_API(2,3) int botan_base64_decode(const char* base64_str, size_t in_len,
177  uint8_t* out, size_t* out_len);
178 
179 /**
180 * RNG type
181 */
182 typedef struct botan_rng_struct* botan_rng_t;
183 
184 /**
185 * Initialize a random number generator object
186 * @param rng rng object
187 * @param rng_type type of the rng, possible values:
188 * "system": System_RNG, "user": AutoSeeded_RNG
189 * Set rng_type to null or empty string to let the library choose
190 *
191 * TODO: replace rng_type with simple flags?
192 */
193 BOTAN_PUBLIC_API(2,0) int botan_rng_init(botan_rng_t* rng, const char* rng_type);
194 
195 /**
196 * Get random bytes from a random number generator
197 * @param rng rng object
198 * @param out output buffer of size out_len
199 * @param out_len number of requested bytes
200 * @return 0 on success, negative on failure
201 *
202 * TODO: better name
203 */
204 BOTAN_PUBLIC_API(2,0) int botan_rng_get(botan_rng_t rng, uint8_t* out, size_t out_len);
205 
206 /**
207 * Reseed a random number generator
208 * Uses the System_RNG as a seed generator.
209 *
210 * @param rng rng object
211 * @param bits number of bits to to reseed with
212 * @return 0 on success, a negative value on failure
213 */
214 BOTAN_PUBLIC_API(2,0) int botan_rng_reseed(botan_rng_t rng, size_t bits);
215 
216 /**
217 * Frees all resources of the random number generator object
218 * @param rng rng object
219 * @return always returns 0
220 */
222 
223 /*
224 * Hash type
225 */
226 typedef struct botan_hash_struct* botan_hash_t;
227 
228 /**
229 * Initialize a hash function object
230 * @param hash hash object
231 * @param hash_name name of the hash function, e.g., "SHA-384"
232 * @param flags should be 0 in current API revision, all other uses are reserved
233 * and return BOTAN_FFI_ERROR_BAD_FLAG
234 *
235 * TODO: since output_length is effectively required to use this API,
236 * return it from init as an output parameter
237 */
238 BOTAN_PUBLIC_API(2,0) int botan_hash_init(botan_hash_t* hash, const char* hash_name, uint32_t flags);
239 
240 /**
241 * Copy the state of a hash function object
242 * @param dest destination hash object
243 * @param source source hash object
244 * @return 0 on success, a negative value on failure
245 */
247 
248 /**
249 * Writes the output length of the hash function to *output_length
250 * @param hash hash object
251 * @param output_length output buffer to hold the hash function output length
252 * @return 0 on success, a negative value on failure
253 */
254 BOTAN_PUBLIC_API(2,0) int botan_hash_output_length(botan_hash_t hash, size_t* output_length);
255 
256 /**
257 * Writes the block size of the hash function to *block_size
258 * @param hash hash object
259 * @param block_size output buffer to hold the hash function output length
260 * @return 0 on success, a negative value on failure
261 */
262 BOTAN_PUBLIC_API(2,2) int botan_hash_block_size(botan_hash_t hash, size_t* block_size);
263 
264 /**
265 * Send more input to the hash function
266 * @param hash hash object
267 * @param in input buffer
268 * @param in_len number of bytes to read from the input buffer
269 * @return 0 on success, a negative value on failure
270 */
271 BOTAN_PUBLIC_API(2,0) int botan_hash_update(botan_hash_t hash, const uint8_t* in, size_t in_len);
272 
273 /**
274 * Finalizes the hash computation and writes the output to
275 * out[0:botan_hash_output_length()] then reinitializes for computing
276 * another digest as if botan_hash_clear had been called.
277 * @param hash hash object
278 * @param out output buffer
279 * @return 0 on success, a negative value on failure
280 */
281 BOTAN_PUBLIC_API(2,0) int botan_hash_final(botan_hash_t hash, uint8_t out[]);
282 
283 /**
284 * Reinitializes the state of the hash computation. A hash can
285 * be computed (with update/final) immediately.
286 * @param hash hash object
287 * @return 0 on success, a negative value on failure
288 */
290 
291 /**
292 * Frees all resources of the hash object
293 * @param hash hash object
294 * @return always returns 0
295 */
297 
298 /**
299 * TODO has no implementation
300 */
301 BOTAN_PUBLIC_API(2,0) int botan_hash_name(botan_hash_t hash, char* name, size_t name_len);
302 
303 /*
304 * Message Authentication type
305 */
306 typedef struct botan_mac_struct* botan_mac_t;
307 
308 /**
309 * Initialize a message authentication code object
310 * @param mac mac object
311 * @param mac_name name of the hash function, e.g., "HMAC(SHA-384)"
312 * @param flags should be 0 in current API revision, all other uses are reserved
313 * and return a negative value (error code)
314 * @return 0 on success, a negative value on failure
315 */
316 BOTAN_PUBLIC_API(2,0) int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags);
317 
318 /**
319 * Writes the output length of the message authentication code to *output_length
320 * @param mac mac object
321 * @param output_length output buffer to hold the MAC output length
322 * @return 0 on success, a negative value on failure
323 */
324 BOTAN_PUBLIC_API(2,0) int botan_mac_output_length(botan_mac_t mac, size_t* output_length);
325 
326 /**
327 * Sets the key on the MAC
328 * @param mac mac object
329 * @param key buffer holding the key
330 * @param key_len size of the key buffer in bytes
331 * @return 0 on success, a negative value on failure
332 */
333 BOTAN_PUBLIC_API(2,0) int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len);
334 
335 /**
336 * Send more input to the message authentication code
337 * @param mac mac object
338 * @param buf input buffer
339 * @param len number of bytes to read from the input buffer
340 * @return 0 on success, a negative value on failure
341 */
342 BOTAN_PUBLIC_API(2,0) int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len);
343 
344 /**
345 * Finalizes the MAC computation and writes the output to
346 * out[0:botan_mac_output_length()] then reinitializes for computing
347 * another MAC as if botan_mac_clear had been called.
348 * @param mac mac object
349 * @param out output buffer
350 * @return 0 on success, a negative value on failure
351 */
352 BOTAN_PUBLIC_API(2,0) int botan_mac_final(botan_mac_t mac, uint8_t out[]);
353 
354 /**
355 * Reinitializes the state of the MAC computation. A MAC can
356 * be computed (with update/final) immediately.
357 * @param mac mac object
358 * @return 0 on success, a negative value on failure
359 */
361 
362 /**
363 * Frees all resources of the MAC object
364 * @param mac mac object
365 * @return always returns 0
366 */
368 
369 /*
370 * Cipher modes
371 */
372 typedef struct botan_cipher_struct* botan_cipher_t;
373 
374 #define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION 1
375 #define BOTAN_CIPHER_INIT_FLAG_ENCRYPT 0
376 #define BOTAN_CIPHER_INIT_FLAG_DECRYPT 1
377 
378 BOTAN_PUBLIC_API(2,0) int botan_cipher_init(botan_cipher_t* cipher, const char* name, uint32_t flags);
379 
381 BOTAN_PUBLIC_API(2,0) int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t* tag_size);
384 
386  size_t* out_minimum_keylength,
387  size_t* out_maximum_keylength);
388 
390  const uint8_t* key, size_t key_len);
391 
393  const uint8_t* ad, size_t ad_len);
394 
396  const uint8_t* nonce, size_t nonce_len);
397 
398 #define BOTAN_CIPHER_UPDATE_FLAG_FINAL (1U << 0)
399 
401  uint32_t flags,
402  uint8_t output[],
403  size_t output_size,
404  size_t* output_written,
405  const uint8_t input_bytes[],
406  size_t input_size,
407  size_t* input_consumed);
408 
411 
412 /*
413 * Derive a key from a passphrase for a number of iterations
414 * @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2"
415 * @param out buffer to store the derived key, must be of out_len bytes
416 * @param out_len the desired length of the key to produce
417 * @param passphrase the password to derive the key from
418 * @param salt a randomly chosen salt
419 * @param salt_len length of salt in bytes
420 * @param iterations the number of iterations to use (use 10K or more)
421 * @return 0 on success, a negative value on failure
422 */
423 BOTAN_PUBLIC_API(2,0) int botan_pbkdf(const char* pbkdf_algo,
424  uint8_t out[], size_t out_len,
425  const char* passphrase,
426  const uint8_t salt[], size_t salt_len,
427  size_t iterations);
428 
429 /**
430 * Derive a key from a passphrase, running until msec time has elapsed.
431 * @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2"
432 * @param out buffer to store the derived key, must be of out_len bytes
433 * @param out_len the desired length of the key to produce
434 * @param passphrase the password to derive the key from
435 * @param salt a randomly chosen salt
436 * @param salt_len length of salt in bytes
437 * @param milliseconds_to_run if iterations is zero, then instead the PBKDF is
438 * run until milliseconds_to_run milliseconds has passed
439 * @param out_iterations_used set to the number iterations executed
440 * @return 0 on success, a negative value on failure
441 */
442 BOTAN_PUBLIC_API(2,0) int botan_pbkdf_timed(const char* pbkdf_algo,
443  uint8_t out[], size_t out_len,
444  const char* passphrase,
445  const uint8_t salt[], size_t salt_len,
446  size_t milliseconds_to_run,
447  size_t* out_iterations_used);
448 
449 /**
450 * Derive a key
451 * @param kdf_algo KDF algorithm, e.g., "SP800-56C"
452 * @param out buffer holding the derived key, must be of length out_len
453 * @param out_len the desired output length in bytes
454 * @param secret the secret input
455 * @param secret_len size of secret in bytes
456 * @param salt a diversifier
457 * @param salt_len size of salt in bytes
458 * @param label purpose for the derived keying material
459 * @param label_len size of label in bytes
460 * @return 0 on success, a negative value on failure
461 */
462 BOTAN_PUBLIC_API(2,0) int botan_kdf(const char* kdf_algo,
463  uint8_t out[], size_t out_len,
464  const uint8_t secret[], size_t secret_len,
465  const uint8_t salt[], size_t salt_len,
466  const uint8_t label[], size_t label_len);
467 
468 /**
469 * Create a password hash using Bcrypt
470 * @param out buffer holding the password hash, should be of length 64 bytes
471 * @param out_len the desired output length in bytes
472 * @param password the password
473 * @param rng a random number generator
474 * @param work_factor how much work to do to slow down guessing attacks
475 * @param flags should be 0 in current API revision, all other uses are reserved
476 * and return BOTAN_FFI_ERROR_BAD_FLAG
477 * @return 0 on success, a negative value on failure
478 
479 * Output is formatted bcrypt $2a$...
480 */
481 BOTAN_PUBLIC_API(2,0) int botan_bcrypt_generate(uint8_t* out, size_t* out_len,
482  const char* password,
483  botan_rng_t rng,
484  size_t work_factor,
485  uint32_t flags);
486 
487 /*
488 * Raw Block Cipher (PRP) interface
489 */
490 typedef struct botan_block_cipher_struct* botan_block_cipher_t;
491 
492 /**
493 * Initialize a block cipher object
494 */
496  const char* cipher_name);
497 
498 /**
499 * Destroy a block cipher object
500 */
502 
503 /**
504 * Reinitializes the block cipher
505 * @return 0 on success, a negative value on failure
506 */
508 
509 /**
510 * Set the key for a block cipher instance
511 */
513  const uint8_t key[], size_t len);
514 
515 /**
516 * Return the positive block size of this block cipher, or negative to
517 * indicate an error
518 */
520 
522  const uint8_t in[],
523  uint8_t out[],
524  size_t blocks);
525 
527  const uint8_t in[],
528  uint8_t out[],
529  size_t blocks);
530 
531 
532 /*
533 * Multiple precision integers
534 */
535 typedef struct botan_mp_struct* botan_mp_t;
536 
539 
540 // writes botan_mp_num_bytes(mp)*2 + 1 bytes to out[]
541 BOTAN_PUBLIC_API(2,1) int botan_mp_to_hex(const botan_mp_t mp, char* out);
542 BOTAN_PUBLIC_API(2,1) int botan_mp_to_str(const botan_mp_t mp, uint8_t base, char* out, size_t* out_len);
543 
545 
546 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_int(botan_mp_t mp, int initial_value);
547 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_mp(botan_mp_t dest, const botan_mp_t source);
548 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_str(botan_mp_t dest, const char* str);
549 BOTAN_PUBLIC_API(2,1) int botan_mp_set_from_radix_str(botan_mp_t dest, const char* str, size_t radix);
550 
551 BOTAN_PUBLIC_API(2,1) int botan_mp_num_bits(const botan_mp_t n, size_t* bits);
552 BOTAN_PUBLIC_API(2,1) int botan_mp_num_bytes(const botan_mp_t n, size_t* bytes);
553 
554 // Writes botan_mp_num_bytes(mp) to vec
555 BOTAN_PUBLIC_API(2,1) int botan_mp_to_bin(const botan_mp_t mp, uint8_t vec[]);
556 BOTAN_PUBLIC_API(2,1) int botan_mp_from_bin(const botan_mp_t mp, const uint8_t vec[], size_t vec_len);
557 
558 BOTAN_PUBLIC_API(2,1) int botan_mp_to_uint32(const botan_mp_t mp, uint32_t* val);
559 
560 /**
561 * This function is not well named. Returns 1 iff mp is greater than
562 * *or equal to* zero. Use botan_mp_is_negative to detect negative
563 * numbers, botan_mp_is_zero to check for zero.
564 */
566 
567 /**
568 * Return 1 iff mp is less than 0
569 */
571 
573 //BOTAN_PUBLIC_API(2,1) int botan_mp_set_negative(botan_mp_t mp);
574 
575 BOTAN_PUBLIC_API(2,1) int botan_mp_is_zero(const botan_mp_t mp);
576 BOTAN_PUBLIC_API(2,1) int botan_mp_is_odd(const botan_mp_t mp);
577 BOTAN_PUBLIC_API(2,1) int botan_mp_is_even(const botan_mp_t mp);
578 
579 BOTAN_PUBLIC_API(2,1) int botan_mp_add(botan_mp_t result, const botan_mp_t x, const botan_mp_t y);
580 BOTAN_PUBLIC_API(2,1) int botan_mp_sub(botan_mp_t result, const botan_mp_t x, const botan_mp_t y);
581 BOTAN_PUBLIC_API(2,1) int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y);
582 
583 BOTAN_PUBLIC_API(2,1) int botan_mp_div(botan_mp_t quotient,
584  botan_mp_t remainder,
585  const botan_mp_t x, const botan_mp_t y);
586 
587 BOTAN_PUBLIC_API(2,1) int botan_mp_mod_mul(botan_mp_t result, const botan_mp_t x,
588  const botan_mp_t y, const botan_mp_t mod);
589 
590 /*
591 * Returns 0 if x != y
592 * Returns 1 if x == y
593 * Returns negative number on error
594 */
595 BOTAN_PUBLIC_API(2,1) int botan_mp_equal(const botan_mp_t x, const botan_mp_t y);
596 
597 /*
598 * Sets *result to comparison result:
599 * -1 if x < y, 0 if x == y, 1 if x > y
600 * Returns negative number on error or zero on success
601 */
602 BOTAN_PUBLIC_API(2,1) int botan_mp_cmp(int* result, const botan_mp_t x, const botan_mp_t y);
603 
604 /*
605 * Swap two botan_mp_t
606 */
608 
609 // Return (base^exponent) % modulus
610 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);
611 
612 BOTAN_PUBLIC_API(2,1) int botan_mp_lshift(botan_mp_t out, const botan_mp_t in, size_t shift);
613 BOTAN_PUBLIC_API(2,1) int botan_mp_rshift(botan_mp_t out, const botan_mp_t in, size_t shift);
614 
615 BOTAN_PUBLIC_API(2,1) int botan_mp_mod_inverse(botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus);
616 
617 BOTAN_PUBLIC_API(2,1) int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits);
618 
620  const botan_mp_t lower_bound, const botan_mp_t upper_bound);
621 
622 BOTAN_PUBLIC_API(2,1) int botan_mp_gcd(botan_mp_t out, const botan_mp_t x, const botan_mp_t y);
623 
624 /**
625 * Returns 0 if n is not prime
626 * Returns 1 if n is prime
627 * Returns negative number on error
628 */
629 BOTAN_PUBLIC_API(2,1) int botan_mp_is_prime(const botan_mp_t n, botan_rng_t rng, size_t test_prob);
630 
631 /**
632 * Returns 0 if specified bit of n is not set
633 * Returns 1 if specified bit of n is set
634 * Returns negative number on error
635 */
636 BOTAN_PUBLIC_API(2,1) int botan_mp_get_bit(const botan_mp_t n, size_t bit);
637 
638 /**
639 * Set the specified bit
640 */
641 BOTAN_PUBLIC_API(2,1) int botan_mp_set_bit(botan_mp_t n, size_t bit);
642 
643 /**
644 * Clear the specified bit
645 */
646 BOTAN_PUBLIC_API(2,1) int botan_mp_clear_bit(botan_mp_t n, size_t bit);
647 
648 /* Bcrypt password hashing */
649 
650 /**
651 * Check a previously created password hash
652 * @param pass the password to check against
653 * @param hash the stored hash to check against
654 * @return 0 if if this password/hash combination is valid,
655 * 1 if the combination is not valid (but otherwise well formed),
656 * negative on error
657 */
658 BOTAN_PUBLIC_API(2,0) int botan_bcrypt_is_valid(const char* pass, const char* hash);
659 
660 /*
661 * Public/private key creation, import, ...
662 */
663 typedef struct botan_privkey_struct* botan_privkey_t;
664 
666  const char* algo_name,
667  const char* algo_params,
668  botan_rng_t rng);
669 
670 #define BOTAN_CHECK_KEY_EXPENSIVE_TESTS 1
671 
673 
674 BOTAN_PUBLIC_API(2,0) int botan_privkey_create_rsa(botan_privkey_t* key, botan_rng_t rng, size_t n_bits);
675 BOTAN_PUBLIC_API(2,0) int botan_privkey_create_ecdsa(botan_privkey_t* key, botan_rng_t rng, const char* params);
676 BOTAN_PUBLIC_API(2,0) int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, const char* params);
677 BOTAN_PUBLIC_API(2,0) int botan_privkey_create_mceliece(botan_privkey_t* key, botan_rng_t rng, size_t n, size_t t);
678 BOTAN_PUBLIC_API(2,0) int botan_privkey_create_dh(botan_privkey_t* key, botan_rng_t rng, const char* param);
679 
680 
681 /*
682  * Generates DSA key pair. Gives to a caller control over key length
683  * and order of a subgroup 'q'.
684  *
685  * @param key handler to the resulting key
686  * @param rng initialized PRNG
687  * @param pbits length of the key in bits. Must be between in range (1024, 3072)
688  * and multiple of 64. Bit size of the prime 'p'
689  * @param qbits order of the subgroup. Must be in range (160, 256) and multiple
690  * of 8
691  *
692  * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
693  * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
694  * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
695  * `qbits'
696  * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
697  *
698 -------------------------------------------------------------------------------- */
700  botan_privkey_t* key,
701  botan_rng_t rng,
702  size_t pbits,
703  size_t qbits);
704 
705 /*
706  * Generates ElGamal key pair. Caller has a control over key length
707  * and order of a subgroup 'q'. Function is able to use two types of
708  * primes:
709  * * if pbits-1 == qbits then safe primes are used for key generation
710  * * otherwise generation uses group of prime order
711  *
712  * @param key handler to the resulting key
713  * @param rng initialized PRNG
714  * @param pbits length of the key in bits. Must be at least 1024
715  * @param qbits order of the subgroup. Must be at least 160
716  *
717  * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
718  * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
719  * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
720  * `qbits'
721  * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
722  *
723 -------------------------------------------------------------------------------- */
725  botan_privkey_t* key,
726  botan_rng_t rng,
727  size_t pbits,
728  size_t qbits);
729 
730 /*
731 * Input currently assumed to be PKCS #8 structure;
732 * Set password to NULL to indicate no encryption expected
733 */
735  const uint8_t bits[], size_t len,
736  const char* password);
737 
739 
740 #define BOTAN_PRIVKEY_EXPORT_FLAG_DER 0
741 #define BOTAN_PRIVKEY_EXPORT_FLAG_PEM 1
742 
743 /*
744 * On input *out_len is number of bytes in out[]
745 * On output *out_len is number of bytes written (or required)
746 * If out is not big enough no output is written, *out_len is set and 1 is returned
747 * Returns 0 on success and sets
748 * If some other error occurs a negative integer is returned.
749 */
751  uint8_t out[], size_t* out_len,
752  uint32_t flags);
753 
754 /*
755 * Set encryption_algo to NULL or "" to have the library choose a default (recommended)
756 */
757 BOTAN_DEPRECATED("Use botan_privkey_export_encrypted_pbkdf_{msec,iter}")
758 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_encrypted(botan_privkey_t key,
759  uint8_t out[], size_t* out_len,
760  botan_rng_t rng,
761  const char* passphrase,
762  const char* encryption_algo,
763  uint32_t flags);
764 
765 /*
766 * Export a private key, running PBKDF for specified amount of time
767 * @param key the private key to export
768 */
769 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_encrypted_pbkdf_msec(botan_privkey_t key,
770  uint8_t out[], size_t* out_len,
771  botan_rng_t rng,
772  const char* passphrase,
773  uint32_t pbkdf_msec_runtime,
774  size_t* pbkdf_iterations_out,
775  const char* cipher_algo,
776  const char* pbkdf_algo,
777  uint32_t flags);
778 
779 /*
780 * Export a private key using the specified number of iterations.
781 */
782 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key,
783  uint8_t out[], size_t* out_len,
784  botan_rng_t rng,
785  const char* passphrase,
786  size_t pbkdf_iterations,
787  const char* cipher_algo,
788  const char* pbkdf_algo,
789  uint32_t flags);
790 
791 typedef struct botan_pubkey_struct* botan_pubkey_t;
792 
793 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t len);
794 
795 BOTAN_PUBLIC_API(2,0) int botan_privkey_export_pubkey(botan_pubkey_t* out, botan_privkey_t in);
796 
797 BOTAN_PUBLIC_API(2,0) int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags);
798 
799 BOTAN_PUBLIC_API(2,0) int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len);
800 
801 /**
802 * Returns 0 if key is valid, negative if invalid key or some other error
803 */
804 BOTAN_PUBLIC_API(2,0) int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags);
805 
806 BOTAN_PUBLIC_API(2,0) int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate);
807 
808 BOTAN_PUBLIC_API(2,0) int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash,
809  uint8_t out[], size_t* out_len);
810 
811 BOTAN_PUBLIC_API(2,0) int botan_pubkey_destroy(botan_pubkey_t key);
812 
813 /*
814 * Get arbitrary named fields from public or privat keys
815 */
816 BOTAN_PUBLIC_API(2,0) int botan_pubkey_get_field(botan_mp_t output,
817  botan_pubkey_t key,
818  const char* field_name);
819 
820 BOTAN_PUBLIC_API(2,0) int botan_privkey_get_field(botan_mp_t output,
821  botan_privkey_t key,
822  const char* field_name);
823 
824 /*
825 * Algorithm specific key operations: RSA
826 */
827 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_rsa(botan_privkey_t* key,
828  botan_mp_t p,
829  botan_mp_t q,
830  botan_mp_t e);
831 
832 BOTAN_PUBLIC_API(2,0) int botan_privkey_rsa_get_p(botan_mp_t p, botan_privkey_t rsa_key);
833 BOTAN_PUBLIC_API(2,0) int botan_privkey_rsa_get_q(botan_mp_t q, botan_privkey_t rsa_key);
834 BOTAN_PUBLIC_API(2,0) int botan_privkey_rsa_get_d(botan_mp_t d, botan_privkey_t rsa_key);
835 BOTAN_PUBLIC_API(2,0) int botan_privkey_rsa_get_n(botan_mp_t n, botan_privkey_t rsa_key);
836 BOTAN_PUBLIC_API(2,0) int botan_privkey_rsa_get_e(botan_mp_t e, botan_privkey_t rsa_key);
837 
838 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_rsa(botan_pubkey_t* key,
839  botan_mp_t n,
840  botan_mp_t e);
841 
842 BOTAN_PUBLIC_API(2,0) int botan_pubkey_rsa_get_e(botan_mp_t e, botan_pubkey_t rsa_key);
843 BOTAN_PUBLIC_API(2,0) int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t rsa_key);
844 
845 /*
846 * Algorithm specific key operations: DSA
847 */
848 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_dsa(botan_privkey_t* key,
849  botan_mp_t p,
850  botan_mp_t q,
851  botan_mp_t g,
852  botan_mp_t x);
853 
854 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_dsa(botan_pubkey_t* key,
855  botan_mp_t p,
856  botan_mp_t q,
857  botan_mp_t g,
858  botan_mp_t y);
859 
860 BOTAN_PUBLIC_API(2,0) int botan_privkey_dsa_get_x(botan_mp_t n, botan_privkey_t key);
861 
862 BOTAN_PUBLIC_API(2,0) int botan_pubkey_dsa_get_p(botan_mp_t p, botan_pubkey_t key);
863 BOTAN_PUBLIC_API(2,0) int botan_pubkey_dsa_get_q(botan_mp_t q, botan_pubkey_t key);
864 BOTAN_PUBLIC_API(2,0) int botan_pubkey_dsa_get_g(botan_mp_t d, botan_pubkey_t key);
865 BOTAN_PUBLIC_API(2,0) int botan_pubkey_dsa_get_y(botan_mp_t y, botan_pubkey_t key);
866 
867 /*
868 * Loads Diffie Hellman private key
869 *
870 * @param key variable populated with key material
871 * @param p prime order of a Z_p group
872 * @param g group generator
873 * @param x private key
874 *
875 * @pre key is NULL on input
876 * @post function allocates memory and assigns to `key'
877 *
878 * @return 0 on success, a negative value on failure
879 */
880 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_dh(botan_privkey_t* key,
881  botan_mp_t p,
882  botan_mp_t g,
883  botan_mp_t x);
884 /*
885 * Loads Diffie Hellman public key
886 *
887 * @param key variable populated with key material
888 * @param p prime order of a Z_p group
889 * @param g group generator
890 * @param y public key
891 *
892 * @pre key is NULL on input
893 * @post function allocates memory and assigns to `key'
894 *
895 * @return 0 on success, a negative value on failure
896 */
897 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_dh(botan_pubkey_t* key,
898  botan_mp_t p,
899  botan_mp_t g,
900  botan_mp_t y);
901 
902 /*
903 * Algorithm specific key operations: ElGamal
904 */
905 
906 /*
907 * Loads ElGamal public key
908 * @param key variable populated with key material
909 * @param p prime order of a Z_p group
910 * @param g group generator
911 * @param y public key
912 *
913 * @pre key is NULL on input
914 * @post function allocates memory and assigns to `key'
915 *
916 * @return 0 on success, a negative value on failure
917 */
918 BOTAN_PUBLIC_API(2,0) int botan_pubkey_load_elgamal(botan_pubkey_t* key,
919  botan_mp_t p,
920  botan_mp_t g,
921  botan_mp_t y);
922 
923 /*
924 * Loads ElGamal private key
925 *
926 * @param key variable populated with key material
927 * @param p prime order of a Z_p group
928 * @param g group generator
929 * @param x private key
930 *
931 * @pre key is NULL on input
932 * @post function allocates memory and assigns to `key'
933 *
934 * @return 0 on success, a negative value on failure
935 */
936 BOTAN_PUBLIC_API(2,0) int botan_privkey_load_elgamal(botan_privkey_t* key,
937  botan_mp_t p,
938  botan_mp_t g,
939  botan_mp_t x);
940 
941 /*
942 * Algorithm specific key operations: Ed25519
943 */
944 
945 BOTAN_PUBLIC_API(2,2) int botan_privkey_load_ed25519(botan_privkey_t* key,
946  const uint8_t privkey[32]);
947 
948 BOTAN_PUBLIC_API(2,2) int botan_pubkey_load_ed25519(botan_pubkey_t* key,
949  const uint8_t pubkey[32]);
950 
951 BOTAN_PUBLIC_API(2,2) int botan_privkey_ed25519_get_privkey(botan_privkey_t key,
952  uint8_t output[64]);
953 
954 BOTAN_PUBLIC_API(2,2) int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key,
955  uint8_t pubkey[32]);
956 
957 /*
958 * Algorithm specific key operations: ECDSA and ECDH
959 */
960 BOTAN_PUBLIC_API(2,2)
961 int botan_privkey_load_ecdsa(botan_privkey_t* key,
962  const botan_mp_t scalar,
963  const char* curve_name);
964 
965 BOTAN_PUBLIC_API(2,2)
966 int botan_pubkey_load_ecdsa(botan_pubkey_t* key,
967  const botan_mp_t public_x,
968  const botan_mp_t public_y,
969  const char* curve_name);
970 
971 BOTAN_PUBLIC_API(2,2)
972 int botan_pubkey_load_ecdh(botan_pubkey_t* key,
973  const botan_mp_t public_x,
974  const botan_mp_t public_y,
975  const char* curve_name);
976 
977 BOTAN_PUBLIC_API(2,2)
978 int botan_privkey_load_ecdh(botan_privkey_t* key,
979  const botan_mp_t scalar,
980  const char* curve_name);
981 
982 BOTAN_PUBLIC_API(2,2)
983 int botan_pubkey_load_sm2(botan_pubkey_t* key,
984  const botan_mp_t public_x,
985  const botan_mp_t public_y,
986  const char* curve_name);
987 
988 BOTAN_PUBLIC_API(2,2)
989 int botan_privkey_load_sm2(botan_privkey_t* key,
990  const botan_mp_t scalar,
991  const char* curve_name);
992 
993 BOTAN_PUBLIC_API(2,2)
994 int botan_pubkey_load_sm2_enc(botan_pubkey_t* key,
995  const botan_mp_t public_x,
996  const botan_mp_t public_y,
997  const char* curve_name);
998 
999 BOTAN_PUBLIC_API(2,2)
1000 int botan_privkey_load_sm2_enc(botan_privkey_t* key,
1001  const botan_mp_t scalar,
1002  const char* curve_name);
1003 
1004 BOTAN_PUBLIC_API(2,3)
1005 int botan_pubkey_sm2_compute_za(uint8_t out[],
1006  size_t* out_len,
1007  const char* ident,
1008  const char* hash_algo,
1009  const botan_pubkey_t key);
1010 
1011 /*
1012 * Public Key Encryption
1013 */
1014 typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t;
1015 
1016 BOTAN_PUBLIC_API(2,0) int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t* op,
1017  botan_pubkey_t key,
1018  const char* padding,
1019  uint32_t flags);
1020 
1021 BOTAN_PUBLIC_API(2,0) int botan_pk_op_encrypt_destroy(botan_pk_op_encrypt_t op);
1022 
1023 BOTAN_PUBLIC_API(2,0) int botan_pk_op_encrypt(botan_pk_op_encrypt_t op,
1024  botan_rng_t rng,
1025  uint8_t out[], size_t* out_len,
1026  const uint8_t plaintext[], size_t plaintext_len);
1027 
1028 /*
1029 * Public Key Decryption
1030 */
1031 typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t;
1032 
1033 BOTAN_PUBLIC_API(2,0) int botan_pk_op_decrypt_create(botan_pk_op_decrypt_t* op,
1034  botan_privkey_t key,
1035  const char* padding,
1036  uint32_t flags);
1037 BOTAN_PUBLIC_API(2,0) int botan_pk_op_decrypt_destroy(botan_pk_op_decrypt_t op);
1038 
1039 BOTAN_PUBLIC_API(2,0) int botan_pk_op_decrypt(botan_pk_op_decrypt_t op,
1040  uint8_t out[], size_t* out_len,
1041  const uint8_t ciphertext[], size_t ciphertext_len);
1042 
1043 /*
1044 * Signature Generation
1045 */
1046 typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t;
1047 
1048 BOTAN_PUBLIC_API(2,0)
1049 int botan_pk_op_sign_create(botan_pk_op_sign_t* op,
1050  botan_privkey_t key,
1051  const char* hash_and_padding,
1052  uint32_t flags);
1053 
1054 BOTAN_PUBLIC_API(2,0) int botan_pk_op_sign_destroy(botan_pk_op_sign_t op);
1055 
1056 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);
1057 
1058 BOTAN_PUBLIC_API(2,0)
1059 int botan_pk_op_sign_finish(botan_pk_op_sign_t op, botan_rng_t rng,
1060  uint8_t sig[], size_t* sig_len);
1061 
1062 /*
1063 * Signature Verification
1064 */
1065 typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t;
1066 
1067 BOTAN_PUBLIC_API(2,0)
1068 int botan_pk_op_verify_create(botan_pk_op_verify_t* op,
1069  botan_pubkey_t key,
1070  const char* hash_and_padding,
1071  uint32_t flags);
1072 
1073 BOTAN_PUBLIC_API(2,0) int botan_pk_op_verify_destroy(botan_pk_op_verify_t op);
1074 
1075 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);
1076 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);
1077 
1078 /*
1079 * Key Agreement
1080 */
1081 typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t;
1082 
1083 BOTAN_PUBLIC_API(2,0)
1084 int botan_pk_op_key_agreement_create(botan_pk_op_ka_t* op,
1085  botan_privkey_t key,
1086  const char* kdf,
1087  uint32_t flags);
1088 
1089 BOTAN_PUBLIC_API(2,0) int botan_pk_op_key_agreement_destroy(botan_pk_op_ka_t op);
1090 
1091 BOTAN_PUBLIC_API(2,0) int botan_pk_op_key_agreement_export_public(botan_privkey_t key,
1092  uint8_t out[], size_t* out_len);
1093 
1094 BOTAN_PUBLIC_API(2,0)
1095 int botan_pk_op_key_agreement(botan_pk_op_ka_t op,
1096  uint8_t out[], size_t* out_len,
1097  const uint8_t other_key[], size_t other_key_len,
1098  const uint8_t salt[], size_t salt_len);
1099 
1100 BOTAN_PUBLIC_API(2,0) int botan_pkcs_hash_id(const char* hash_name, uint8_t pkcs_id[], size_t* pkcs_id_len);
1101 
1102 
1103 /*
1104 *
1105 * @param mce_key must be a McEliece key
1106 * ct_len should be pt_len + n/8 + a few?
1107 */
1108 BOTAN_PUBLIC_API(2,0)
1109 int botan_mceies_encrypt(botan_pubkey_t mce_key,
1110  botan_rng_t rng,
1111  const char* aead,
1112  const uint8_t pt[], size_t pt_len,
1113  const uint8_t ad[], size_t ad_len,
1114  uint8_t ct[], size_t* ct_len);
1115 
1116 BOTAN_PUBLIC_API(2,0)
1117 int botan_mceies_decrypt(botan_privkey_t mce_key,
1118  const char* aead,
1119  const uint8_t ct[], size_t ct_len,
1120  const uint8_t ad[], size_t ad_len,
1121  uint8_t pt[], size_t* pt_len);
1122 
1123 typedef struct botan_x509_cert_struct* botan_x509_cert_t;
1124 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_load(botan_x509_cert_t* cert_obj, const uint8_t cert[], size_t cert_len);
1125 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* filename);
1126 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_destroy(botan_x509_cert_t cert);
1127 
1128 BOTAN_PUBLIC_API(2,0)
1129 int botan_x509_cert_gen_selfsigned(botan_x509_cert_t* cert,
1130  botan_privkey_t key,
1131  botan_rng_t rng,
1132  const char* common_name,
1133  const char* org_name);
1134 
1135 // TODO: return botan_time_struct instead
1136 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* out_len);
1137 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* out_len);
1138 
1139 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);
1140 
1141 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1142 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);
1143 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);
1144 
1145 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert,
1146  uint8_t out[], size_t* out_len);
1147 
1148 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t* key);
1149 
1150 BOTAN_PUBLIC_API(2,0)
1151 int botan_x509_cert_get_issuer_dn(botan_x509_cert_t cert,
1152  const char* key, size_t index,
1153  uint8_t out[], size_t* out_len);
1154 
1155 BOTAN_PUBLIC_API(2,0)
1156 int botan_x509_cert_get_subject_dn(botan_x509_cert_t cert,
1157  const char* key, size_t index,
1158  uint8_t out[], size_t* out_len);
1159 
1160 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_len);
1161 
1162 // Must match values of Key_Constraints in key_constraints.h
1163 enum botan_x509_cert_key_constraints {
1164  NO_CONSTRAINTS = 0,
1165  DIGITAL_SIGNATURE = 32768,
1166  NON_REPUDIATION = 16384,
1167  KEY_ENCIPHERMENT = 8192,
1168  DATA_ENCIPHERMENT = 4096,
1169  KEY_AGREEMENT = 2048,
1170  KEY_CERT_SIGN = 1024,
1171  CRL_SIGN = 512,
1172  ENCIPHER_ONLY = 256,
1173  DECIPHER_ONLY = 128
1174 };
1175 
1176 BOTAN_PUBLIC_API(2,0) int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage);
1177 
1178 /**
1179 * Check if the certificate matches the specified hostname via alternative name or CN match.
1180 * RFC 5280 wildcards also supported.
1181 */
1182 BOTAN_PUBLIC_API(2,5) int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname);
1183 
1184 /**
1185  * Key wrapping as per RFC 3394
1186  */
1187 BOTAN_PUBLIC_API(2,2)
1188 int botan_key_wrap3394(const uint8_t key[], size_t key_len,
1189  const uint8_t kek[], size_t kek_len,
1190  uint8_t wrapped_key[], size_t *wrapped_key_len);
1191 
1192 BOTAN_PUBLIC_API(2,2)
1193 int botan_key_unwrap3394(const uint8_t wrapped_key[], size_t wrapped_key_len,
1194  const uint8_t kek[], size_t kek_len,
1195  uint8_t key[], size_t *key_len);
1196 
1197 /*
1198 * TLS (WIP)
1199 */
1200 #if defined(BOTAN_HAS_TLS) && 0
1201 
1202 typedef struct botan_tls_session_struct* botan_tls_session_t;
1203 
1204 BOTAN_TEST_API int botan_tls_session_decrypt(botan_tls_session_t* session,
1205  const uint8_t key[], size_t key_len,
1206  const uint8_t blob[], size_t blob_len);
1207 
1208 BOTAN_TEST_API int botan_tls_session_get_version(botan_tls_session_t session, uint16_t* tls_version);
1209 BOTAN_TEST_API int botan_tls_session_get_ciphersuite(botan_tls_session_t session, uint16_t* ciphersuite);
1210 BOTAN_TEST_API int botan_tls_session_encrypt(botan_tls_session_t session, botan_rng_t rng, uint8_t key[], size_t* key_len);
1211 
1212 BOTAN_TEST_API int botan_tls_session_get_peer_certs(botan_tls_session_t session, botan_x509_cert_t certs[], size_t* cert_len);
1213 
1214 // TODO: peer certs, validation, ...
1215 
1216 typedef struct botan_tls_channel_struct* botan_tls_channel_t;
1217 
1218 typedef void (*botan_tls_channel_output_fn)(void* application_data, const uint8_t* data, size_t data_len);
1219 
1220 typedef void (*botan_tls_channel_data_cb)(void* application_data, const uint8_t* data, size_t data_len);
1221 
1222 typedef void (*botan_tls_channel_alert_cb)(void* application_data, uint16_t alert_code);
1223 
1224 typedef void (*botan_tls_channel_session_established)(void* application_data,
1225  botan_tls_channel_t channel,
1226  botan_tls_session_t session);
1227 
1228 BOTAN_TEST_API int botan_tls_channel_init_client(botan_tls_channel_t* channel,
1229  botan_tls_channel_output_fn output_fn,
1230  botan_tls_channel_data_cb data_cb,
1231  botan_tls_channel_alert_cb alert_cb,
1232  botan_tls_channel_session_established session_cb,
1233  const char* server_name);
1234 
1235 BOTAN_TEST_API int botan_tls_channel_init_server(botan_tls_channel_t* channel,
1236  botan_tls_channel_output_fn output_fn,
1237  botan_tls_channel_data_cb data_cb,
1238  botan_tls_channel_alert_cb alert_cb,
1239  botan_tls_channel_session_established session_cb);
1240 
1241 BOTAN_TEST_API int botan_tls_channel_received_data(botan_tls_channel_t chan,
1242  const uint8_t input[], size_t len);
1243 
1244 /**
1245 * Returns 0 for client, 1 for server, negative for error
1246 */
1247 BOTAN_TEST_API int botan_tls_channel_type(botan_tls_channel_t chan);
1248 
1249 BOTAN_TEST_API int botan_tls_channel_send(botan_tls_channel_t chan,
1250  const uint8_t input[], size_t len);
1251 
1252 BOTAN_TEST_API int botan_tls_channel_close(botan_tls_channel_t chan);
1253 
1254 BOTAN_TEST_API int botan_tls_channel_destroy(botan_tls_channel_t chan);
1255 
1256 #endif
1257 #ifdef __cplusplus
1258 }
1259 #endif
1260 
1261 #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:44
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:108
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition: ffi_pkey.cpp:158
int botan_hash_clear(botan_hash_t hash)
Definition: ffi_hash.cpp:49
uint32_t botan_version_datestamp()
Definition: ffi.cpp:108
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:71
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:110
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_base64_decode(const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition: ffi.cpp:151
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:48
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:130
int botan_mp_equal(const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:170
int botan_hash_block_size(botan_hash_t hash, size_t *block_size)
Definition: ffi_hash.cpp:44
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:106
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
BOTAN_FFI_ERROR
Definition: ffi.h:67
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_mac_final(botan_mac_t mac, uint8_t out[])
Definition: ffi_mac.cpp:59
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_same_mem(const uint8_t *x, const uint8_t *y, size_t len)
Definition: ffi.cpp:115
int botan_mp_destroy(botan_mp_t mp)
Definition: ffi_mp.cpp:139
int botan_hash_copy_state(botan_hash_t *dest, const botan_hash_t source)
Definition: ffi_hash.cpp:64
int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits)
Definition: ffi_mp.cpp:230
int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t *ug)
Definition: ffi_cipher.cpp:186
int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
Definition: ffi_cipher.cpp:162
int botan_mp_to_bin(const botan_mp_t mp, uint8_t vec[])
Definition: ffi_mp.cpp:125
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:61
int botan_mac_destroy(botan_mac_t mac)
Definition: ffi_mac.cpp:34
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:306
const char * botan_version_string()
Definition: ffi.cpp:100
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:262
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:222
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:39
int botan_base64_encode(const uint8_t *x, size_t len, char *out, size_t *out_len)
Definition: ffi.cpp:143
int botan_mp_is_positive(const botan_mp_t mp)
Definition: ffi_mp.cpp:84
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:54
struct botan_mp_struct * botan_mp_t
Definition: ffi.h:535
int botan_mp_swap(botan_mp_t x, botan_mp_t y)
Definition: ffi_mp.cpp:195
int botan_hash_final(botan_hash_t hash, uint8_t out[])
Definition: ffi_hash.cpp:59
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:212
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:32
int botan_mp_is_even(const botan_mp_t mp)
Definition: ffi_mp.cpp:185
int botan_mp_get_bit(const botan_mp_t n, size_t bit)
Definition: ffi_mp.cpp:257
int botan_hex_encode(const uint8_t *x, size_t len, char *out, uint32_t flags)
Definition: ffi.cpp:126
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:76
struct botan_hash_struct * botan_hash_t
Definition: ffi.h:226
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:17
int botan_hash_name(botan_hash_t hash, char *name, size_t name_len)
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:54
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:107
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:135
size_t salt_len
Definition: x509_obj.cpp:26
int botan_hash_destroy(botan_hash_t hash)
Definition: ffi_hash.cpp:34
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:74
int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl)
Definition: ffi_cipher.cpp:176
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:663
int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t *tag_size)
Definition: ffi_cipher.cpp:191
uint32_t botan_version_major()
Definition: ffi.cpp:105
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:236
int botan_mp_is_zero(const botan_mp_t mp)
Definition: ffi_mp.cpp:175
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:251
int botan_rng_reseed(botan_rng_t rng, size_t bits)
Definition: ffi_rng.cpp:49
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:277
struct botan_block_cipher_struct * botan_block_cipher_t
Definition: ffi.h:490
int botan_cipher_start(botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
Definition: ffi_cipher.cpp:60
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:120
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:66
int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:154
int botan_block_cipher_block_size(botan_block_cipher_t bc)
Definition: ffi_block.cpp:60
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:180
int botan_mp_mod_inverse(botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
Definition: ffi_mp.cpp:217
int botan_mp_add(botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:144
int botan_mp_lshift(botan_mp_t out, const botan_mp_t in, size_t shift)
Definition: ffi_mp.cpp:207
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
Definition: ffi_pkey.cpp:139
int botan_mp_cmp(int *result, const botan_mp_t x, const botan_mp_t y)
Definition: ffi_mp.cpp:190
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:159
int botan_bcrypt_is_valid(const char *pass, const char *hash)
Definition: ffi_kdf.cpp:86
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:44
struct botan_cipher_struct * botan_cipher_t
Definition: ffi.h:372
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:201
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:21
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:29
int botan_ffi_supports_api(uint32_t api_version)
Definition: ffi.cpp:81
int botan_mp_clear_bit(botan_mp_t n, size_t bit)
Definition: ffi_mp.cpp:267
int botan_mp_num_bits(const botan_mp_t n, size_t *bits)
Definition: ffi_mp.cpp:272
MechanismType hash
int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t *nl)
Definition: ffi_cipher.cpp:181
struct botan_rng_struct * botan_rng_t
Definition: ffi.h:182
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:245