Botan 3.5.0
Crypto and TLS for C&
ffi.h
Go to the documentation of this file.
1/*
2* FFI (C89 API)
3* (C) 2015,2017 Jack Lloyd
4* (C) 2021 René Fischer
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_FFI_H_
10#define BOTAN_FFI_H_
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/*
17This header exports some of botan's functionality via a C89 interface. This API
18is uesd by the Python, OCaml, Rust, Ruby, and Haskell bindings via those languages
19respective ctypes/FFI libraries.
20
21The API is intended to be as easy as possible to call from other
22languages, which often have easy ways to call C, because C. But some C
23code is easier to deal with than others, so to make things easy this
24API follows a few simple rules:
25
26- All interactions are via pointers to opaque structs. No need to worry about
27 structure padding issues and the like.
28
29- All functions return an int error code (except the version calls, which are
30 assumed to always have something to say).
31
32- Use simple types: size_t for lengths, const char* NULL terminated strings,
33 uint8_t for binary.
34
35- No ownership of memory transfers across the API boundary. The API will
36 consume data from const pointers, and will produce output by writing to
37 buffers provided by (and allocated by) the caller.
38
39- If exporting a value (a string or a blob) the function takes a pointer to the
40 output array and a read/write pointer to the length. If the length is insufficient, an
41 error is returned. So passing nullptr/0 allows querying the final value.
42
43 Typically there is also a function which allows querying the expected output
44 length of a function, for example `botan_hash_output_length` allows knowing in
45 advance the expected size for `botan_hash_final`. Some of these are exact,
46 while others such as `botan_pk_op_decrypt_output_length` only provide an upper
47 bound.
48
49 The big exception to this currently is the various functions which serialize
50 public and private keys, where there are currently no function that can
51 estimate the serialized size. Here view functions are used; see the handbook
52 for further details.
53
54 TODO:
55 - Doxygen comments for all functions/params
56 - TLS
57*/
58
59#include <stddef.h>
60#include <stdint.h>
61
62/**
63* BOTAN_FFI_EXPORT indicates public FFI functions.
64*
65* The arguments to the macro are to indicate the version that
66* that particular FFI function was first available
67*/
68#if defined(BOTAN_DLL)
69 #define BOTAN_FFI_EXPORT(maj, min) BOTAN_DLL
70#else
71 #if defined(__has_attribute)
72 #if __has_attribute(visibility)
73 #define BOTAN_FFI_EXPORT(maj, min) __attribute__((visibility("default")))
74 #endif
75 #elif defined(_MSC_VER) && !defined(BOTAN_IS_BEING_BUILT)
76 #define BOTAN_FFI_EXPORT(maj, min) __declspec(dllimport)
77 #else
78 #define BOTAN_FFI_EXPORT(maj, min)
79 #endif
80#endif
81
82#if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
83 #if defined(__has_attribute)
84 #if __has_attribute(deprecated)
85 #define BOTAN_FFI_DEPRECATED(msg) __attribute__((deprecated(msg)))
86 #endif
87 #elif defined(_MSC_VER)
88 #define BOTAN_FFI_DEPRECATED(msg) __declspec(deprecated(msg))
89 #endif
90#endif
91
92#if !defined(BOTAN_FFI_DEPRECATED)
93 #define BOTAN_FFI_DEPRECATED(msg) /**/
94#endif
95
96/**
97* Error codes
98*
99* If you add a new value here be sure to also add it in
100* botan_error_description
101*/
133
134typedef void* botan_view_ctx;
135
136/**
137* Viewer function for binary data
138*
139* @param view_ctx some application context
140* @param data the binary data
141* @param len the length of data in bytes
142*/
143typedef int (*botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t* data, size_t len);
144
145/**
146* Viewer function for string data
147*
148* @param view_ctx some application context
149* @param str the null terminated string
150* @param len the length of string *including* the null terminator
151*/
152typedef int (*botan_view_str_fn)(botan_view_ctx view_ctx, const char* str, size_t len);
153
154/**
155* Convert an error code into a string. Returns "Unknown error"
156* if the error code is not a known one.
157*/
158BOTAN_FFI_EXPORT(2, 8) const char* botan_error_description(int err);
159
160/**
161* Return the message of the last exception caught in this thread.
162*
163* This pointer can/will be reallocated or overwritten the next time
164* this thread calls any other Botan FFI function and must be copied
165* to persistent storage first.
166*/
168
169/**
170* Return the version of the currently supported FFI API. This is
171* expressed in the form YYYYMMDD of the release date of this version
172* of the API.
173*/
174BOTAN_FFI_EXPORT(2, 0) uint32_t botan_ffi_api_version(void);
175
176/**
177* Return 0 (ok) if the version given is one this library supports.
178* botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.
179*/
180BOTAN_FFI_EXPORT(2, 0) int botan_ffi_supports_api(uint32_t api_version);
181
182/**
183* Return a free-form version string, e.g., 2.0.0
184*/
185BOTAN_FFI_EXPORT(2, 0) const char* botan_version_string(void);
186
187/**
188* Return the major version of the library
189*/
190BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_major(void);
191
192/**
193* Return the minor version of the library
194*/
195BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_minor(void);
196
197/**
198* Return the patch version of the library
199*/
200BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_patch(void);
201
202/**
203* Return the date this version was released as
204* an integer, or 0 if an unreleased version
205*/
206BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_datestamp(void);
207
208/**
209* Returns 0 if x[0..len] == y[0..len], or otherwise -1
210*/
211BOTAN_FFI_EXPORT(2, 3) int botan_constant_time_compare(const uint8_t* x, const uint8_t* y, size_t len);
212
213/**
214* Deprecated equivalent to botan_constant_time_compare
215*/
217BOTAN_FFI_EXPORT(2, 0) int botan_same_mem(const uint8_t* x, const uint8_t* y, size_t len);
218
219/**
220* Clear out memory using a system specific approach to bypass elision by the
221* compiler (currently using RtlSecureZeroMemory or tricks with volatile pointers).
222*/
223BOTAN_FFI_EXPORT(2, 2) int botan_scrub_mem(void* mem, size_t bytes);
224
225#define BOTAN_FFI_HEX_LOWER_CASE 1
226
227/**
228* Perform hex encoding
229* @param x is some binary data
230* @param len length of x in bytes
231* @param out an array of at least x*2 bytes
232* @param flags flags out be upper or lower case?
233* @return 0 on success, a negative value on failure
234*/
235BOTAN_FFI_EXPORT(2, 0) int botan_hex_encode(const uint8_t* x, size_t len, char* out, uint32_t flags);
236
237/**
238* Perform hex decoding
239* @param hex_str a string of hex chars (whitespace is ignored)
240* @param in_len the length of hex_str
241* @param out the output buffer should be at least strlen(hex_str)/2 bytes
242* @param out_len the size of the output buffer on input, set to the number of bytes written
243* @return 0 on success, a negative value on failure
244*/
245BOTAN_FFI_EXPORT(2, 3) int botan_hex_decode(const char* hex_str, size_t in_len, uint8_t* out, size_t* out_len);
246
247/**
248* Perform base64 encoding
249*/
250BOTAN_FFI_EXPORT(2, 3) int botan_base64_encode(const uint8_t* x, size_t len, char* out, size_t* out_len);
251
252/**
253* Perform base64 decoding
254*/
255BOTAN_FFI_EXPORT(2, 3) int botan_base64_decode(const char* base64_str, size_t in_len, uint8_t* out, size_t* out_len);
256
257/**
258* RNG type
259*/
260typedef struct botan_rng_struct* botan_rng_t;
261
262/**
263* Initialize a random number generator object
264* @param rng rng object
265* @param rng_type type of the rng, possible values:
266* "system": system RNG
267* "user": userspace RNG
268* "user-threadsafe": userspace RNG, with internal locking
269* "rdrand": directly read RDRAND
270* Set rng_type to null to let the library choose some default.
271*/
272BOTAN_FFI_EXPORT(2, 0) int botan_rng_init(botan_rng_t* rng, const char* rng_type);
273
274/**
275* Initialize a custom random number generator from a set of callback functions
276* @param rng_out rng object to create
277* @param rng_name name of the rng
278* @param context An application-specific context passed to the callback functions
279* @param get_cb Callback for getting random bytes from the rng, return 0 for success
280* @param add_entropy_cb Callback for adding entropy to the rng, return 0 for success, may be NULL
281* @param destroy_cb Callback called when rng is destroyed, may be NULL
282*/
285 const char* rng_name,
286 void* context,
287 int (*get_cb)(void* context, uint8_t* out, size_t out_len),
288 int (*add_entropy_cb)(void* context, const uint8_t input[], size_t length),
289 void (*destroy_cb)(void* context));
290
291/**
292* Get random bytes from a random number generator
293* @param rng rng object
294* @param out output buffer of size out_len
295* @param out_len number of requested bytes
296* @return 0 on success, negative on failure
297*/
298BOTAN_FFI_EXPORT(2, 0) int botan_rng_get(botan_rng_t rng, uint8_t* out, size_t out_len);
299
300/**
301* Get random bytes from system random number generator
302* @param out output buffer of size out_len
303* @param out_len number of requested bytes
304* @return 0 on success, negative on failure
305*/
306BOTAN_FFI_EXPORT(3, 0) int botan_system_rng_get(uint8_t* out, size_t out_len);
307
308/**
309* Reseed a random number generator
310* Uses the System_RNG as a seed generator.
311*
312* @param rng rng object
313* @param bits number of bits to reseed with
314* @return 0 on success, a negative value on failure
315*/
316BOTAN_FFI_EXPORT(2, 0) int botan_rng_reseed(botan_rng_t rng, size_t bits);
317
318/**
319* Reseed a random number generator
320*
321* @param rng rng object
322* @param source_rng the rng that will be read from
323* @param bits number of bits to reseed with
324* @return 0 on success, a negative value on failure
325*/
326BOTAN_FFI_EXPORT(2, 8) int botan_rng_reseed_from_rng(botan_rng_t rng, botan_rng_t source_rng, size_t bits);
327
328/**
329* Add some seed material to a random number generator
330*
331* @param rng rng object
332* @param entropy the data to add
333* @param entropy_len length of entropy buffer
334* @return 0 on success, a negative value on failure
335*/
336BOTAN_FFI_EXPORT(2, 8) int botan_rng_add_entropy(botan_rng_t rng, const uint8_t* entropy, size_t entropy_len);
337
338/**
339* Frees all resources of the random number generator object
340* @param rng rng object
341* @return 0 if success, error if invalid object handle
342*/
344
345/*
346* Hash type
347*/
348typedef struct botan_hash_struct* botan_hash_t;
349
350/**
351* Initialize a hash function object
352* @param hash hash object
353* @param hash_name name of the hash function, e.g., "SHA-384"
354* @param flags should be 0 in current API revision, all other uses are reserved
355* and return BOTAN_FFI_ERROR_BAD_FLAG
356*/
357BOTAN_FFI_EXPORT(2, 0) int botan_hash_init(botan_hash_t* hash, const char* hash_name, uint32_t flags);
358
359/**
360* Copy the state of a hash function object
361* @param dest destination hash object
362* @param source source hash object
363* @return 0 on success, a negative value on failure
364*/
366
367/**
368* Writes the output length of the hash function to *output_length
369* @param hash hash object
370* @param output_length output buffer to hold the hash function output length
371* @return 0 on success, a negative value on failure
372*/
373BOTAN_FFI_EXPORT(2, 0) int botan_hash_output_length(botan_hash_t hash, size_t* output_length);
374
375/**
376* Writes the block size of the hash function to *block_size
377* @param hash hash object
378* @param block_size output buffer to hold the hash function output length
379* @return 0 on success, a negative value on failure
380*/
381BOTAN_FFI_EXPORT(2, 2) int botan_hash_block_size(botan_hash_t hash, size_t* block_size);
382
383/**
384* Send more input to the hash function
385* @param hash hash object
386* @param in input buffer
387* @param in_len number of bytes to read from the input buffer
388* @return 0 on success, a negative value on failure
389*/
390BOTAN_FFI_EXPORT(2, 0) int botan_hash_update(botan_hash_t hash, const uint8_t* in, size_t in_len);
391
392/**
393* Finalizes the hash computation and writes the output to
394* out[0:botan_hash_output_length()] then reinitializes for computing
395* another digest as if botan_hash_clear had been called.
396* @param hash hash object
397* @param out output buffer
398* @return 0 on success, a negative value on failure
399*/
400BOTAN_FFI_EXPORT(2, 0) int botan_hash_final(botan_hash_t hash, uint8_t out[]);
401
402/**
403* Reinitializes the state of the hash computation. A hash can
404* be computed (with update/final) immediately.
405* @param hash hash object
406* @return 0 on success, a negative value on failure
407*/
409
410/**
411* Frees all resources of the hash object
412* @param hash hash object
413* @return 0 if success, error if invalid object handle
414*/
416
417/**
418* Get the name of this hash function
419* @param hash the object to read
420* @param name output buffer
421* @param name_len on input, the length of buffer, on success the number of bytes written
422*/
423BOTAN_FFI_EXPORT(2, 8) int botan_hash_name(botan_hash_t hash, char* name, size_t* name_len);
424
425/*
426* Message Authentication type
427*/
428typedef struct botan_mac_struct* botan_mac_t;
429
430/**
431* Initialize a message authentication code object
432* @param mac mac object
433* @param mac_name name of the hash function, e.g., "HMAC(SHA-384)"
434* @param flags should be 0 in current API revision, all other uses are reserved
435* and return a negative value (error code)
436* @return 0 on success, a negative value on failure
437*/
438BOTAN_FFI_EXPORT(2, 0) int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags);
439
440/**
441* Writes the output length of the message authentication code to *output_length
442* @param mac mac object
443* @param output_length output buffer to hold the MAC output length
444* @return 0 on success, a negative value on failure
445*/
446BOTAN_FFI_EXPORT(2, 0) int botan_mac_output_length(botan_mac_t mac, size_t* output_length);
447
448/**
449* Sets the key on the MAC
450* @param mac mac object
451* @param key buffer holding the key
452* @param key_len size of the key buffer in bytes
453* @return 0 on success, a negative value on failure
454*/
455BOTAN_FFI_EXPORT(2, 0) int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len);
456
457/**
458* Sets the nonce on the MAC
459* @param mac mac object
460* @param nonce buffer holding the key
461* @param nonce_len size of the key buffer in bytes
462* @return 0 on success, a negative value on failure
463*/
464BOTAN_FFI_EXPORT(3, 0) int botan_mac_set_nonce(botan_mac_t mac, const uint8_t* nonce, size_t nonce_len);
465
466/**
467* Send more input to the message authentication code
468* @param mac mac object
469* @param buf input buffer
470* @param len number of bytes to read from the input buffer
471* @return 0 on success, a negative value on failure
472*/
473BOTAN_FFI_EXPORT(2, 0) int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len);
474
475/**
476* Finalizes the MAC computation and writes the output to
477* out[0:botan_mac_output_length()] then reinitializes for computing
478* another MAC as if botan_mac_clear had been called.
479* @param mac mac object
480* @param out output buffer
481* @return 0 on success, a negative value on failure
482*/
483BOTAN_FFI_EXPORT(2, 0) int botan_mac_final(botan_mac_t mac, uint8_t out[]);
484
485/**
486* Reinitializes the state of the MAC computation. A MAC can
487* be computed (with update/final) immediately.
488* @param mac mac object
489* @return 0 on success, a negative value on failure
490*/
492
493/**
494* Get the name of this MAC
495* @param mac the object to read
496* @param name output buffer
497* @param name_len on input, the length of buffer, on success the number of bytes written
498*/
499BOTAN_FFI_EXPORT(2, 8) int botan_mac_name(botan_mac_t mac, char* name, size_t* name_len);
500
501/**
502* Get the key length limits of this auth code
503* @param mac the object to read
504* @param out_minimum_keylength if non-NULL, will be set to minimum keylength of MAC
505* @param out_maximum_keylength if non-NULL, will be set to maximum keylength of MAC
506* @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys
507*/
510 size_t* out_minimum_keylength,
511 size_t* out_maximum_keylength,
512 size_t* out_keylength_modulo);
513
514/**
515* Frees all resources of the MAC object
516* @param mac mac object
517* @return 0 if success, error if invalid object handle
518*/
520
521/*
522* Cipher modes
523*/
524typedef struct botan_cipher_struct* botan_cipher_t;
525
526#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION 1
527#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT 0
528#define BOTAN_CIPHER_INIT_FLAG_DECRYPT 1
529
530/**
531* Initialize a cipher object
532*/
533BOTAN_FFI_EXPORT(2, 0) int botan_cipher_init(botan_cipher_t* cipher, const char* name, uint32_t flags);
534
535/**
536* Return the name of the cipher object
537*/
538BOTAN_FFI_EXPORT(2, 8) int botan_cipher_name(botan_cipher_t cipher, char* name, size_t* name_len);
539
540/**
541* Return the output length of this cipher, for a particular input length.
542*/
543BOTAN_FFI_EXPORT(2, 8) int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t* out_len);
544
545/**
546* Return if the specified nonce length is valid for this cipher
547*/
549
550/**
551* Get the tag length of the cipher (0 for non-AEAD modes)
552*/
553BOTAN_FFI_EXPORT(2, 0) int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t* tag_size);
554
555/**
556* Returns 1 iff the cipher provides authentication as well as confidentiality.
557*/
559
560/**
561 * Returns 1 iff the cipher requires the entire message before any
562 * encryption or decryption can be performed. No output data will be produced
563 * in botan_cipher_update() until the final flag is set.
564 */
566
567/**
568* Get the default nonce length of this cipher
569*/
571
572/**
573* Return the update granularity of the cipher; botan_cipher_update must be
574* called with blocks of this size, except for the final.
575*/
577
578/**
579* Return the ideal update granularity of the cipher. This is some multiple of the
580* update granularity, reflecting possibilities for optimization.
581*/
583
584/**
585* Get information about the key lengths. Prefer botan_cipher_get_keyspec
586*/
588int botan_cipher_query_keylen(botan_cipher_t, size_t* out_minimum_keylength, size_t* out_maximum_keylength);
589
590/**
591* Get information about the supported key lengths.
592*/
594int botan_cipher_get_keyspec(botan_cipher_t, size_t* min_keylen, size_t* max_keylen, size_t* mod_keylen);
595
596/**
597* Set the key for this cipher object
598*/
599BOTAN_FFI_EXPORT(2, 0) int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t* key, size_t key_len);
600
601/**
602* Reset the message specific state for this cipher.
603* Without resetting the keys, this resets the nonce, and any state
604* associated with any message bits that have been processed so far.
605*
606* It is conceptually equivalent to calling botan_cipher_clear followed
607* by botan_cipher_set_key with the original key.
608*/
610
611/**
612* Set the associated data. Will fail if cipher is not an AEAD
613*/
614BOTAN_FFI_EXPORT(2, 0) int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t* ad, size_t ad_len);
615
616/**
617* Begin processing a new message using the provided nonce
618*/
619BOTAN_FFI_EXPORT(2, 0) int botan_cipher_start(botan_cipher_t cipher, const uint8_t* nonce, size_t nonce_len);
620
621#define BOTAN_CIPHER_UPDATE_FLAG_FINAL (1U << 0)
622
623/**
624* @brief Encrypt/Decrypt some data and/or finalize the encryption/decryption
625*
626* This encrypts as many bytes from @p input_bytes into @p output_bytes as
627* possible. Unless ``BOTAN_CIPHER_UPDATE_FLAG_FINAL`` is set, this function will
628* consume bytes in multiples of botan_cipher_get_update_granularity().
629* @p input_consumed and @p output_written will be set accordingly and it is the
630* caller's responsibility to adapt their buffers accordingly before calling this
631* function again. Note that, unless ``BOTAN_CIPHER_UPDATE_FLAG_FINAL`` is set,
632* the cipher will at most generate @p input_size output bytes.
633*
634* Eventually, the caller must set the ``BOTAN_CIPHER_UPDATE_FLAG_FINAL`` flag to
635* indicate that no more input will be provided. This will cause the cipher to
636* consume all given input bytes and produce the final output; or return a
637* ``BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE`` error if the given output buffer
638* was too small. In the latter case, @p output_written will be set to the
639* required buffer size. Calling again with ``BOTAN_CIPHER_UPDATE_FLAG_FINAL``, a
640* big enough buffer and no further input will then produce the final output.
641*
642* Note that some ciphers require the entire message to be provided before any
643* output is produced. @sa botan_cipher_requires_entire_message().
644*/
647 uint32_t flags,
648 uint8_t output[],
649 size_t output_size,
650 size_t* output_written,
651 const uint8_t input_bytes[],
652 size_t input_size,
653 size_t* input_consumed);
654
655/**
656* Reset the key, nonce, AD and all other state on this cipher object
657*/
659
660/**
661* Destroy the cipher object
662* @return 0 if success, error if invalid object handle
663*/
665
666/*
667* Derive a key from a passphrase for a number of iterations
668* @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
669* @param out buffer to store the derived key, must be of out_len bytes
670* @param out_len the desired length of the key to produce
671* @param passphrase the password to derive the key from
672* @param salt a randomly chosen salt
673* @param salt_len length of salt in bytes
674* @param iterations the number of iterations to use (use 10K or more)
675* @return 0 on success, a negative value on failure
676*
677* Deprecated: use
678* botan_pwdhash(pbkdf_algo, iterations, 0, 0, out, out_len,
679* passphrase, 0, salt, salt_len);
680*/
683int botan_pbkdf(const char* pbkdf_algo,
684 uint8_t out[],
685 size_t out_len,
686 const char* passphrase,
687 const uint8_t salt[],
688 size_t salt_len,
689 size_t iterations);
690
691/**
692* Derive a key from a passphrase, running until msec time has elapsed.
693* @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
694* @param out buffer to store the derived key, must be of out_len bytes
695* @param out_len the desired length of the key to produce
696* @param passphrase the password to derive the key from
697* @param salt a randomly chosen salt
698* @param salt_len length of salt in bytes
699* @param milliseconds_to_run if iterations is zero, then instead the PBKDF is
700* run until milliseconds_to_run milliseconds has passed
701* @param out_iterations_used set to the number iterations executed
702* @return 0 on success, a negative value on failure
703*
704* Deprecated: use
705*
706* botan_pwdhash_timed(pbkdf_algo,
707* static_cast<uint32_t>(ms_to_run),
708* iterations_used,
709* nullptr,
710* nullptr,
711* out, out_len,
712* password, 0,
713* salt, salt_len);
714*/
716int botan_pbkdf_timed(const char* pbkdf_algo,
717 uint8_t out[],
718 size_t out_len,
719 const char* passphrase,
720 const uint8_t salt[],
721 size_t salt_len,
722 size_t milliseconds_to_run,
723 size_t* out_iterations_used);
724
725/*
726* Derive a key from a passphrase
727* @param algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)" or "Scrypt"
728* @param param1 the first PBKDF algorithm parameter
729* @param param2 the second PBKDF algorithm parameter (may be zero if unneeded)
730* @param param3 the third PBKDF algorithm parameter (may be zero if unneeded)
731* @param out buffer to store the derived key, must be of out_len bytes
732* @param out_len the desired length of the key to produce
733* @param passphrase the password to derive the key from
734* @param passphrase_len if > 0, specifies length of password. If len == 0, then
735* strlen will be called on passphrase to compute the length.
736* @param salt a randomly chosen salt
737* @param salt_len length of salt in bytes
738* @return 0 on success, a negative value on failure
739*/
740int BOTAN_FFI_EXPORT(2, 8) botan_pwdhash(const char* algo,
741 size_t param1,
742 size_t param2,
743 size_t param3,
744 uint8_t out[],
745 size_t out_len,
746 const char* passphrase,
747 size_t passphrase_len,
748 const uint8_t salt[],
749 size_t salt_len);
750
751/*
752* Derive a key from a passphrase
753* @param pbkdf_algo PBKDF algorithm, e.g., "Scrypt" or "PBKDF2(SHA-256)"
754* @param msec the desired runtime in milliseconds
755* @param param1 will be set to the first password hash parameter
756* @param param2 will be set to the second password hash parameter
757* @param param3 will be set to the third password hash parameter
758* @param out buffer to store the derived key, must be of out_len bytes
759* @param out_len the desired length of the key to produce
760* @param passphrase the password to derive the key from
761* @param passphrase_len if > 0, specifies length of password. If len == 0, then
762* strlen will be called on passphrase to compute the length.
763* @param salt a randomly chosen salt
764* @param salt_len length of salt in bytes
765* @return 0 on success, a negative value on failure
766*/
767int BOTAN_FFI_EXPORT(2, 8) botan_pwdhash_timed(const char* algo,
768 uint32_t msec,
769 size_t* param1,
770 size_t* param2,
771 size_t* param3,
772 uint8_t out[],
773 size_t out_len,
774 const char* passphrase,
775 size_t passphrase_len,
776 const uint8_t salt[],
777 size_t salt_len);
778
779/**
780* Derive a key using scrypt
781* Deprecated; use
782* botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
783*/
786int botan_scrypt(uint8_t out[],
787 size_t out_len,
788 const char* passphrase,
789 const uint8_t salt[],
790 size_t salt_len,
791 size_t N,
792 size_t r,
793 size_t p);
794
795/**
796* Derive a key
797* @param kdf_algo KDF algorithm, e.g., "SP800-56C"
798* @param out buffer holding the derived key, must be of length out_len
799* @param out_len the desired output length in bytes
800* @param secret the secret input
801* @param secret_len size of secret in bytes
802* @param salt a diversifier
803* @param salt_len size of salt in bytes
804* @param label purpose for the derived keying material
805* @param label_len size of label in bytes
806* @return 0 on success, a negative value on failure
807*/
809int botan_kdf(const char* kdf_algo,
810 uint8_t out[],
811 size_t out_len,
812 const uint8_t secret[],
813 size_t secret_len,
814 const uint8_t salt[],
815 size_t salt_len,
816 const uint8_t label[],
817 size_t label_len);
818
819/*
820* Raw Block Cipher (PRP) interface
821*/
822typedef struct botan_block_cipher_struct* botan_block_cipher_t;
823
824/**
825* Initialize a block cipher object
826*/
827BOTAN_FFI_EXPORT(2, 1) int botan_block_cipher_init(botan_block_cipher_t* bc, const char* cipher_name);
828
829/**
830* Destroy a block cipher object
831* @return 0 if success, error if invalid object handle
832*/
834
835/**
836* Reinitializes the block cipher
837* @return 0 on success, a negative value on failure
838*/
840
841/**
842* Set the key for a block cipher instance
843*/
844BOTAN_FFI_EXPORT(2, 1) int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], size_t len);
845
846/**
847* Return the positive block size of this block cipher, or negative to
848* indicate an error
849*/
851
852/**
853* Encrypt one or more blocks with the cipher
854*/
856int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks);
857
858/**
859* Decrypt one or more blocks with the cipher
860*/
862int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks);
863
864/**
865* Get the name of this block cipher
866* @param cipher the object to read
867* @param name output buffer
868* @param name_len on input, the length of buffer, on success the number of bytes written
869*/
870BOTAN_FFI_EXPORT(2, 8) int botan_block_cipher_name(botan_block_cipher_t cipher, char* name, size_t* name_len);
871
872/**
873* Get the key length limits of this block cipher
874* @param cipher the object to read
875* @param out_minimum_keylength if non-NULL, will be set to minimum keylength of cipher
876* @param out_maximum_keylength if non-NULL, will be set to maximum keylength of cipher
877* @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys
878*/
881 size_t* out_minimum_keylength,
882 size_t* out_maximum_keylength,
883 size_t* out_keylength_modulo);
884
885/*
886* Multiple precision integers (MPI)
887*/
888typedef struct botan_mp_struct* botan_mp_t;
889
890/**
891* Initialize an MPI
892*/
894
895/**
896* Destroy (deallocate) an MPI
897* @return 0 if success, error if invalid object handle
898*/
900
901/**
902* Convert the MPI to a hex string. Writes botan_mp_num_bytes(mp)*2 + 1 bytes
903*/
904BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_hex(botan_mp_t mp, char* out);
905
906/**
907* Convert the MPI to a string. Currently base == 10 and base == 16 are supported.
908*/
909BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_str(botan_mp_t mp, uint8_t base, char* out, size_t* out_len);
910
911/**
912* Set the MPI to zero
913*/
915
916/**
917* Set the MPI value from an int
918*/
919BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_from_int(botan_mp_t mp, int initial_value);
920
921/**
922* Set the MPI value from another MP object
923*/
925
926/**
927* Set the MPI value from a string
928*/
929BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_from_str(botan_mp_t dest, const char* str);
930
931/**
932* Set the MPI value from a string with arbitrary radix.
933* For arbitrary being 10 or 16.
934*/
935BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_from_radix_str(botan_mp_t dest, const char* str, size_t radix);
936
937/**
938* Return the number of significant bits in the MPI
939*/
940BOTAN_FFI_EXPORT(2, 1) int botan_mp_num_bits(botan_mp_t n, size_t* bits);
941
942/**
943* Return the number of significant bytes in the MPI
944*/
945BOTAN_FFI_EXPORT(2, 1) int botan_mp_num_bytes(botan_mp_t n, size_t* bytes);
946
947/*
948* Convert the MPI to a big-endian binary string. Writes botan_mp_num_bytes to vec
949*/
950BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_bin(botan_mp_t mp, uint8_t vec[]);
951
952/*
953* Set an MP to the big-endian binary value
954*/
955BOTAN_FFI_EXPORT(2, 1) int botan_mp_from_bin(botan_mp_t mp, const uint8_t vec[], size_t vec_len);
956
957/*
958* Convert the MPI to a uint32_t, if possible. Fails if MPI is negative or too large.
959*/
960BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_uint32(botan_mp_t mp, uint32_t* val);
961
962/**
963* This function should have been named mp_is_non_negative. Returns 1
964* iff mp is greater than *or equal to* zero. Use botan_mp_is_negative
965* to detect negative numbers, botan_mp_is_zero to check for zero.
966*/
968
969/**
970* Return 1 iff mp is less than 0
971*/
973
975
977
980
981BOTAN_FFI_EXPORT(2, 8) int botan_mp_add_u32(botan_mp_t result, botan_mp_t x, uint32_t y);
982BOTAN_FFI_EXPORT(2, 8) int botan_mp_sub_u32(botan_mp_t result, botan_mp_t x, uint32_t y);
983
987
989int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, botan_mp_t x, botan_mp_t y);
990
993
994/*
995* Returns 0 if x != y
996* Returns 1 if x == y
997* Returns negative number on error
998*/
1000
1001/*
1002* Sets *result to comparison result:
1003* -1 if x < y, 0 if x == y, 1 if x > y
1004* Returns negative number on error or zero on success
1005*/
1006BOTAN_FFI_EXPORT(2, 1) int botan_mp_cmp(int* result, botan_mp_t x, botan_mp_t y);
1007
1008/*
1009* Swap two botan_mp_t
1010*/
1012
1013/* Return (base^exponent) % modulus */
1014BOTAN_FFI_EXPORT(2, 1)
1015int botan_mp_powmod(botan_mp_t out, botan_mp_t base, botan_mp_t exponent, botan_mp_t modulus);
1016
1017BOTAN_FFI_EXPORT(2, 1) int botan_mp_lshift(botan_mp_t out, botan_mp_t in, size_t shift);
1018BOTAN_FFI_EXPORT(2, 1) int botan_mp_rshift(botan_mp_t out, botan_mp_t in, size_t shift);
1019
1021
1022BOTAN_FFI_EXPORT(2, 1) int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits);
1023
1024BOTAN_FFI_EXPORT(2, 1)
1025int botan_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng, botan_mp_t lower_bound, botan_mp_t upper_bound);
1026
1028
1029/**
1030* Returns 0 if n is not prime
1031* Returns 1 if n is prime
1032* Returns negative number on error
1033*/
1034BOTAN_FFI_EXPORT(2, 1) int botan_mp_is_prime(botan_mp_t n, botan_rng_t rng, size_t test_prob);
1035
1036/**
1037* Returns 0 if specified bit of n is not set
1038* Returns 1 if specified bit of n is set
1039* Returns negative number on error
1040*/
1041BOTAN_FFI_EXPORT(2, 1) int botan_mp_get_bit(botan_mp_t n, size_t bit);
1042
1043/**
1044* Set the specified bit
1045*/
1046BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_bit(botan_mp_t n, size_t bit);
1047
1048/**
1049* Clear the specified bit
1050*/
1051BOTAN_FFI_EXPORT(2, 1) int botan_mp_clear_bit(botan_mp_t n, size_t bit);
1052
1053/* Bcrypt password hashing */
1054
1055/**
1056* Create a password hash using Bcrypt
1057* @param out buffer holding the password hash, should be of length 64 bytes
1058* @param out_len the desired output length in bytes
1059* @param password the password
1060* @param rng a random number generator
1061* @param work_factor how much work to do to slow down guessing attacks
1062* @param flags should be 0 in current API revision, all other uses are reserved
1063* and return BOTAN_FFI_ERROR_BAD_FLAG
1064* @return 0 on success, a negative value on failure
1065
1066* Output is formatted bcrypt $2a$...
1067*/
1068BOTAN_FFI_EXPORT(2, 0)
1070 uint8_t* out, size_t* out_len, const char* password, botan_rng_t rng, size_t work_factor, uint32_t flags);
1071
1072/**
1073* Check a previously created password hash
1074* @param pass the password to check against
1075* @param hash the stored hash to check against
1076* @return 0 if if this password/hash combination is valid,
1077* 1 if the combination is not valid (but otherwise well formed),
1078* negative on error
1079*/
1080BOTAN_FFI_EXPORT(2, 0) int botan_bcrypt_is_valid(const char* pass, const char* hash);
1081
1082/*
1083* Public/private key creation, import, ...
1084*/
1085typedef struct botan_privkey_struct* botan_privkey_t;
1086
1087/**
1088* Create a new private key
1089* @param key the new object will be placed here
1090* @param algo_name something like "RSA" or "ECDSA"
1091* @param algo_params is specific to the algorithm. For RSA, specifies
1092* the modulus bit length. For ECC is the name of the curve.
1093* @param rng a random number generator
1094*/
1095BOTAN_FFI_EXPORT(2, 0)
1096int botan_privkey_create(botan_privkey_t* key, const char* algo_name, const char* algo_params, botan_rng_t rng);
1097
1098#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS 1
1099
1100BOTAN_FFI_EXPORT(2, 0) int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags);
1101
1103BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_rsa(botan_privkey_t* key, botan_rng_t rng, size_t n_bits);
1105BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_ecdsa(botan_privkey_t* key, botan_rng_t rng, const char* params);
1107BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, const char* params);
1109BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_mceliece(botan_privkey_t* key, botan_rng_t rng, size_t n, size_t t);
1111BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_dh(botan_privkey_t* key, botan_rng_t rng, const char* param);
1112
1113/**
1114 * Generates DSA key pair. Gives to a caller control over key length
1115 * and order of a subgroup 'q'.
1116 *
1117 * @param key handler to the resulting key
1118 * @param rng initialized PRNG
1119 * @param pbits length of the key in bits. Must be between in range (1024, 3072)
1120 * and multiple of 64. Bit size of the prime 'p'
1121 * @param qbits order of the subgroup. Must be in range (160, 256) and multiple
1122 * of 8
1123 *
1124 * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
1125 * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
1126 * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
1127 * `qbits'
1128 * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
1129 *
1130*/
1131BOTAN_FFI_EXPORT(2, 5) int botan_privkey_create_dsa(botan_privkey_t* key, botan_rng_t rng, size_t pbits, size_t qbits);
1132
1133/**
1134 * Generates ElGamal key pair. Caller has a control over key length
1135 * and order of a subgroup 'q'. Function is able to use two types of
1136 * primes:
1137 * * if pbits-1 == qbits then safe primes are used for key generation
1138 * * otherwise generation uses group of prime order
1139 *
1140 * @param key handler to the resulting key
1141 * @param rng initialized PRNG
1142 * @param pbits length of the key in bits. Must be at least 1024
1143 * @param qbits order of the subgroup. Must be at least 160
1144 *
1145 * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
1146 * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
1147 * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
1148 * `qbits'
1149 * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
1150 *
1151*/
1152BOTAN_FFI_EXPORT(2, 5)
1153int botan_privkey_create_elgamal(botan_privkey_t* key, botan_rng_t rng, size_t pbits, size_t qbits);
1154
1155/**
1156* Input currently assumed to be PKCS #8 structure;
1157* Set password to NULL to indicate no encryption expected
1158* Starting in 2.8.0, the rng parameter is unused and may be set to null
1159*/
1160BOTAN_FFI_EXPORT(2, 0)
1161int botan_privkey_load(botan_privkey_t* key, botan_rng_t rng, const uint8_t bits[], size_t len, const char* password);
1162
1163/**
1164* @return 0 if success, error if invalid object handle
1165*/
1167
1168#define BOTAN_PRIVKEY_EXPORT_FLAG_DER 0
1169#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM 1
1170
1171/**
1172* On input *out_len is number of bytes in out[]
1173* On output *out_len is number of bytes written (or required)
1174* If out is not big enough no output is written, *out_len is set and 1 is returned
1175* Returns 0 on success and sets
1176* If some other error occurs a negative integer is returned.
1177*/
1178BOTAN_FFI_EXPORT(2, 0) int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t* out_len, uint32_t flags);
1179
1180/**
1181* View the private key's DER encoding
1182*/
1184
1185/**
1186* View the private key's PEM encoding
1187*/
1189
1190BOTAN_FFI_EXPORT(2, 8) int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t* out_len);
1191
1192/**
1193* Set encryption_algo to NULL or "" to have the library choose a default (recommended)
1194*/
1195BOTAN_FFI_DEPRECATED("Use botan_privkey_export_encrypted_pbkdf_{msec,iter}")
1196BOTAN_FFI_EXPORT(2, 0)
1197int botan_privkey_export_encrypted(botan_privkey_t key,
1198 uint8_t out[],
1199 size_t* out_len,
1200 botan_rng_t rng,
1201 const char* passphrase,
1202 const char* encryption_algo,
1203 uint32_t flags);
1204
1205/*
1206* Export a private key, running PBKDF for specified amount of time
1207* @param key the private key to export
1208*
1209* Note: starting in 3.0, the output iterations count is not provided
1210*/
1211BOTAN_FFI_EXPORT(2, 0)
1212int botan_privkey_export_encrypted_pbkdf_msec(botan_privkey_t key,
1213 uint8_t out[],
1214 size_t* out_len,
1215 botan_rng_t rng,
1216 const char* passphrase,
1217 uint32_t pbkdf_msec_runtime,
1218 size_t* pbkdf_iterations_out,
1219 const char* cipher_algo,
1220 const char* pbkdf_algo,
1221 uint32_t flags);
1222
1223/**
1224* Export a private key using the specified number of iterations.
1225*/
1226BOTAN_FFI_EXPORT(2, 0)
1227int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key,
1228 uint8_t out[],
1229 size_t* out_len,
1230 botan_rng_t rng,
1231 const char* passphrase,
1232 size_t pbkdf_iterations,
1233 const char* cipher_algo,
1234 const char* pbkdf_algo,
1235 uint32_t flags);
1236
1237/**
1238* View the encryption of a private key (binary DER encoding)
1239*
1240* Set cipher_algo, pbkdf_algo to NULL to use defaults
1241* Set pbkdf_iterations to 0 to use defaults
1242*/
1243BOTAN_FFI_EXPORT(3, 0)
1244int botan_privkey_view_encrypted_der(botan_privkey_t key,
1245 botan_rng_t rng,
1246 const char* passphrase,
1247 const char* cipher_algo,
1248 const char* pbkdf_algo,
1249 size_t pbkdf_iterations,
1250 botan_view_ctx ctx,
1251 botan_view_bin_fn view);
1252
1253/**
1254* View the encryption of a private key (binary DER encoding)
1255*
1256* Set cipher_algo, pbkdf_algo to NULL to use defaults
1257*/
1258BOTAN_FFI_EXPORT(3, 0)
1259int botan_privkey_view_encrypted_der_timed(botan_privkey_t key,
1260 botan_rng_t rng,
1261 const char* passphrase,
1262 const char* cipher_algo,
1263 const char* pbkdf_algo,
1264 size_t pbkdf_runtime_msec,
1265 botan_view_ctx ctx,
1266 botan_view_bin_fn view);
1267
1268/**
1269* View the encryption of a private key (PEM encoding)
1270*
1271* Set cipher_algo, pbkdf_algo to NULL to use defaults
1272* Set pbkdf_iterations to 0 to use defaults
1273*/
1274BOTAN_FFI_EXPORT(3, 0)
1275int botan_privkey_view_encrypted_pem(botan_privkey_t key,
1276 botan_rng_t rng,
1277 const char* passphrase,
1278 const char* cipher_algo,
1279 const char* pbkdf_algo,
1280 size_t pbkdf_iterations,
1281 botan_view_ctx ctx,
1282 botan_view_str_fn view);
1283
1284/**
1285* View the encryption of a private key (PEM encoding)
1286*
1287* Set cipher_algo, pbkdf_algo to NULL to use defaults
1288*/
1289BOTAN_FFI_EXPORT(3, 0)
1290int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key,
1291 botan_rng_t rng,
1292 const char* passphrase,
1293 const char* cipher_algo,
1294 const char* pbkdf_algo,
1295 size_t pbkdf_runtime_msec,
1296 botan_view_ctx ctx,
1297 botan_view_str_fn view);
1298
1299typedef struct botan_pubkey_struct* botan_pubkey_t;
1300
1301BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t len);
1302
1303BOTAN_FFI_EXPORT(2, 0) int botan_privkey_export_pubkey(botan_pubkey_t* out, botan_privkey_t in);
1304
1305BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags);
1306
1307/**
1308* View the public key's DER encoding
1309*/
1310BOTAN_FFI_EXPORT(3, 0) int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view);
1311
1312/**
1313* View the public key's PEM encoding
1314*/
1315BOTAN_FFI_EXPORT(3, 0) int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view);
1316
1317BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len);
1318
1319/**
1320* Returns 0 if key is valid, negative if invalid key or some other error
1321*/
1322BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags);
1323
1324BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate);
1325
1326BOTAN_FFI_EXPORT(2, 0)
1327int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash, uint8_t out[], size_t* out_len);
1328
1329/**
1330* @return 0 if success, error if invalid object handle
1331*/
1332BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_destroy(botan_pubkey_t key);
1333
1334/*
1335* Get arbitrary named fields from public or private keys
1336*/
1337BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char* field_name);
1338
1339BOTAN_FFI_EXPORT(2, 0) int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char* field_name);
1340
1341/*
1342* Algorithm specific key operations: RSA
1343*/
1344BOTAN_FFI_EXPORT(2, 0) int botan_privkey_load_rsa(botan_privkey_t* key, botan_mp_t p, botan_mp_t q, botan_mp_t e);
1345
1346BOTAN_FFI_EXPORT(2, 8) int botan_privkey_load_rsa_pkcs1(botan_privkey_t* key, const uint8_t bits[], size_t len);
1347
1348BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
1349BOTAN_FFI_EXPORT(2, 0) int botan_privkey_rsa_get_p(botan_mp_t p, botan_privkey_t rsa_key);
1350BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
1351BOTAN_FFI_EXPORT(2, 0) int botan_privkey_rsa_get_q(botan_mp_t q, botan_privkey_t rsa_key);
1352BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
1353BOTAN_FFI_EXPORT(2, 0) int botan_privkey_rsa_get_d(botan_mp_t d, botan_privkey_t rsa_key);
1354BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
1355BOTAN_FFI_EXPORT(2, 0) int botan_privkey_rsa_get_n(botan_mp_t n, botan_privkey_t rsa_key);
1356BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
1357BOTAN_FFI_EXPORT(2, 0) int botan_privkey_rsa_get_e(botan_mp_t e, botan_privkey_t rsa_key);
1358
1359BOTAN_FFI_EXPORT(2, 8)
1360int botan_privkey_rsa_get_privkey(botan_privkey_t rsa_key, uint8_t out[], size_t* out_len, uint32_t flags);
1361
1362BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_load_rsa(botan_pubkey_t* key, botan_mp_t n, botan_mp_t e);
1363
1364BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
1365BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_rsa_get_e(botan_mp_t e, botan_pubkey_t rsa_key);
1366BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
1367BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t rsa_key);
1368
1369/*
1370* Algorithm specific key operations: DSA
1371*/
1372BOTAN_FFI_EXPORT(2, 0)
1373int botan_privkey_load_dsa(botan_privkey_t* key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x);
1374
1375BOTAN_FFI_EXPORT(2, 0)
1376int botan_pubkey_load_dsa(botan_pubkey_t* key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t y);
1377
1378BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
1379BOTAN_FFI_EXPORT(2, 0) int botan_privkey_dsa_get_x(botan_mp_t n, botan_privkey_t key);
1380
1381BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
1382BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_dsa_get_p(botan_mp_t p, botan_pubkey_t key);
1383BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
1384BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_dsa_get_q(botan_mp_t q, botan_pubkey_t key);
1385BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
1386BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_dsa_get_g(botan_mp_t d, botan_pubkey_t key);
1387BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
1388BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_dsa_get_y(botan_mp_t y, botan_pubkey_t key);
1389
1390/*
1391* Loads Diffie Hellman private key
1392*
1393* @param key variable populated with key material
1394* @param p prime order of a Z_p group
1395* @param g group generator
1396* @param x private key
1397*
1398* @pre key is NULL on input
1399* @post function allocates memory and assigns to `key'
1400*
1401* @return 0 on success, a negative value on failure
1402*/
1403BOTAN_FFI_EXPORT(2, 0) int botan_privkey_load_dh(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x);
1404/**
1405* Loads Diffie Hellman public key
1406*
1407* @param key variable populated with key material
1408* @param p prime order of a Z_p group
1409* @param g group generator
1410* @param y public key
1411*
1412* @pre key is NULL on input
1413* @post function allocates memory and assigns to `key'
1414*
1415* @return 0 on success, a negative value on failure
1416*/
1417BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_load_dh(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y);
1418
1419/*
1420* Algorithm specific key operations: ElGamal
1421*/
1422
1423/**
1424* Loads ElGamal public key
1425* @param key variable populated with key material
1426* @param p prime order of a Z_p group
1427* @param g group generator
1428* @param y public key
1429*
1430* @pre key is NULL on input
1431* @post function allocates memory and assigns to `key'
1432*
1433* @return 0 on success, a negative value on failure
1434*/
1435BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_load_elgamal(botan_pubkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t y);
1436
1437/**
1438* Loads ElGamal private key
1439*
1440* @param key variable populated with key material
1441* @param p prime order of a Z_p group
1442* @param g group generator
1443* @param x private key
1444*
1445* @pre key is NULL on input
1446* @post function allocates memory and assigns to `key'
1447*
1448* @return 0 on success, a negative value on failure
1449*/
1450BOTAN_FFI_EXPORT(2, 0) int botan_privkey_load_elgamal(botan_privkey_t* key, botan_mp_t p, botan_mp_t g, botan_mp_t x);
1451
1452/*
1453* Algorithm specific key operations: Ed25519
1454*/
1455
1456BOTAN_FFI_EXPORT(2, 2) int botan_privkey_load_ed25519(botan_privkey_t* key, const uint8_t privkey[32]);
1457
1458BOTAN_FFI_EXPORT(2, 2) int botan_pubkey_load_ed25519(botan_pubkey_t* key, const uint8_t pubkey[32]);
1459
1460BOTAN_FFI_EXPORT(2, 2) int botan_privkey_ed25519_get_privkey(botan_privkey_t key, uint8_t output[64]);
1461
1462BOTAN_FFI_EXPORT(2, 2) int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key, uint8_t pubkey[32]);
1463
1464/*
1465* Algorithm specific key operations: Ed448
1466*/
1467
1468BOTAN_FFI_EXPORT(3, 4) int botan_privkey_load_ed448(botan_privkey_t* key, const uint8_t privkey[57]);
1469
1470BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_load_ed448(botan_pubkey_t* key, const uint8_t pubkey[57]);
1471
1472BOTAN_FFI_EXPORT(3, 4) int botan_privkey_ed448_get_privkey(botan_privkey_t key, uint8_t output[57]);
1473
1474BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_ed448_get_pubkey(botan_pubkey_t key, uint8_t pubkey[57]);
1475
1476/*
1477* Algorithm specific key operations: X25519
1478*/
1479
1480BOTAN_FFI_EXPORT(2, 8) int botan_privkey_load_x25519(botan_privkey_t* key, const uint8_t privkey[32]);
1481
1482BOTAN_FFI_EXPORT(2, 8) int botan_pubkey_load_x25519(botan_pubkey_t* key, const uint8_t pubkey[32]);
1483
1484BOTAN_FFI_EXPORT(2, 8) int botan_privkey_x25519_get_privkey(botan_privkey_t key, uint8_t output[32]);
1485
1486BOTAN_FFI_EXPORT(2, 8) int botan_pubkey_x25519_get_pubkey(botan_pubkey_t key, uint8_t pubkey[32]);
1487
1488/*
1489* Algorithm specific key operations: X448
1490*/
1491
1492BOTAN_FFI_EXPORT(3, 4) int botan_privkey_load_x448(botan_privkey_t* key, const uint8_t privkey[56]);
1493
1494BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_load_x448(botan_pubkey_t* key, const uint8_t pubkey[56]);
1495
1496BOTAN_FFI_EXPORT(3, 4) int botan_privkey_x448_get_privkey(botan_privkey_t key, uint8_t output[56]);
1497
1498BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_x448_get_pubkey(botan_pubkey_t key, uint8_t pubkey[56]);
1499
1500/*
1501* Algorithm specific key operations: Kyber
1502*/
1503
1504BOTAN_FFI_EXPORT(3, 1) int botan_privkey_load_kyber(botan_privkey_t* key, const uint8_t privkey[], size_t key_len);
1505
1506BOTAN_FFI_EXPORT(3, 1) int botan_pubkey_load_kyber(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len);
1507
1508BOTAN_FFI_EXPORT(3, 1)
1509int botan_privkey_view_kyber_raw_key(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view);
1510
1511BOTAN_FFI_EXPORT(3, 1)
1512int botan_pubkey_view_kyber_raw_key(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view);
1513
1514/*
1515* Algorithm specific key operations: ECDSA and ECDH
1516*/
1517BOTAN_FFI_EXPORT(3, 2)
1518int botan_pubkey_ecc_key_used_explicit_encoding(botan_pubkey_t key);
1519
1520BOTAN_FFI_EXPORT(2, 2)
1521int botan_privkey_load_ecdsa(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
1522
1523BOTAN_FFI_EXPORT(2, 2)
1524int botan_pubkey_load_ecdsa(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
1525
1526BOTAN_FFI_EXPORT(2, 2)
1527int botan_pubkey_load_ecdh(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
1528
1529BOTAN_FFI_EXPORT(2, 2)
1530int botan_privkey_load_ecdh(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
1531
1532BOTAN_FFI_EXPORT(2, 2)
1533int botan_pubkey_load_sm2(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
1534
1535BOTAN_FFI_EXPORT(2, 2)
1536int botan_privkey_load_sm2(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
1537
1538BOTAN_FFI_DEPRECATED("Use botan_pubkey_load_sm2")
1539BOTAN_FFI_EXPORT(2, 2)
1540int botan_pubkey_load_sm2_enc(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
1541
1542BOTAN_FFI_DEPRECATED("Use botan_privkey_load_sm2")
1543BOTAN_FFI_EXPORT(2, 2)
1544int botan_privkey_load_sm2_enc(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
1545
1546BOTAN_FFI_EXPORT(2, 3)
1547int botan_pubkey_sm2_compute_za(
1548 uint8_t out[], size_t* out_len, const char* ident, const char* hash_algo, botan_pubkey_t key);
1549
1550/**
1551* View the uncompressed public point associated with the key
1552*/
1553BOTAN_FFI_EXPORT(3, 0)
1554int botan_pubkey_view_ec_public_point(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view);
1555
1556/*
1557* Public Key Encryption
1558*/
1559typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t;
1560
1561BOTAN_FFI_EXPORT(2, 0)
1562int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t* op, botan_pubkey_t key, const char* padding, uint32_t flags);
1563
1564/**
1565* @return 0 if success, error if invalid object handle
1566*/
1567BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_encrypt_destroy(botan_pk_op_encrypt_t op);
1568
1569BOTAN_FFI_EXPORT(2, 8)
1570int botan_pk_op_encrypt_output_length(botan_pk_op_encrypt_t op, size_t ptext_len, size_t* ctext_len);
1571
1572BOTAN_FFI_EXPORT(2, 0)
1573int botan_pk_op_encrypt(botan_pk_op_encrypt_t op,
1574 botan_rng_t rng,
1575 uint8_t out[],
1576 size_t* out_len,
1577 const uint8_t plaintext[],
1578 size_t plaintext_len);
1579
1580/*
1581* Public Key Decryption
1582*/
1583typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t;
1584
1585BOTAN_FFI_EXPORT(2, 0)
1586int botan_pk_op_decrypt_create(botan_pk_op_decrypt_t* op, botan_privkey_t key, const char* padding, uint32_t flags);
1587
1588/**
1589* @return 0 if success, error if invalid object handle
1590*/
1591BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_decrypt_destroy(botan_pk_op_decrypt_t op);
1592
1593BOTAN_FFI_EXPORT(2, 8)
1594int botan_pk_op_decrypt_output_length(botan_pk_op_decrypt_t op, size_t ctext_len, size_t* ptext_len);
1595
1596BOTAN_FFI_EXPORT(2, 0)
1597int botan_pk_op_decrypt(
1598 botan_pk_op_decrypt_t op, uint8_t out[], size_t* out_len, const uint8_t ciphertext[], size_t ciphertext_len);
1599
1600/*
1601* Signature Generation
1602*/
1603
1604#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE 1
1605
1606typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t;
1607
1608BOTAN_FFI_EXPORT(2, 0)
1609int botan_pk_op_sign_create(botan_pk_op_sign_t* op, botan_privkey_t key, const char* hash_and_padding, uint32_t flags);
1610
1611/**
1612* @return 0 if success, error if invalid object handle
1613*/
1614BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_sign_destroy(botan_pk_op_sign_t op);
1615
1616BOTAN_FFI_EXPORT(2, 8) int botan_pk_op_sign_output_length(botan_pk_op_sign_t op, size_t* olen);
1617
1618BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_sign_update(botan_pk_op_sign_t op, const uint8_t in[], size_t in_len);
1619
1620BOTAN_FFI_EXPORT(2, 0)
1621int botan_pk_op_sign_finish(botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t* sig_len);
1622
1623/*
1624* Signature Verification
1625*/
1626typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t;
1627
1628BOTAN_FFI_EXPORT(2, 0)
1629int botan_pk_op_verify_create(botan_pk_op_verify_t* op,
1630 botan_pubkey_t key,
1631 const char* hash_and_padding,
1632 uint32_t flags);
1633
1634/**
1635* @return 0 if success, error if invalid object handle
1636*/
1637BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_verify_destroy(botan_pk_op_verify_t op);
1638
1639BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_len);
1640BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len);
1641
1642/*
1643* Key Agreement
1644*/
1645typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t;
1646
1647BOTAN_FFI_EXPORT(2, 0)
1648int botan_pk_op_key_agreement_create(botan_pk_op_ka_t* op, botan_privkey_t key, const char* kdf, uint32_t flags);
1649
1650/**
1651* @return 0 if success, error if invalid object handle
1652*/
1653BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_key_agreement_destroy(botan_pk_op_ka_t op);
1654
1655BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_key_agreement_export_public(botan_privkey_t key, uint8_t out[], size_t* out_len);
1656
1657BOTAN_FFI_EXPORT(3, 0)
1658int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view);
1659
1660BOTAN_FFI_EXPORT(2, 8) int botan_pk_op_key_agreement_size(botan_pk_op_ka_t op, size_t* out_len);
1661
1662BOTAN_FFI_EXPORT(2, 0)
1663int botan_pk_op_key_agreement(botan_pk_op_ka_t op,
1664 uint8_t out[],
1665 size_t* out_len,
1666 const uint8_t other_key[],
1667 size_t other_key_len,
1668 const uint8_t salt[],
1669 size_t salt_len);
1670
1671/*
1672* Key Encapsulation
1673*/
1674typedef struct botan_pk_op_kem_encrypt_struct* botan_pk_op_kem_encrypt_t;
1675
1676BOTAN_FFI_EXPORT(3, 0)
1677int botan_pk_op_kem_encrypt_create(botan_pk_op_kem_encrypt_t* op, botan_pubkey_t key, const char* kdf);
1678
1679/**
1680* @return 0 if success, error if invalid object handle
1681*/
1682BOTAN_FFI_EXPORT(3, 0) int botan_pk_op_kem_encrypt_destroy(botan_pk_op_kem_encrypt_t op);
1683
1684BOTAN_FFI_EXPORT(3, 0)
1685int botan_pk_op_kem_encrypt_shared_key_length(botan_pk_op_kem_encrypt_t op,
1686 size_t desired_shared_key_length,
1687 size_t* output_shared_key_length);
1688
1689BOTAN_FFI_EXPORT(3, 0)
1690int botan_pk_op_kem_encrypt_encapsulated_key_length(botan_pk_op_kem_encrypt_t op,
1691 size_t* output_encapsulated_key_length);
1692
1693BOTAN_FFI_EXPORT(3, 0)
1694int botan_pk_op_kem_encrypt_create_shared_key(botan_pk_op_kem_encrypt_t op,
1695 botan_rng_t rng,
1696 const uint8_t salt[],
1697 size_t salt_len,
1698 size_t desired_shared_key_len,
1699 uint8_t shared_key[],
1700 size_t* shared_key_len,
1701 uint8_t encapsulated_key[],
1702 size_t* encapsulated_key_len);
1703
1704typedef struct botan_pk_op_kem_decrypt_struct* botan_pk_op_kem_decrypt_t;
1705
1706BOTAN_FFI_EXPORT(3, 0)
1707int botan_pk_op_kem_decrypt_create(botan_pk_op_kem_decrypt_t* op, botan_privkey_t key, const char* kdf);
1708
1709/**
1710* @return 0 if success, error if invalid object handle
1711*/
1712BOTAN_FFI_EXPORT(3, 0) int botan_pk_op_kem_decrypt_destroy(botan_pk_op_kem_decrypt_t op);
1713
1714BOTAN_FFI_EXPORT(3, 0)
1715int botan_pk_op_kem_decrypt_shared_key_length(botan_pk_op_kem_decrypt_t op,
1716 size_t desired_shared_key_length,
1717 size_t* output_shared_key_length);
1718
1719BOTAN_FFI_EXPORT(3, 0)
1720int botan_pk_op_kem_decrypt_shared_key(botan_pk_op_kem_decrypt_t op,
1721 const uint8_t salt[],
1722 size_t salt_len,
1723 const uint8_t encapsulated_key[],
1724 size_t encapsulated_key_len,
1725 size_t desired_shared_key_len,
1726 uint8_t shared_key[],
1727 size_t* shared_key_len);
1728
1729/**
1730* Signature Scheme Utility Functions
1731*/
1732
1733BOTAN_FFI_EXPORT(2, 0) int botan_pkcs_hash_id(const char* hash_name, uint8_t pkcs_id[], size_t* pkcs_id_len);
1734
1735/*
1736* Always returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED
1737*/
1738BOTAN_FFI_DEPRECATED("No longer implemented")
1739BOTAN_FFI_EXPORT(2, 0)
1740int botan_mceies_encrypt(botan_pubkey_t mce_key,
1741 botan_rng_t rng,
1742 const char* aead,
1743 const uint8_t pt[],
1744 size_t pt_len,
1745 const uint8_t ad[],
1746 size_t ad_len,
1747 uint8_t ct[],
1748 size_t* ct_len);
1749
1750/*
1751* Always returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED
1752*/
1753BOTAN_FFI_DEPRECATED("No longer implemented")
1754BOTAN_FFI_EXPORT(2, 0)
1755int botan_mceies_decrypt(botan_privkey_t mce_key,
1756 const char* aead,
1757 const uint8_t ct[],
1758 size_t ct_len,
1759 const uint8_t ad[],
1760 size_t ad_len,
1761 uint8_t pt[],
1762 size_t* pt_len);
1763
1764/*
1765* X.509 certificates
1766**************************/
1767
1768typedef struct botan_x509_cert_struct* botan_x509_cert_t;
1769
1770BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_load(botan_x509_cert_t* cert_obj, const uint8_t cert[], size_t cert_len);
1771BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* filename);
1772
1773/**
1774* @return 0 if success, error if invalid object handle
1775*/
1776BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_destroy(botan_x509_cert_t cert);
1777
1778BOTAN_FFI_EXPORT(2, 8) int botan_x509_cert_dup(botan_x509_cert_t* new_cert, botan_x509_cert_t cert);
1779
1780/* Prefer botan_x509_cert_not_before and botan_x509_cert_not_after */
1781BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* out_len);
1782BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* out_len);
1783
1784BOTAN_FFI_EXPORT(2, 8) int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t* time_since_epoch);
1785BOTAN_FFI_EXPORT(2, 8) int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t* time_since_epoch);
1786
1787BOTAN_FFI_EXPORT(2, 0)
1788int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char* hash, uint8_t out[], size_t* out_len);
1789
1790BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1791BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1792BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1793
1794BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
1795
1796BOTAN_FFI_EXPORT(3, 0)
1797int botan_x509_cert_view_public_key_bits(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view);
1798
1799BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t* key);
1800
1801BOTAN_FFI_EXPORT(2, 0)
1802int botan_x509_cert_get_issuer_dn(
1803 botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len);
1804
1805BOTAN_FFI_EXPORT(2, 0)
1806int botan_x509_cert_get_subject_dn(
1807 botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len);
1808
1809BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_len);
1810
1811BOTAN_FFI_EXPORT(3, 0)
1812int botan_x509_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view);
1813
1814/* Must match values of Key_Constraints in key_constraints.h */
1815enum botan_x509_cert_key_constraints {
1816 NO_CONSTRAINTS = 0,
1817 DIGITAL_SIGNATURE = 32768,
1818 NON_REPUDIATION = 16384,
1819 KEY_ENCIPHERMENT = 8192,
1820 DATA_ENCIPHERMENT = 4096,
1821 KEY_AGREEMENT = 2048,
1822 KEY_CERT_SIGN = 1024,
1823 CRL_SIGN = 512,
1824 ENCIPHER_ONLY = 256,
1825 DECIPHER_ONLY = 128
1827
1828BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage);
1829
1830/**
1831* Check if the certificate matches the specified hostname via alternative name or CN match.
1832* RFC 5280 wildcards also supported.
1833*/
1834BOTAN_FFI_EXPORT(2, 5) int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname);
1835
1836/**
1837* Returns 0 if the validation was successful, 1 if validation failed,
1838* and negative on error. A status code with details is written to
1839* *validation_result
1840*
1841* Intermediates or trusted lists can be null
1842* Trusted path can be null
1843*/
1844BOTAN_FFI_EXPORT(2, 8)
1845int botan_x509_cert_verify(int* validation_result,
1846 botan_x509_cert_t cert,
1847 const botan_x509_cert_t* intermediates,
1848 size_t intermediates_len,
1849 const botan_x509_cert_t* trusted,
1850 size_t trusted_len,
1851 const char* trusted_path,
1852 size_t required_strength,
1853 const char* hostname,
1854 uint64_t reference_time);
1855
1856/**
1857* Returns a pointer to a static character string explaining the status code,
1858* or else NULL if unknown.
1859*/
1860BOTAN_FFI_EXPORT(2, 8) const char* botan_x509_cert_validation_status(int code);
1861
1862/*
1863* X.509 CRL
1864**************************/
1865
1866typedef struct botan_x509_crl_struct* botan_x509_crl_t;
1867
1868BOTAN_FFI_EXPORT(2, 13) int botan_x509_crl_load_file(botan_x509_crl_t* crl_obj, const char* crl_path);
1869BOTAN_FFI_EXPORT(2, 13)
1870int botan_x509_crl_load(botan_x509_crl_t* crl_obj, const uint8_t crl_bits[], size_t crl_bits_len);
1871
1872BOTAN_FFI_EXPORT(2, 13) int botan_x509_crl_destroy(botan_x509_crl_t crl);
1873
1874/**
1875 * Given a CRL and a certificate,
1876 * check if the certificate is revoked on that particular CRL
1877 */
1878BOTAN_FFI_EXPORT(2, 13) int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert);
1879
1880/**
1881 * Different flavor of `botan_x509_cert_verify`, supports revocation lists.
1882 * CRLs are passed as an array, same as intermediates and trusted CAs
1883 */
1884BOTAN_FFI_EXPORT(2, 13)
1885int botan_x509_cert_verify_with_crl(int* validation_result,
1886 botan_x509_cert_t cert,
1887 const botan_x509_cert_t* intermediates,
1888 size_t intermediates_len,
1889 const botan_x509_cert_t* trusted,
1890 size_t trusted_len,
1891 const botan_x509_crl_t* crls,
1892 size_t crls_len,
1893 const char* trusted_path,
1894 size_t required_strength,
1895 const char* hostname,
1896 uint64_t reference_time);
1897
1898/**
1899 * Key wrapping as per RFC 3394
1900 */
1901BOTAN_FFI_DEPRECATED("Use botan_nist_kw_enc")
1902BOTAN_FFI_EXPORT(2, 2)
1903int botan_key_wrap3394(const uint8_t key[],
1904 size_t key_len,
1905 const uint8_t kek[],
1906 size_t kek_len,
1907 uint8_t wrapped_key[],
1908 size_t* wrapped_key_len);
1909
1910BOTAN_FFI_DEPRECATED("Use botan_nist_kw_dec")
1911BOTAN_FFI_EXPORT(2, 2)
1912int botan_key_unwrap3394(const uint8_t wrapped_key[],
1913 size_t wrapped_key_len,
1914 const uint8_t kek[],
1915 size_t kek_len,
1916 uint8_t key[],
1917 size_t* key_len);
1918
1919BOTAN_FFI_EXPORT(3, 0)
1920int botan_nist_kw_enc(const char* cipher_algo,
1921 int padded,
1922 const uint8_t key[],
1923 size_t key_len,
1924 const uint8_t kek[],
1925 size_t kek_len,
1926 uint8_t wrapped_key[],
1927 size_t* wrapped_key_len);
1928
1929BOTAN_FFI_EXPORT(3, 0)
1930int botan_nist_kw_dec(const char* cipher_algo,
1931 int padded,
1932 const uint8_t wrapped_key[],
1933 size_t wrapped_key_len,
1934 const uint8_t kek[],
1935 size_t kek_len,
1936 uint8_t key[],
1937 size_t* key_len);
1938
1939/**
1940* HOTP
1941*/
1942
1943typedef struct botan_hotp_struct* botan_hotp_t;
1944
1945/**
1946* Initialize a HOTP instance
1947*/
1948BOTAN_FFI_EXPORT(2, 8)
1949int botan_hotp_init(botan_hotp_t* hotp, const uint8_t key[], size_t key_len, const char* hash_algo, size_t digits);
1950
1951/**
1952* Destroy a HOTP instance
1953* @return 0 if success, error if invalid object handle
1954*/
1955BOTAN_FFI_EXPORT(2, 8)
1956int botan_hotp_destroy(botan_hotp_t hotp);
1957
1958/**
1959* Generate a HOTP code for the provided counter
1960*/
1961BOTAN_FFI_EXPORT(2, 8)
1962int botan_hotp_generate(botan_hotp_t hotp, uint32_t* hotp_code, uint64_t hotp_counter);
1963
1964/**
1965* Verify a HOTP code
1966*/
1967BOTAN_FFI_EXPORT(2, 8)
1968int botan_hotp_check(
1969 botan_hotp_t hotp, uint64_t* next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range);
1970
1971/**
1972* TOTP
1973*/
1974
1975typedef struct botan_totp_struct* botan_totp_t;
1976
1977/**
1978* Initialize a TOTP instance
1979*/
1980BOTAN_FFI_EXPORT(2, 8)
1981int botan_totp_init(
1982 botan_totp_t* totp, const uint8_t key[], size_t key_len, const char* hash_algo, size_t digits, size_t time_step);
1983
1984/**
1985* Destroy a TOTP instance
1986* @return 0 if success, error if invalid object handle
1987*/
1988BOTAN_FFI_EXPORT(2, 8)
1989int botan_totp_destroy(botan_totp_t totp);
1990
1991/**
1992* Generate a TOTP code for the provided timestamp
1993* @param totp the TOTP object
1994* @param totp_code the OTP code will be written here
1995* @param timestamp the current local timestamp
1996*/
1997BOTAN_FFI_EXPORT(2, 8)
1998int botan_totp_generate(botan_totp_t totp, uint32_t* totp_code, uint64_t timestamp);
1999
2000/**
2001* Verify a TOTP code
2002* @param totp the TOTP object
2003* @param totp_code the presented OTP
2004* @param timestamp the current local timestamp
2005* @param acceptable_clock_drift specifies the acceptable amount
2006* of clock drift (in terms of time steps) between the two hosts.
2007*/
2008BOTAN_FFI_EXPORT(2, 8)
2009int botan_totp_check(botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift);
2010
2011/**
2012* Format Preserving Encryption
2013*/
2014
2015typedef struct botan_fpe_struct* botan_fpe_t;
2016
2017#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE 1
2018
2019BOTAN_FFI_EXPORT(2, 8)
2020int botan_fpe_fe1_init(
2021 botan_fpe_t* fpe, botan_mp_t n, const uint8_t key[], size_t key_len, size_t rounds, uint32_t flags);
2022
2023/**
2024* @return 0 if success, error if invalid object handle
2025*/
2026BOTAN_FFI_EXPORT(2, 8)
2027int botan_fpe_destroy(botan_fpe_t fpe);
2028
2029BOTAN_FFI_EXPORT(2, 8)
2030int botan_fpe_encrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len);
2031
2032BOTAN_FFI_EXPORT(2, 8)
2033int botan_fpe_decrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len);
2034
2035/**
2036* SRP-6 Server Session type
2037*/
2038typedef struct botan_srp6_server_session_struct* botan_srp6_server_session_t;
2039
2040/**
2041* Initialize an SRP-6 server session object
2042* @param srp6 SRP-6 server session object
2043*/
2044BOTAN_FFI_EXPORT(3, 0)
2045int botan_srp6_server_session_init(botan_srp6_server_session_t* srp6);
2046
2047/**
2048* Frees all resources of the SRP-6 server session object
2049* @param srp6 SRP-6 server session object
2050* @return 0 if success, error if invalid object handle
2051*/
2052BOTAN_FFI_EXPORT(3, 0)
2053int botan_srp6_server_session_destroy(botan_srp6_server_session_t srp6);
2054
2055/**
2056* SRP-6 Server side step 1
2057* @param srp6 SRP-6 server session object
2058* @param verifier the verification value saved from client registration
2059* @param verifier_len SRP-6 verifier value length
2060* @param group_id the SRP group id
2061* @param hash_id the SRP hash in use
2062* @param rng_obj a random number generator object
2063* @param B_pub out buffer to store the SRP-6 B value
2064* @param B_pub_len SRP-6 B value length
2065* @return 0 on success, negative on failure
2066*/
2067BOTAN_FFI_EXPORT(3, 0)
2068int botan_srp6_server_session_step1(botan_srp6_server_session_t srp6,
2069 const uint8_t verifier[],
2070 size_t verifier_len,
2071 const char* group_id,
2072 const char* hash_id,
2073 botan_rng_t rng_obj,
2074 uint8_t B_pub[],
2075 size_t* B_pub_len);
2076
2077/**
2078* SRP-6 Server side step 2
2079* @param srp6 SRP-6 server session object
2080* @param A the client's value
2081* @param A_len the client's value length
2082* @param key out buffer to store the symmetric key value
2083* @param key_len symmetric key length
2084* @return 0 on success, negative on failure
2085*/
2086BOTAN_FFI_EXPORT(3, 0)
2087int botan_srp6_server_session_step2(
2088 botan_srp6_server_session_t srp6, const uint8_t A[], size_t A_len, uint8_t key[], size_t* key_len);
2089
2090/**
2091* Generate a new SRP-6 verifier
2092* @param identifier a username or other client identifier
2093* @param password the secret used to authenticate user
2094* @param salt a randomly chosen value, at least 128 bits long
2095* @param salt_len the length of salt
2096* @param group_id specifies the shared SRP group
2097* @param hash_id specifies a secure hash function
2098* @param verifier out buffer to store the SRP-6 verifier value
2099* @param verifier_len SRP-6 verifier value length
2100* @return 0 on success, negative on failure
2101*/
2102BOTAN_FFI_EXPORT(3, 0)
2103int botan_srp6_generate_verifier(const char* identifier,
2104 const char* password,
2105 const uint8_t salt[],
2106 size_t salt_len,
2107 const char* group_id,
2108 const char* hash_id,
2109 uint8_t verifier[],
2110 size_t* verifier_len);
2111
2112/**
2113* SRP6a Client side
2114* @param username the username we are attempting login for
2115* @param password the password we are attempting to use
2116* @param group_id specifies the shared SRP group
2117* @param hash_id specifies a secure hash function
2118* @param salt is the salt value sent by the server
2119* @param salt_len the length of salt
2120* @param B is the server's public value
2121* @param B_len is the server's public value length
2122* @param rng_obj is a random number generator object
2123* @param A out buffer to store the SRP-6 A value
2124* @param A_len SRP-6 A verifier value length
2125* @param K out buffer to store the symmetric value
2126* @param K_len symmetric key length
2127* @return 0 on success, negative on failure
2128*/
2129BOTAN_FFI_EXPORT(3, 0)
2130int botan_srp6_client_agree(const char* username,
2131 const char* password,
2132 const char* group_id,
2133 const char* hash_id,
2134 const uint8_t salt[],
2135 size_t salt_len,
2136 const uint8_t B[],
2137 size_t B_len,
2138 botan_rng_t rng_obj,
2139 uint8_t A[],
2140 size_t* A_len,
2141 uint8_t K[],
2142 size_t* K_len);
2143
2144/**
2145* Return the size, in bytes, of the prime associated with group_id
2146*/
2147BOTAN_FFI_EXPORT(3, 0)
2148int botan_srp6_group_size(const char* group_id, size_t* group_p_bytes);
2149
2150/**
2151 * ZFEC
2152 */
2153
2154/**
2155 * Encode some bytes with certain ZFEC parameters.
2156 *
2157 * @param K the number of shares needed for recovery
2158 * @param N the number of shares generated
2159 * @param input the data to FEC
2160 * @param size the length in bytes of input, which must be a multiple of K
2161 *
2162 * @param outputs An out parameter pointing to a fully allocated array of size
2163 * [N][size / K]. For all n in range, an encoded block will be
2164 * written to the memory starting at outputs[n][0].
2165 *
2166 * @return 0 on success, negative on failure
2167 */
2168BOTAN_FFI_EXPORT(3, 0)
2169int botan_zfec_encode(size_t K, size_t N, const uint8_t* input, size_t size, uint8_t** outputs);
2170
2171/**
2172 * Decode some previously encoded shares using certain ZFEC parameters.
2173 *
2174 * @param K the number of shares needed for recovery
2175 * @param N the total number of shares
2176 *
2177 * @param indexes The index into the encoder's outputs for the corresponding
2178 * element of the inputs array. Must be of length K.
2179 *
2180 * @param inputs K previously encoded shares to decode
2181 * @param shareSize the length in bytes of each input
2182 *
2183 * @param outputs An out parameter pointing to a fully allocated array of size
2184 * [K][shareSize]. For all k in range, a decoded block will
2185 * written to the memory starting at outputs[k][0].
2186 *
2187 * @return 0 on success, negative on failure
2188 */
2189BOTAN_FFI_EXPORT(3, 0)
2190int botan_zfec_decode(
2191 size_t K, size_t N, const size_t* indexes, uint8_t* const* inputs, size_t shareSize, uint8_t** outputs);
2192
2193#ifdef __cplusplus
2194}
2195#endif
2196
2197#endif
std::string name
int botan_mp_lshift(botan_mp_t out, botan_mp_t in, size_t shift)
Definition ffi_mp.cpp:199
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:87
int botan_block_cipher_init(botan_block_cipher_t *bc, const char *cipher_name)
Definition ffi_block.cpp:18
int botan_mp_is_prime(botan_mp_t n, botan_rng_t rng, size_t test_prob)
Definition ffi_mp.cpp:231
int botan_rng_reseed_from_rng(botan_rng_t rng, botan_rng_t source_rng, size_t bits)
Definition ffi_rng.cpp:166
int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:161
uint32_t botan_version_minor(void)
Definition ffi.cpp:286
int botan_mp_set_from_int(botan_mp_t mp, int initial_value)
Definition ffi_mp.cpp:37
int botan_mp_to_bin(botan_mp_t mp, uint8_t vec[])
Definition ffi_mp.cpp:101
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:157
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:127
int botan_base64_encode(const uint8_t *x, size_t len, char *out, size_t *out_len)
Definition ffi.cpp:328
int botan_privkey_create_elgamal(botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
int botan_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng, botan_mp_t lower_bound, botan_mp_t upper_bound)
Definition ffi_mp.cpp:222
int botan_hash_update(botan_hash_t hash, const uint8_t *in, size_t in_len)
Definition ffi_hash.cpp:59
int botan_mp_rshift(botan_mp_t out, botan_mp_t in, size_t shift)
Definition ffi_mp.cpp:203
int botan_nist_kw_enc(const char *cipher_algo, int padded, const uint8_t key[], size_t key_len, const uint8_t kek[], size_t kek_len, uint8_t wrapped_key[], size_t *wrapped_key_len)
int botan_privkey_create_rsa(botan_privkey_t *key, botan_rng_t rng, size_t n_bits)
uint32_t botan_version_datestamp(void)
Definition ffi.cpp:294
uint32_t botan_version_patch(void)
Definition ffi.cpp:290
int botan_privkey_create_ecdsa(botan_privkey_t *key, botan_rng_t rng, const char *params)
int botan_mp_set_from_radix_str(botan_mp_t dest, const char *str, size_t radix)
Definition ffi_mp.cpp:45
int botan_rng_add_entropy(botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
Definition ffi_rng.cpp:162
int botan_cipher_start(botan_cipher_t cipher, const uint8_t *nonce, size_t nonce_len)
int botan_mp_add(botan_mp_t result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:116
int botan_mp_powmod(botan_mp_t out, botan_mp_t base, botan_mp_t exponent, botan_mp_t modulus)
Definition ffi_mp.cpp:194
uint32_t botan_version_major(void)
Definition ffi.cpp:282
int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl)
int botan_mac_init(botan_mac_t *mac, const char *mac_name, uint32_t flags)
Definition ffi_mac.cpp:18
int botan_mp_to_uint32(botan_mp_t mp, uint32_t *val)
Definition ffi_mp.cpp:105
int botan_privkey_create_dh(botan_privkey_t *key, botan_rng_t rng, const char *param)
int botan_hash_name(botan_hash_t hash, char *name, size_t *name_len)
Definition ffi_hash.cpp:82
int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t *tag_size)
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name)
int botan_rng_init_custom(botan_rng_t *rng_out, const char *rng_name, void *context, int(*get_cb)(void *context, uint8_t *out, size_t out_len), int(*add_entropy_cb)(void *context, const uint8_t input[], size_t length), void(*destroy_cb)(void *context))
Definition ffi_rng.cpp:58
#define BOTAN_FFI_EXPORT(maj, min)
Definition ffi.h:78
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_rng_reseed(botan_rng_t rng, size_t bits)
Definition ffi_rng.cpp:158
int botan_mp_init(botan_mp_t *mp)
Definition ffi_mp.cpp:21
int botan_same_mem(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:304
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:54
struct botan_mac_struct * botan_mac_t
Definition ffi.h:428
int botan_base64_decode(const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition ffi.cpp:335
int botan_mac_destroy(botan_mac_t mac)
Definition ffi_mac.cpp:35
int botan_mp_is_odd(botan_mp_t mp)
Definition ffi_mp.cpp:177
int botan_cipher_requires_entire_message(botan_cipher_t cipher)
struct botan_privkey_struct * botan_privkey_t
Definition ffi.h:1085
int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t *out_len)
int botan_cipher_reset(botan_cipher_t cipher)
int botan_cipher_init(botan_cipher_t *cipher, const char *name, uint32_t flags)
int botan_block_cipher_clear(botan_block_cipher_t bc)
Definition ffi_block.cpp:43
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:154
int botan_hash_destroy(botan_hash_t hash)
Definition ffi_hash.cpp:37
int botan_mac_set_nonce(botan_mac_t mac, const uint8_t *nonce, size_t nonce_len)
Definition ffi_mac.cpp:43
int botan_block_cipher_block_size(botan_block_cipher_t bc)
Definition ffi_block.cpp:61
int botan_cipher_destroy(botan_cipher_t cipher)
#define BOTAN_FFI_DEPRECATED(msg)
Definition ffi.h:93
int botan_mp_num_bytes(botan_mp_t n, size_t *bytes)
Definition ffi_mp.cpp:251
int botan_cipher_name(botan_cipher_t cipher, char *name, size_t *name_len)
int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t *ad, size_t ad_len)
int botan_cipher_get_keyspec(botan_cipher_t, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
int botan_privkey_destroy(botan_privkey_t key)
Definition ffi_pkey.cpp:79
int botan_mp_from_bin(botan_mp_t mp, const uint8_t vec[], size_t vec_len)
Definition ffi_mp.cpp:79
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:72
int botan_hash_clear(botan_hash_t hash)
Definition ffi_hash.cpp:55
int botan_mp_add_u32(botan_mp_t result, botan_mp_t x, uint32_t y)
Definition ffi_mp.cpp:134
int botan_mp_to_hex(botan_mp_t mp, char *out)
Definition ffi_mp.cpp:83
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:164
int botan_mp_swap(botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:189
int botan_mp_destroy(botan_mp_t mp)
Definition ffi_mp.cpp:112
uint32_t botan_ffi_api_version(void)
Definition ffi.cpp:219
int botan_mp_mod_mul(botan_mp_t result, botan_mp_t x, botan_mp_t y, botan_mp_t mod)
Definition ffi_mp.cpp:211
int botan_hash_output_length(botan_hash_t hash, size_t *output_length)
Definition ffi_hash.cpp:41
int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits)
Definition ffi_mp.cpp:218
int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t *key, size_t key_len)
int botan_mp_equal(botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:169
int botan_cipher_query_keylen(botan_cipher_t, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
int botan_mp_set_from_str(botan_mp_t dest, const char *str)
Definition ffi_mp.cpp:41
int botan_mp_flip_sign(botan_mp_t mp)
Definition ffi_mp.cpp:75
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:146
int botan_cipher_get_ideal_update_granularity(botan_cipher_t cipher, size_t *ug)
int botan_mp_clear_bit(botan_mp_t n, size_t bit)
Definition ffi_mp.cpp:243
int botan_mp_is_zero(botan_mp_t mp)
Definition ffi_mp.cpp:173
int botan_mp_mod_inverse(botan_mp_t out, botan_mp_t in, botan_mp_t modulus)
Definition ffi_mp.cpp:207
int botan_mp_cmp(int *result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:185
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_gcd(botan_mp_t out, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:227
struct botan_block_cipher_struct * botan_block_cipher_t
Definition ffi.h:822
int botan_system_rng_get(uint8_t *out, size_t out_len)
Definition ffi_rng.cpp:151
const char * botan_version_string(void)
Definition ffi.cpp:278
int botan_hex_encode(const uint8_t *x, size_t len, char *out, uint32_t flags)
Definition ffi.cpp:313
int botan_mp_clear(botan_mp_t mp)
Definition ffi_mp.cpp:33
int botan_cipher_is_authenticated(botan_cipher_t cipher)
int botan_mp_get_bit(botan_mp_t n, size_t bit)
Definition ffi_mp.cpp:235
int botan_privkey_load_sm2(botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
int botan_mac_final(botan_mac_t mac, uint8_t out[])
Definition ffi_mac.cpp:59
int botan_block_cipher_name(botan_block_cipher_t cipher, char *name, size_t *name_len)
Definition ffi_block.cpp:79
int botan_rng_get(botan_rng_t rng, uint8_t *out, size_t out_len)
Definition ffi_rng.cpp:147
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
Definition ffi.h:143
int botan_mp_sub_u32(botan_mp_t result, botan_mp_t x, uint32_t y)
Definition ffi_mp.cpp:143
int botan_scrub_mem(void *mem, size_t bytes)
Definition ffi.cpp:308
int botan_mp_num_bits(botan_mp_t n, size_t *bits)
Definition ffi_mp.cpp:247
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:27
int botan_mac_update(botan_mac_t mac, const uint8_t *buf, size_t len)
Definition ffi_mac.cpp:55
int botan_privkey_create_mceliece(botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
int botan_mp_mul(botan_mp_t result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:152
int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:111
int botan_hash_block_size(botan_hash_t hash, size_t *block_size)
Definition ffi_hash.cpp:48
int botan_hash_copy_state(botan_hash_t *dest, botan_hash_t source)
Definition ffi_hash.cpp:78
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name)
int botan_privkey_create_dsa(botan_privkey_t *key, botan_rng_t rng, size_t pbits, size_t qbits)
int botan_pubkey_load_sm2(botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
struct botan_mp_struct * botan_mp_t
Definition ffi.h:888
void * botan_view_ctx
Definition ffi.h:134
struct botan_rng_struct * botan_rng_t
Definition ffi.h:260
int botan_block_cipher_destroy(botan_block_cipher_t bc)
Definition ffi_block.cpp:39
BOTAN_FFI_ERROR
Definition ffi.h:102
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:124
@ BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition ffi.h:121
@ BOTAN_FFI_ERROR_KEY_NOT_SET
Definition ffi.h:120
@ BOTAN_FFI_ERROR_TLS_ERROR
Definition ffi.h:127
@ BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition ffi.h:112
@ BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition ffi.h:113
@ BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition ffi.h:115
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:104
@ BOTAN_FFI_ERROR_INVALID_OBJECT
Definition ffi.h:125
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:131
@ BOTAN_FFI_ERROR_HTTP_ERROR
Definition ffi.h:128
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:117
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:106
@ BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR
Definition ffi.h:110
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:118
@ BOTAN_FFI_SUCCESS
Definition ffi.h:103
@ BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition ffi.h:114
@ BOTAN_FFI_ERROR_ROUGHTIME_ERROR
Definition ffi.h:129
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition ffi.h:122
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:109
@ BOTAN_FFI_ERROR_BAD_MAC
Definition ffi.h:107
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:119
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:53
int botan_mac_name(botan_mac_t mac, char *name, size_t *name_len)
Definition ffi_mac.cpp:63
int botan_cipher_clear(botan_cipher_t hash)
int botan_mp_is_even(botan_mp_t mp)
Definition ffi_mp.cpp:181
int botan_rng_destroy(botan_rng_t rng)
Definition ffi_rng.cpp:143
int botan_ffi_supports_api(uint32_t api_version)
Definition ffi.cpp:223
const char * botan_error_description(int err)
Definition ffi.cpp:146
int botan_hash_final(botan_hash_t hash, uint8_t out[])
Definition ffi_hash.cpp:71
const char * botan_error_last_exception_message(void)
Definition ffi.cpp:142
int botan_hash_init(botan_hash_t *hash, const char *hash_name, uint32_t flags)
Definition ffi_hash.cpp:18
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:67
struct botan_cipher_struct * botan_cipher_t
Definition ffi.h:524
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)
Encrypt/Decrypt some data and/or finalize the encryption/decryption.
int botan_mac_output_length(botan_mac_t mac, size_t *output_length)
Definition ffi_mac.cpp:47
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:152
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:298
int botan_mp_is_negative(botan_mp_t mp)
Definition ffi_mp.cpp:67
int botan_hex_decode(const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition ffi.cpp:321
int botan_mac_set_key(botan_mac_t mac, const uint8_t *key, size_t key_len)
Definition ffi_mac.cpp:39
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:130
int botan_mp_sub(botan_mp_t result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:125
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:26
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:65
int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t *nl)
int botan_mp_is_positive(botan_mp_t mp)
Definition ffi_mp.cpp:71
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:169
int botan_nist_kw_dec(const char *cipher_algo, int padded, const uint8_t wrapped_key[], size_t wrapped_key_len, const uint8_t kek[], size_t kek_len, uint8_t key[], size_t *key_len)
int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t *ug)
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_mac_clear(botan_mac_t mac)
Definition ffi_mac.cpp:51
int botan_mp_to_str(botan_mp_t mp, uint8_t base, char *out, size_t *out_len)
Definition ffi_mp.cpp:90
int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], size_t len)
Definition ffi_block.cpp:50
int botan_mp_set_bit(botan_mp_t n, size_t bit)
Definition ffi_mp.cpp:239
int botan_bcrypt_is_valid(const char *pass, const char *hash)
Definition ffi_kdf.cpp:188
int botan_mp_set_from_mp(botan_mp_t dest, botan_mp_t source)
Definition ffi_mp.cpp:63
struct botan_hash_struct * botan_hash_t
Definition ffi.h:348