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