Botan 3.13.0
Crypto and TLS for C&
ffi.h
Go to the documentation of this file.
1/*
2* FFI (C89 API)
3* (C) 2015,2017 Jack Lloyd
4* (C) 2021 René Fischer
5* (C) 2024,2025,2026 Amos Treiber, René Meusel, Rohde & Schwarz Cybersecurity
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#ifndef BOTAN_FFI_H_
11#define BOTAN_FFI_H_
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/*
18This header exports some of botan's functionality via a C89 interface. This API
19is used by the Python, OCaml, Rust, Ruby, and Haskell bindings via those languages
20respective ctypes/FFI libraries.
21
22The API is intended to be as easy as possible to call from other
23languages, which often have easy ways to call C, because C. But some C
24code is easier to deal with than others, so to make things easy this
25API follows a few simple rules:
26
27- All interactions are via pointers to opaque structs. No need to worry about
28 structure padding issues and the like.
29
30- All functions return an int error code (except the version calls, which are
31 assumed to always have something to say).
32
33- Use simple types: size_t for lengths, const char* NULL terminated strings,
34 uint8_t for binary.
35
36- No ownership of memory transfers across the API boundary. The API will consume
37 data from const pointers with specified lengths. Outputs are either placed into
38 buffers provided by (and allocated by) the caller, or are returned via a
39 callback (what the FFI layer calls "view" functions).
40
41 When writing to an application-provided buffer, the function takes a pointer
42 to the output array and a read/write pointer to the length. The length field
43 is always set to the actual amount of data that would have been written. If
44 the input buffer's size was insufficient an error is returned.
45
46 In many situations the length of the output can be known in advance without
47 difficulty, in which case there will be a function which allows querying the
48 expected output length. For example `botan_hash_output_length` allows knowing
49 in advance the expected size for `botan_hash_final`. Some of these are exact,
50 while others such as `botan_pk_op_decrypt_output_length` can only provide an
51 upper bound for various technical reasons.
52
53 In some cases knowing the exact size is difficult or impossible. In these
54 situations view functions are used; see the handbook for further details.
55*/
56
57#include <stddef.h>
58#include <stdint.h>
59
60/* NOLINTBEGIN(*-macro-usage,*-misplaced-const) */
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 20260811
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) && !defined(BOTAN_AMALGAMATION_H_) && !defined(BOTAN_IS_BEING_BUILT)
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*/
148
149/**
150* The application provided context for a view function
151*/
152typedef void* botan_view_ctx;
153
154/**
155* Viewer function for binary data
156*
157* @param view_ctx some application context
158* @param data the binary data
159* @param len the length of data in bytes
160*/
161typedef int (*botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t* data, size_t len);
162
163/**
164* Viewer function for string data
165*
166* @param view_ctx some application context
167* @param str the null terminated string
168* @param len the length of string *including* the null terminator
169*/
170typedef int (*botan_view_str_fn)(botan_view_ctx view_ctx, const char* str, size_t len);
171
172/**
173* Convert an error code into a string. Returns "Unknown error"
174* if the error code is not a known one.
175*/
176BOTAN_FFI_EXPORT(2, 8) const char* botan_error_description(int err);
177
178/**
179* Return the message of the last exception caught in this thread.
180*
181* This pointer can/will be reallocated or overwritten the next time
182* this thread calls any other Botan FFI function and must be copied
183* to persistent storage first.
184*/
186
187/**
188* Return the version of the currently supported FFI API. This is
189* expressed in the form YYYYMMDD of the release date of this version
190* of the API.
191*/
192BOTAN_FFI_EXPORT(2, 0) uint32_t botan_ffi_api_version(void);
193
194/**
195* Return 0 (ok) if the version given is one this library supports.
196* botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.
197*/
198BOTAN_FFI_EXPORT(2, 0) int botan_ffi_supports_api(uint32_t api_version);
199
200/**
201* Return a free-form version string, e.g., 2.0.0
202*/
203BOTAN_FFI_EXPORT(2, 0) const char* botan_version_string(void);
204
205/**
206* Return the major version of the library
207*/
208BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_major(void);
209
210/**
211* Return the minor version of the library
212*/
213BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_minor(void);
214
215/**
216* Return the patch version of the library
217*/
218BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_patch(void);
219
220/**
221* Return the date this version was released as an integer.
222*
223* Returns 0 if the library was not built from an official release
224*/
225BOTAN_FFI_EXPORT(2, 0) uint32_t botan_version_datestamp(void);
226
227/**
228* Returns 0 if x[0..len] == y[0..len], or otherwise -1
229*/
230BOTAN_FFI_EXPORT(2, 3) int botan_constant_time_compare(const uint8_t* x, const uint8_t* y, size_t len);
231
232/**
233* Deprecated equivalent to botan_constant_time_compare
234*/
235BOTAN_FFI_DEPRECATED("Use botan_constant_time_compare")
236BOTAN_FFI_EXPORT(2, 0) int botan_same_mem(const uint8_t* x, const uint8_t* y, size_t len);
237
238/**
239* Clear out memory using a system specific approach to bypass elision by the
240* compiler (currently using RtlSecureZeroMemory or tricks with volatile pointers).
241*/
242BOTAN_FFI_EXPORT(2, 2) int botan_scrub_mem(void* mem, size_t bytes);
243
244/**
245* Flag that can be provided to botan_hex_encode to request lower case hex
246*/
247#define BOTAN_FFI_HEX_LOWER_CASE 1
248
249/**
250* Perform hex encoding
251* @param x is some binary data
252* @param len length of x in bytes
253* @param out an array of at least x*2 bytes
254* @param flags flags out be upper or lower case?
255* @return 0 on success, a negative value on failure
256*/
257BOTAN_FFI_EXPORT(2, 0) int botan_hex_encode(const uint8_t* x, size_t len, char* out, uint32_t flags);
258
259/**
260* Perform hex decoding
261* @param hex_str a string of hex chars (whitespace is ignored)
262* @param in_len the length of hex_str
263* @param out the output buffer should be at least strlen(hex_str)/2 bytes
264* @param out_len the size of the output buffer on input, set to the number of bytes written
265* @return 0 on success, a negative value on failure
266*/
267BOTAN_FFI_EXPORT(2, 3) int botan_hex_decode(const char* hex_str, size_t in_len, uint8_t* out, size_t* out_len);
268
269/**
270* Perform base64 encoding
271*
272* @param x the input data
273* @param len the length of x
274* @param out the output buffer
275* @param out_len the size of the output buffer on input, set to the number of bytes written
276* @return 0 on success, a negative value on failure
277
278*/
279BOTAN_FFI_EXPORT(2, 3) int botan_base64_encode(const uint8_t* x, size_t len, char* out, size_t* out_len);
280
281/**
282* Perform base64 decoding
283*/
284BOTAN_FFI_EXPORT(2, 3) int botan_base64_decode(const char* base64_str, size_t in_len, uint8_t* out, size_t* out_len);
285
286/**
287* RNG type
288*/
289typedef struct botan_rng_struct* botan_rng_t;
290
291/**
292* Initialize a random number generator object
293* @param rng rng object
294* @param rng_type type of the rng, possible values:
295* "system": system RNG
296* "esdm-full": ESDM RNG (fully seeded)
297* "esdm-pr": ESDM RNG (w. prediction resistance)
298* "user": userspace RNG
299* "user-threadsafe": userspace RNG, with internal locking
300* "rdrand": directly read RDRAND
301* Set rng_type to null to let the library choose some default.
302*/
303BOTAN_FFI_EXPORT(2, 0) int botan_rng_init(botan_rng_t* rng, const char* rng_type);
304
305/**
306* Initialize a custom random number generator from a set of callback functions
307* @param rng_out rng object to create
308* @param rng_name name of the rng
309* @param context An application-specific context passed to the callback functions
310* @param get_cb Callback for getting random bytes from the rng, return 0 for success
311* @param add_entropy_cb Callback for adding entropy to the rng, return 0 for success, may be NULL
312* @param destroy_cb Callback called when rng is destroyed, may be NULL
313*/
316 const char* rng_name,
317 void* context,
318 int (*get_cb)(void* context, uint8_t* out, size_t out_len),
319 int (*add_entropy_cb)(void* context, const uint8_t input[], size_t length),
320 void (*destroy_cb)(void* context));
321
322/**
323* Get random bytes from a random number generator
324*
325* @param rng rng object
326* @param out output buffer of size out_len
327* @param out_len number of requested bytes
328* @return 0 on success, negative on failure
329*/
330BOTAN_FFI_EXPORT(2, 0) int botan_rng_get(botan_rng_t rng, uint8_t* out, size_t out_len);
331
332/**
333* Get random bytes from system random number generator
334*
335* @param out output buffer of size out_len
336* @param out_len number of requested bytes
337* @return 0 on success, negative on failure
338*/
339BOTAN_FFI_EXPORT(3, 0) int botan_system_rng_get(uint8_t* out, size_t out_len);
340
341/**
342* Reseed a random number generator
343* Uses the System_RNG as a seed generator.
344*
345* @param rng rng object
346* @param bits number of bits to reseed with
347* @return 0 on success, a negative value on failure
348*/
349BOTAN_FFI_EXPORT(2, 0) int botan_rng_reseed(botan_rng_t rng, size_t bits);
350
351/**
352* Reseed a random number generator
353*
354* @param rng rng object
355* @param source_rng the rng that will be read from
356* @param bits number of bits to reseed with
357* @return 0 on success, a negative value on failure
358*/
359BOTAN_FFI_EXPORT(2, 8) int botan_rng_reseed_from_rng(botan_rng_t rng, botan_rng_t source_rng, size_t bits);
360
361/**
362* Add some seed material to a random number generator
363*
364* @param rng rng object
365* @param entropy the data to add
366* @param entropy_len length of entropy buffer
367* @return 0 on success, a negative value on failure
368*/
369BOTAN_FFI_EXPORT(2, 8) int botan_rng_add_entropy(botan_rng_t rng, const uint8_t* entropy, size_t entropy_len);
370
371/**
372* Create and seed a DRBG
373*
374* @param rng_out the new DRBG object
375* @param drbg_name the name of the DRBG (e.g. "HMAC_DRBG(SHA-256)")
376* @param seed the seed material (entropy || nonce || personalization_string)
377* @param seed_len length of seed in bytes
378* @return 0 on success, negative on failure
379*/
380BOTAN_FFI_EXPORT(3, 12)
381int botan_rng_init_drbg(botan_rng_t* rng_out, const char* drbg_name, const uint8_t* seed, size_t seed_len);
382
383/**
384* Generate random bytes from an RNG with additional input.
385*
386* For a DRBG, the additional input is mixed in before generating.
387* Many other RNG types (eg RDRAND or system RNG) will ignore the input.
388*
389* @param rng the RNG object
390* @param out output buffer
391* @param out_len number of bytes to generate
392* @param addl_input additional input to mix in (may be NULL if addl_len is 0)
393* @param addl_len length of additional input
394* @return 0 on success, negative on failure
395*/
396BOTAN_FFI_EXPORT(3, 12)
398 botan_rng_t rng, uint8_t* out, size_t out_len, const uint8_t* addl_input, size_t addl_len);
399
400/**
401* Frees all resources of the random number generator object
402* @param rng rng object
403* @return 0 if success, error if invalid object handle
404*/
406
407/**
408* Opaque type of an eXtendable Output Function (XOF)
409*/
410typedef struct botan_xof_struct* botan_xof_t;
411
412/**
413* Initialize an eXtendable Output Function
414* @param xof XOF object
415* @param xof_name name of the XOF, e.g., "SHAKE-128"
416* @param flags should be 0 in current API revision, all other uses are reserved
417* and return BOTAN_FFI_ERROR_BAD_FLAG
418*/
419BOTAN_FFI_EXPORT(3, 11) int botan_xof_init(botan_xof_t* xof, const char* xof_name, uint32_t flags);
420
421/**
422* Copy the state of an eXtendable Output Function
423* @param dest destination XOF object
424* @param source source XOF object
425* @return 0 on success, a negative value on failure
426*/
428
429/**
430* Writes the block size of the eXtendable Output Function to *block_size
431* @param xof XOF object
432* @param block_size variable to hold the XOF's block size
433* @return 0 on success, a negative value on failure
434*/
435BOTAN_FFI_EXPORT(3, 11) int botan_xof_block_size(botan_xof_t xof, size_t* block_size);
436
437/**
438* Get the name of this eXtendable Output Function
439* @param xof the object to read
440* @param name output buffer
441* @param name_len on input, the length of buffer, on success the number of bytes written
442*/
443BOTAN_FFI_EXPORT(3, 11) int botan_xof_name(botan_xof_t xof, char* name, size_t* name_len);
444
445/**
446* Get the input/output state of this eXtendable Output Function
447* Typically, XOFs don't accept input as soon as the first output bytes were requested.
448* @param xof the object to read
449* @returns 1 iff the XOF is still accepting input bytes
450*/
452
453/**
454* Reinitializes the state of the eXtendable Output Function.
455* @param xof XOF object
456* @return 0 on success, a negative value on failure
457*/
459
460/**
461* Send more input to the eXtendable Output Function
462* @param xof XOF object
463* @param in input buffer
464* @param in_len number of bytes to read from the input buffer
465* @return 0 on success, a negative value on failure
466*/
467BOTAN_FFI_EXPORT(3, 11) int botan_xof_update(botan_xof_t xof, const uint8_t* in, size_t in_len);
468
469/**
470* Generate output bytes from the eXtendable Output Function
471* @param xof XOF object
472* @param out output buffer
473* @param out_len number of bytes to write into the output buffer
474* @return 0 on success, a negative value on failure
475*/
476BOTAN_FFI_EXPORT(3, 11) int botan_xof_output(botan_xof_t xof, uint8_t* out, size_t out_len);
477
478/**
479* Frees all resources of the eXtendable Output Function object
480* @param xof xof object
481* @return 0 if success, error if invalid object handle
482*/
484
485/**
486* Opaque type of a hash function
487*/
488typedef struct botan_hash_struct* botan_hash_t;
489
490/**
491* Initialize a hash function object
492* @param hash hash object
493* @param hash_name name of the hash function, e.g., "SHA-384"
494* @param flags should be 0 in current API revision, all other uses are reserved
495* and return BOTAN_FFI_ERROR_BAD_FLAG
496*/
497BOTAN_FFI_EXPORT(2, 0) int botan_hash_init(botan_hash_t* hash, const char* hash_name, uint32_t flags);
498
499/**
500* Copy the state of a hash function object
501* @param dest destination hash object
502* @param source source hash object
503* @return 0 on success, a negative value on failure
504*/
506
507/**
508* Writes the output length of the hash function to *output_length
509* @param hash hash object
510* @param output_length output buffer to hold the hash function output length
511* @return 0 on success, a negative value on failure
512*/
513BOTAN_FFI_EXPORT(2, 0) int botan_hash_output_length(botan_hash_t hash, size_t* output_length);
514
515/**
516* Writes the block size of the hash function to *block_size
517* @param hash hash object
518* @param block_size output buffer to hold the hash function output length
519* @return 0 on success, a negative value on failure
520*/
521BOTAN_FFI_EXPORT(2, 2) int botan_hash_block_size(botan_hash_t hash, size_t* block_size);
522
523/**
524* Writes the estimated security level of the hash function, in bits, with
525* respect to collision resistance, to *security_level. Returns zero for
526* checksums and any hash where finding collisions is trivial.
527* @param hash hash object
528* @param security_level output variable to hold the security level
529* @return 0 on success, a negative value on failure
530*/
531BOTAN_FFI_EXPORT(3, 13) int botan_hash_security_level(botan_hash_t hash, size_t* security_level);
532
533/**
534* Send more input to the hash function
535* @param hash hash object
536* @param in input buffer
537* @param in_len number of bytes to read from the input buffer
538* @return 0 on success, a negative value on failure
539*/
540BOTAN_FFI_EXPORT(2, 0) int botan_hash_update(botan_hash_t hash, const uint8_t* in, size_t in_len);
541
542/**
543* Finalizes the hash computation and writes the output to
544* out[0:botan_hash_output_length()] then reinitializes for computing
545* another digest as if botan_hash_clear had been called.
546* @param hash hash object
547* @param out output buffer
548* @return 0 on success, a negative value on failure
549*/
550BOTAN_FFI_EXPORT(2, 0) int botan_hash_final(botan_hash_t hash, uint8_t out[]);
551
552/**
553* Reinitializes the state of the hash computation. A hash can
554* be computed (with update/final) immediately.
555* @param hash hash object
556* @return 0 on success, a negative value on failure
557*/
559
560/**
561* Frees all resources of the hash object
562* @param hash hash object
563* @return 0 if success, error if invalid object handle
564*/
566
567/**
568* Get the name of this hash function
569* @param hash the object to read
570* @param name output buffer
571* @param name_len on input, the length of buffer, on success the number of bytes written
572*/
573BOTAN_FFI_EXPORT(2, 8) int botan_hash_name(botan_hash_t hash, char* name, size_t* name_len);
574
575/**
576* Opaque type of a message authentication code
577*/
578typedef struct botan_mac_struct* botan_mac_t;
579
580/**
581* Initialize a message authentication code object
582* @param mac mac object
583* @param mac_name name of the hash function, e.g., "HMAC(SHA-384)"
584* @param flags should be 0 in current API revision, all other uses are reserved
585* and return a negative value (error code)
586* @return 0 on success, a negative value on failure
587*/
588BOTAN_FFI_EXPORT(2, 0) int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags);
589
590/**
591* Writes the output length of the message authentication code to *output_length
592* @param mac mac object
593* @param output_length output buffer to hold the MAC output length
594* @return 0 on success, a negative value on failure
595*/
596BOTAN_FFI_EXPORT(2, 0) int botan_mac_output_length(botan_mac_t mac, size_t* output_length);
597
598/**
599* Sets the key on the MAC
600* @param mac mac object
601* @param key buffer holding the key
602* @param key_len size of the key buffer in bytes
603* @return 0 on success, a negative value on failure
604*/
605BOTAN_FFI_EXPORT(2, 0) int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len);
606
607/**
608* Sets the nonce on the MAC
609* @param mac mac object
610* @param nonce buffer holding the key
611* @param nonce_len size of the key buffer in bytes
612* @return 0 on success, a negative value on failure
613*/
614BOTAN_FFI_EXPORT(3, 0) int botan_mac_set_nonce(botan_mac_t mac, const uint8_t* nonce, size_t nonce_len);
615
616/**
617* Send more input to the message authentication code
618* @param mac mac object
619* @param buf input buffer
620* @param len number of bytes to read from the input buffer
621* @return 0 on success, a negative value on failure
622*/
623BOTAN_FFI_EXPORT(2, 0) int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len);
624
625/**
626* Finalizes the MAC computation and writes the output to
627* out[0:botan_mac_output_length()] then reinitializes for computing
628* another MAC as if botan_mac_clear had been called.
629* @param mac mac object
630* @param out output buffer
631* @return 0 on success, a negative value on failure
632*/
633BOTAN_FFI_EXPORT(2, 0) int botan_mac_final(botan_mac_t mac, uint8_t out[]);
634
635/**
636* Reinitializes the state of the MAC computation. A MAC can
637* be computed (with update/final) immediately.
638* @param mac mac object
639* @return 0 on success, a negative value on failure
640*/
642
643/**
644* Get the name of this MAC
645* @param mac the object to read
646* @param name output buffer
647* @param name_len on input, the length of buffer, on success the number of bytes written
648*/
649BOTAN_FFI_EXPORT(2, 8) int botan_mac_name(botan_mac_t mac, char* name, size_t* name_len);
650
651/**
652* Get the key length limits of this auth code
653* @param mac the object to read
654* @param out_minimum_keylength if non-NULL, will be set to minimum keylength of MAC
655* @param out_maximum_keylength if non-NULL, will be set to maximum keylength of MAC
656* @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys
657*/
660 size_t* out_minimum_keylength,
661 size_t* out_maximum_keylength,
662 size_t* out_keylength_modulo);
663
664/**
665* Frees all resources of the MAC object
666* @param mac mac object
667* @return 0 if success, error if invalid object handle
668*/
670
671/**
672* Opaque type of a cipher mode
673*/
674typedef struct botan_cipher_struct* botan_cipher_t;
675
676#define BOTAN_CIPHER_INIT_FLAG_MASK_DIRECTION 1
677#define BOTAN_CIPHER_INIT_FLAG_ENCRYPT 0
678#define BOTAN_CIPHER_INIT_FLAG_DECRYPT 1
679
680/**
681* Initialize a cipher object
682*/
683BOTAN_FFI_EXPORT(2, 0) int botan_cipher_init(botan_cipher_t* cipher, const char* name, uint32_t flags);
684
685/**
686* Return the name of the cipher object
687*/
688BOTAN_FFI_EXPORT(2, 8) int botan_cipher_name(botan_cipher_t cipher, char* name, size_t* name_len);
689
690/**
691* Return the output length of this cipher, for a particular input length.
692*/
693BOTAN_FFI_EXPORT(2, 8) int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t* out_len);
694
695/**
696* Return if the specified nonce length is valid for this cipher
697*/
699
700/**
701* Get the tag length of the cipher (0 for non-AEAD modes)
702*/
703BOTAN_FFI_EXPORT(2, 0) int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t* tag_size);
704
705/**
706* Returns 1 iff the cipher provides authentication as well as confidentiality.
707*/
709
710/**
711 * Returns 1 iff the cipher requires the entire message before any
712 * encryption or decryption can be performed. No output data will be produced
713 * in botan_cipher_update() until the final flag is set.
714 */
716
717/**
718* Get the default nonce length of this cipher
719*/
721
722/**
723* Return the update granularity of the cipher; botan_cipher_update must be
724* called with blocks of this size, except for the final.
725*/
727
728/**
729* Return the ideal update granularity of the cipher. This is some multiple of the
730* update granularity, reflecting possibilities for optimization.
731*/
733
734/**
735* Get information about the key lengths. Prefer botan_cipher_get_keyspec
736*/
738int botan_cipher_query_keylen(botan_cipher_t cipher, size_t* out_minimum_keylength, size_t* out_maximum_keylength);
739
740/**
741* Get information about the supported key lengths.
742*/
744int botan_cipher_get_keyspec(botan_cipher_t cipher, size_t* min_keylen, size_t* max_keylen, size_t* mod_keylen);
745
746/**
747* Set the key for this cipher object
748*/
749BOTAN_FFI_EXPORT(2, 0) int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t* key, size_t key_len);
750
751/**
752* Reset the message specific state for this cipher.
753* Without resetting the keys, this resets the nonce, and any state
754* associated with any message bits that have been processed so far.
755*
756* It is conceptually equivalent to calling botan_cipher_clear followed
757* by botan_cipher_set_key with the original key.
758*/
760
761/**
762* Set the associated data. Will fail if cipher is not an AEAD
763*/
764BOTAN_FFI_EXPORT(2, 0) int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t* ad, size_t ad_len);
765
766/**
767* Begin processing a new message using the provided nonce
768*/
769BOTAN_FFI_EXPORT(2, 0) int botan_cipher_start(botan_cipher_t cipher, const uint8_t* nonce, size_t nonce_len);
770
771#define BOTAN_CIPHER_UPDATE_FLAG_FINAL (1U << 0)
772
773/**
774* @brief Encrypt/Decrypt some data and/or finalize the encryption/decryption
775*
776* This encrypts as many bytes from @p input_bytes into @p output_bytes as
777* possible. Unless ``BOTAN_CIPHER_UPDATE_FLAG_FINAL`` is set, this function will
778* consume bytes in multiples of botan_cipher_get_update_granularity().
779* @p input_consumed and @p output_written will be set accordingly and it is the
780* caller's responsibility to adapt their buffers accordingly before calling this
781* function again. Note that, unless ``BOTAN_CIPHER_UPDATE_FLAG_FINAL`` is set,
782* the cipher will at most generate @p input_size output bytes.
783*
784* Eventually, the caller must set the ``BOTAN_CIPHER_UPDATE_FLAG_FINAL`` flag to
785* indicate that no more input will be provided. This will cause the cipher to
786* consume all given input bytes and produce the final output; or return a
787* ``BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE`` error if the given output buffer
788* was too small. In the latter case, @p output_written will be set to the
789* required buffer size. Calling again with ``BOTAN_CIPHER_UPDATE_FLAG_FINAL``, a
790* big enough buffer and no further input will then produce the final output.
791*
792* Note that some ciphers require the entire message to be provided before any
793* output is produced. @sa botan_cipher_requires_entire_message().
794*/
797 uint32_t flags,
798 uint8_t output[],
799 size_t output_size,
800 size_t* output_written,
801 const uint8_t input_bytes[],
802 size_t input_size,
803 size_t* input_consumed);
804
805/**
806* Reset the key, nonce, AD and all other state on this cipher object
807*/
809
810/**
811* Destroy the cipher object
812* @return 0 if success, error if invalid object handle
813*/
815
816/**
817* Derive a key from a passphrase for a number of iterations
818* @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
819* @param out buffer to store the derived key, must be of out_len bytes
820* @param out_len the desired length of the key to produce
821* @param passphrase the password to derive the key from
822* @param salt a randomly chosen salt
823* @param salt_len length of salt in bytes
824* @param iterations the number of iterations to use (use 10K or more)
825* @return 0 on success, a negative value on failure
826*
827* Deprecated: use
828* botan_pwdhash(pbkdf_algo, iterations, 0, 0, out, out_len,
829* passphrase, 0, salt, salt_len);
830*/
831BOTAN_FFI_DEPRECATED("Use botan_pwdhash")
833int botan_pbkdf(const char* pbkdf_algo,
834 uint8_t out[],
835 size_t out_len,
836 const char* passphrase,
837 const uint8_t salt[],
838 size_t salt_len,
839 size_t iterations);
840
841/**
842* Derive a key from a passphrase, running until msec time has elapsed.
843* @param pbkdf_algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)"
844* @param out buffer to store the derived key, must be of out_len bytes
845* @param out_len the desired length of the key to produce
846* @param passphrase the password to derive the key from
847* @param salt a randomly chosen salt
848* @param salt_len length of salt in bytes
849* @param milliseconds_to_run if iterations is zero, then instead the PBKDF is
850* run until milliseconds_to_run milliseconds has passed
851* @param out_iterations_used set to the number iterations executed
852* @return 0 on success, a negative value on failure
853*
854* Deprecated: use
855*
856* botan_pwdhash_timed(pbkdf_algo,
857* static_cast<uint32_t>(ms_to_run),
858* iterations_used,
859* nullptr,
860* nullptr,
861* out, out_len,
862* password, 0,
863* salt, salt_len);
864*/
866int botan_pbkdf_timed(const char* pbkdf_algo,
867 uint8_t out[],
868 size_t out_len,
869 const char* passphrase,
870 const uint8_t salt[],
871 size_t salt_len,
872 size_t milliseconds_to_run,
873 size_t* out_iterations_used);
874
875/**
876* Derive a key from a passphrase
877* @param algo PBKDF algorithm, e.g., "PBKDF2(SHA-256)" or "Scrypt"
878* @param param1 the first PBKDF algorithm parameter
879* @param param2 the second PBKDF algorithm parameter (may be zero if unneeded)
880* @param param3 the third PBKDF algorithm parameter (may be zero if unneeded)
881* @param out buffer to store the derived key, must be of out_len bytes
882* @param out_len the desired length of the key to produce
883* @param passphrase the password to derive the key from
884* @param passphrase_len if > 0, specifies length of password. If len == 0, then
885* strlen will be called on passphrase to compute the length.
886* @param salt a randomly chosen salt
887* @param salt_len length of salt in bytes
888* @return 0 on success, a negative value on failure
889*/
891int botan_pwdhash(const char* algo,
892 size_t param1,
893 size_t param2,
894 size_t param3,
895 uint8_t out[],
896 size_t out_len,
897 const char* passphrase,
898 size_t passphrase_len,
899 const uint8_t salt[],
900 size_t salt_len);
901
902/**
903* Derive a key from a passphrase, choosing parameters to hit a target runtime
904* @param algo PBKDF algorithm, e.g., "Scrypt" or "PBKDF2(SHA-256)"
905* @param msec the desired runtime in milliseconds
906* @param param1 will be set to the first password hash parameter
907* @param param2 will be set to the second password hash parameter
908* @param param3 will be set to the third password hash parameter
909* @param out buffer to store the derived key, must be of out_len bytes
910* @param out_len the desired length of the key to produce
911* @param passphrase the password to derive the key from
912* @param passphrase_len if > 0, specifies length of password. If len == 0, then
913* strlen will be called on passphrase to compute the length.
914* @param salt a randomly chosen salt
915* @param salt_len length of salt in bytes
916* @return 0 on success, a negative value on failure
917*/
919int botan_pwdhash_timed(const char* algo,
920 uint32_t msec,
921 size_t* param1,
922 size_t* param2,
923 size_t* param3,
924 uint8_t out[],
925 size_t out_len,
926 const char* passphrase,
927 size_t passphrase_len,
928 const uint8_t salt[],
929 size_t salt_len);
930
931/**
932* Derive a key using scrypt
933* Deprecated; use
934* botan_pwdhash("Scrypt", N, r, p, out, out_len, password, 0, salt, salt_len);
935*/
936BOTAN_FFI_DEPRECATED("Use botan_pwdhash")
938int botan_scrypt(uint8_t out[],
939 size_t out_len,
940 const char* passphrase,
941 const uint8_t salt[],
942 size_t salt_len,
943 size_t N,
944 size_t r,
945 size_t p);
946
947/**
948* Derive a key
949* @param kdf_algo KDF algorithm, e.g., "SP800-56C"
950* @param out buffer holding the derived key, must be of length out_len
951* @param out_len the desired output length in bytes
952* @param secret the secret input
953* @param secret_len size of secret in bytes
954* @param salt a diversifier
955* @param salt_len size of salt in bytes
956* @param label purpose for the derived keying material
957* @param label_len size of label in bytes
958* @return 0 on success, a negative value on failure
959*/
961int botan_kdf(const char* kdf_algo,
962 uint8_t out[],
963 size_t out_len,
964 const uint8_t secret[],
965 size_t secret_len,
966 const uint8_t salt[],
967 size_t salt_len,
968 const uint8_t label[],
969 size_t label_len);
970
971/**
972* Opaque type of a raw block cipher (PRP)
973*/
974typedef struct botan_block_cipher_struct* botan_block_cipher_t;
975
976/**
977* Initialize a block cipher object
978*/
979BOTAN_FFI_EXPORT(2, 1) int botan_block_cipher_init(botan_block_cipher_t* bc, const char* cipher_name);
980
981/**
982* Destroy a block cipher object
983* @return 0 if success, error if invalid object handle
984*/
986
987/**
988* Reinitializes the block cipher
989* @return 0 on success, a negative value on failure
990*/
992
993/**
994* Set the key for a block cipher instance
995*/
996BOTAN_FFI_EXPORT(2, 1) int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], size_t len);
997
998/**
999* Return the positive block size of this block cipher, or negative to
1000* indicate an error
1001*/
1003
1004/**
1005* Encrypt one or more blocks with the cipher
1006*/
1007BOTAN_FFI_EXPORT(2, 1)
1008int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks);
1009
1010/**
1011* Decrypt one or more blocks with the cipher
1012*/
1013BOTAN_FFI_EXPORT(2, 1)
1014int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks);
1015
1016/**
1017* Get the name of this block cipher
1018* @param cipher the object to read
1019* @param name output buffer
1020* @param name_len on input, the length of buffer, on success the number of bytes written
1021*/
1022BOTAN_FFI_EXPORT(2, 8) int botan_block_cipher_name(botan_block_cipher_t cipher, char* name, size_t* name_len);
1023
1024/**
1025* Get the key length limits of this block cipher
1026* @param cipher the object to read
1027* @param out_minimum_keylength if non-NULL, will be set to minimum keylength of cipher
1028* @param out_maximum_keylength if non-NULL, will be set to maximum keylength of cipher
1029* @param out_keylength_modulo if non-NULL will be set to byte multiple of valid keys
1030*/
1031BOTAN_FFI_EXPORT(2, 8)
1033 size_t* out_minimum_keylength,
1034 size_t* out_maximum_keylength,
1035 size_t* out_keylength_modulo);
1036
1037/**
1038* Opaque type of a multiple precision integer (MPI)
1039*/
1040typedef struct botan_mp_struct* botan_mp_t;
1041
1042/**
1043* Initialize an MPI
1044*/
1046
1047/**
1048* Destroy (deallocate) an MPI
1049* @return 0 if success, error if invalid object handle
1050*/
1052
1053/**
1054* Convert the MPI to a hex string. Writes up to botan_mp_num_bytes(mp)*2 + 5 bytes
1055*
1056* Prefer botan_mp_view_hex
1057*/
1058BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_hex(botan_mp_t mp, char* out);
1059
1060/**
1061* View the hex string encoding of the MPI.
1062*/
1064
1065/**
1066* Convert the MPI to a string. Currently radix == 10 and radix == 16 are supported.
1067*/
1068BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_str(botan_mp_t mp, uint8_t radix, char* out, size_t* out_len);
1069
1070/**
1071* View the MPI as a radix-N integer. Currently only radix 10 and radix 16 are supported
1072*/
1073BOTAN_FFI_EXPORT(3, 10) int botan_mp_view_str(botan_mp_t mp, uint8_t radix, botan_view_ctx ctx, botan_view_str_fn view);
1074
1075/**
1076* Set the MPI to zero
1077*/
1079
1080/**
1081* Set the MPI value from an int
1082*/
1083BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_from_int(botan_mp_t mp, int initial_value);
1084
1085/**
1086* Set the MPI value from another MP object
1087*/
1089
1090/**
1091* Set the MPI value from a string
1092*/
1093BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_from_str(botan_mp_t dest, const char* str);
1094
1095/**
1096* Set the MPI value from a string with arbitrary radix.
1097* For arbitrary being 10 or 16.
1098*/
1099BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_from_radix_str(botan_mp_t dest, const char* str, size_t radix);
1100
1101/**
1102* Return the number of significant bits in the MPI
1103*/
1104BOTAN_FFI_EXPORT(2, 1) int botan_mp_num_bits(botan_mp_t n, size_t* bits);
1105
1106/**
1107* Return the number of significant bytes in the MPI
1108*/
1109BOTAN_FFI_EXPORT(2, 1) int botan_mp_num_bytes(botan_mp_t n, size_t* bytes);
1110
1111/**
1112* Convert the MPI to a big-endian binary string. Writes botan_mp_num_bytes to vec
1113*
1114* Note that the sign of the integer is ignored here; only the absolute value is copied
1115*
1116* @param mp the integer to encode
1117* @param vec output buffer of at least botan_mp_num_bytes(mp) bytes
1118* @return 0 on success, a negative value on failure
1119*/
1120BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_bin(botan_mp_t mp, uint8_t vec[]);
1121
1122/**
1123* View the big-endian binary string encoding of this integer
1124*
1125* Note that the sign of the integer is ignored here; only the absolute value is viewed
1126*
1127* @param mp the integer to encode
1128* @param ctx an application context passed to the view function
1129* @param view the view callback which receives the encoding
1130* @return 0 on success, a negative value on failure
1131*/
1133
1134/**
1135* Set an MP to the big-endian binary value
1136*
1137* @param mp the integer to set
1138* @param vec the big-endian encoding to decode
1139* @param vec_len length of vec in bytes
1140* @return 0 on success, a negative value on failure
1141*/
1142BOTAN_FFI_EXPORT(2, 1) int botan_mp_from_bin(botan_mp_t mp, const uint8_t vec[], size_t vec_len);
1143
1144/**
1145* Convert the MPI to a uint32_t, if possible. Fails if MPI is negative or too large.
1146*
1147* @param mp the integer to convert
1148* @param val set to the value of mp
1149* @return 0 on success, a negative value on failure
1150*/
1151BOTAN_FFI_EXPORT(2, 1) int botan_mp_to_uint32(botan_mp_t mp, uint32_t* val);
1152
1153/**
1154* This function should have been named mp_is_non_negative. Returns 1
1155* iff mp is greater than *or equal to* zero. Use botan_mp_is_negative
1156* to detect negative numbers, botan_mp_is_zero to check for zero.
1157*/
1159
1160/**
1161* Return 1 iff mp is less than 0
1162*/
1164
1165/**
1166* Negate the MPI, ie replace it by its additive inverse
1167* @param mp the integer to negate, modified in place
1168* @return 0 on success, a negative value on failure
1169*/
1171
1172/**
1173* Return 1 iff mp is equal to zero
1174* @param mp the integer to test
1175* @return 1 if zero, 0 if not, or a negative value on error
1176*/
1178
1179/**
1180* Return 1 iff mp is odd
1181* @param mp the integer to test
1182* @return 1 if odd, 0 if even, or a negative value on error
1183*/
1184BOTAN_FFI_DEPRECATED("Use botan_mp_get_bit(0)") BOTAN_FFI_EXPORT(2, 1) int botan_mp_is_odd(botan_mp_t mp);
1185
1186/**
1187* Return 1 iff mp is even
1188* @param mp the integer to test
1189* @return 1 if even, 0 if odd, or a negative value on error
1190*/
1191BOTAN_FFI_DEPRECATED("Use botan_mp_get_bit(0)") BOTAN_FFI_EXPORT(2, 1) int botan_mp_is_even(botan_mp_t mp);
1192
1193/**
1194* Set result to x + y
1195* @param result set to the sum
1196* @param x the first addend
1197* @param y the second addend
1198* @return 0 on success, a negative value on failure
1199*/
1200BOTAN_FFI_EXPORT(2, 8) int botan_mp_add_u32(botan_mp_t result, botan_mp_t x, uint32_t y);
1201
1202/**
1203* Set result to x - y
1204* @param result set to the difference
1205* @param x the minuend
1206* @param y the subtrahend
1207* @return 0 on success, a negative value on failure
1208*/
1209BOTAN_FFI_EXPORT(2, 8) int botan_mp_sub_u32(botan_mp_t result, botan_mp_t x, uint32_t y);
1210
1211/**
1212* Set result to x + y
1213* @param result set to the sum
1214* @param x the first addend
1215* @param y the second addend
1216* @return 0 on success, a negative value on failure
1217*/
1219
1220/**
1221* Set result to x - y
1222* @param result set to the difference
1223* @param x the minuend
1224* @param y the subtrahend
1225* @return 0 on success, a negative value on failure
1226*/
1228
1229/**
1230* Set result to x * y
1231* @param result set to the product
1232* @param x the first factor
1233* @param y the second factor
1234* @return 0 on success, a negative value on failure
1235*/
1237
1238/**
1239* Divide x by y, producing both the quotient and the remainder
1240* @param quotient set to x / y
1241* @param remainder set to x % y
1242* @param x the dividend
1243* @param y the divisor, which must not be zero
1244* @return 0 on success, a negative value on failure
1245*/
1246BOTAN_FFI_EXPORT(2, 1)
1247int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, botan_mp_t x, botan_mp_t y);
1248
1249/**
1250* Set result to (x * y) % mod
1251* @param result set to the modular product
1252* @param x the first factor
1253* @param y the second factor
1254* @param mod the modulus, which must be positive
1255* @return 0 on success, a negative value on failure
1256*/
1257BOTAN_FFI_EXPORT(2, 1)
1259
1260/**
1261* Test if two integers are equal
1262* @param x the first integer
1263* @param y the second integer
1264* @return 1 if x == y, 0 if x != y, or a negative value on error
1265*/
1267
1268/**
1269* Compare two integers
1270* @param result set to -1 if x < y, 0 if x == y, 1 if x > y
1271* @param x the first integer
1272* @param y the second integer
1273* @return 0 on success, a negative value on failure
1274*/
1275BOTAN_FFI_EXPORT(2, 1) int botan_mp_cmp(int* result, botan_mp_t x, botan_mp_t y);
1276
1277/**
1278* Swap the values of two integers
1279* @param x the first integer
1280* @param y the second integer
1281* @return 0 on success, a negative value on failure
1282*/
1284
1285/**
1286* Set out to (base^exponent) % modulus
1287* @param out set to the result of the modular exponentiation
1288* @param base the base
1289* @param exponent the exponent
1290* @param modulus the modulus, which must be positive
1291* @return 0 on success, a negative value on failure
1292*/
1293BOTAN_FFI_EXPORT(2, 1)
1294int botan_mp_powmod(botan_mp_t out, botan_mp_t base, botan_mp_t exponent, botan_mp_t modulus);
1295
1296/**
1297* Set out to in shifted left by the specified number of bits
1298* @param out set to the shifted value
1299* @param in the integer to shift
1300* @param shift the number of bits to shift by
1301* @return 0 on success, a negative value on failure
1302*/
1303BOTAN_FFI_EXPORT(2, 1) int botan_mp_lshift(botan_mp_t out, botan_mp_t in, size_t shift);
1304
1305/**
1306* Set out to in shifted right by the specified number of bits
1307* @param out set to the shifted value
1308* @param in the integer to shift
1309* @param shift the number of bits to shift by
1310* @return 0 on success, a negative value on failure
1311*/
1312BOTAN_FFI_EXPORT(2, 1) int botan_mp_rshift(botan_mp_t out, botan_mp_t in, size_t shift);
1313
1314/**
1315* Set out to the inverse of in modulo the specified modulus. If no
1316* inverse exists, out is set to zero.
1317* @param out set to the modular inverse
1318* @param in the value to invert
1319* @param modulus the modulus
1320* @return 0 on success, a negative value on failure
1321*/
1323
1324/**
1325* Set rand_out to a random integer of the specified bit length
1326* @param rand_out set to the random integer
1327* @param rng a random number generator
1328* @param bits the desired bit length
1329* @return 0 on success, a negative value on failure
1330*/
1331BOTAN_FFI_EXPORT(2, 1) int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits);
1332
1333/**
1334* Set rand_out to a random integer within the half-open range [lower_bound, upper_bound)
1335* @param rand_out set to the random integer
1336* @param rng a random number generator
1337* @param lower_bound the inclusive lower bound
1338* @param upper_bound the exclusive upper bound
1339* @return 0 on success, a negative value on failure
1340*/
1341BOTAN_FFI_EXPORT(2, 1)
1342int botan_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng, botan_mp_t lower_bound, botan_mp_t upper_bound);
1343
1344/**
1345* Set out to the greatest common divisor of x and y
1346* @param out set to gcd(x, y)
1347* @param x the first integer
1348* @param y the second integer
1349* @return 0 on success, a negative value on failure
1350*/
1352
1353/**
1354* Returns 0 if n is not prime
1355* Returns 1 if n is prime
1356* Returns negative number on error
1357*/
1358BOTAN_FFI_EXPORT(2, 1) int botan_mp_is_prime(botan_mp_t n, botan_rng_t rng, size_t test_prob);
1359
1360/**
1361* Returns 0 if specified bit of n is not set
1362* Returns 1 if specified bit of n is set
1363* Returns negative number on error
1364*/
1365BOTAN_FFI_EXPORT(2, 1) int botan_mp_get_bit(botan_mp_t n, size_t bit);
1366
1367/**
1368* Set the specified bit
1369*/
1370BOTAN_FFI_EXPORT(2, 1) int botan_mp_set_bit(botan_mp_t n, size_t bit);
1371
1372/**
1373* Clear the specified bit
1374*/
1375BOTAN_FFI_EXPORT(2, 1) int botan_mp_clear_bit(botan_mp_t n, size_t bit);
1376
1377/* Bcrypt password hashing */
1378
1379/**
1380* Create a password hash using Bcrypt
1381* @param out buffer holding the password hash, should be of length 64 bytes
1382* @param out_len the desired output length in bytes
1383* @param password the password
1384* @param rng a random number generator
1385* @param work_factor how much work to do to slow down guessing attacks
1386* @param flags should be 0 in current API revision, all other uses are reserved
1387* and return BOTAN_FFI_ERROR_BAD_FLAG
1388* @return 0 on success, a negative value on failure
1389*
1390* Output is formatted bcrypt $2a$...
1391*
1392* TOD(Botan4) this should use char for the type of `out`
1393*/
1394BOTAN_FFI_EXPORT(2, 0)
1396 uint8_t* out, size_t* out_len, const char* password, botan_rng_t rng, size_t work_factor, uint32_t flags);
1397
1398/**
1399* Check a previously created password hash
1400* @param pass the password to check against
1401* @param hash the stored hash to check against
1402* @return 0 if if this password/hash combination is valid,
1403* 1 if the combination is not valid (but otherwise well formed),
1404* negative on error
1405*/
1406BOTAN_FFI_EXPORT(2, 0) int botan_bcrypt_is_valid(const char* pass, const char* hash);
1407
1408/*
1409* OIDs
1410*/
1411
1412/**
1413* Opaque type of an ASN.1 object identifier
1414*/
1415typedef struct botan_asn1_oid_struct* botan_asn1_oid_t;
1416
1417/**
1418* Frees all resources of the OID object
1419* @param oid the OID object to destroy
1420* @returns negative number on error, or zero on success
1421*/
1423
1424/**
1425* Create an OID from a string, either dot notation (e.g. '1.2.3.4') or a registered name (e.g. 'RSA')
1426* @param oid handle to the resulting OID
1427* @param oid_str the name of the OID to create
1428* @returns negative number on error, or zero on success
1429*/
1430BOTAN_FFI_EXPORT(3, 8) int botan_oid_from_string(botan_asn1_oid_t* oid, const char* oid_str);
1431
1432/**
1433* Registers an OID so that it may later be retrieved by name
1434* @returns negative number on error, or zero on success
1435*/
1436BOTAN_FFI_EXPORT(3, 8) int botan_oid_register(botan_asn1_oid_t oid, const char* name);
1437
1438/**
1439* View an OID in dot notation
1440*/
1442
1443/**
1444* View an OIDs registered name if it exists, else its dot notation
1445*/
1447
1448/**
1449* Test if two OIDs are equal
1450* @param a the first OID
1451* @param b the second OID
1452* @returns 0 if a != b
1453* @returns 1 if a == b
1454* @returns negative number on error
1455*/
1457
1458/**
1459* Sets @param result to comparison result:
1460* -1 if a < b, 0 if a == b, 1 if a > b
1461* @returns negative number on error or zero on success
1462*/
1464
1465/*
1466* EC Groups
1467*/
1468
1469/**
1470* Opaque type of a set of elliptic curve domain parameters
1471*/
1472typedef struct botan_ec_group_struct* botan_ec_group_t;
1473
1474/**
1475* Frees all resources of the EC Group object
1476* @param ec_group the EC Group object to destroy
1477* @returns negative number on error, or zero on success
1478*/
1480
1481/**
1482* Checks if in this build configuration it is possible to register an application specific elliptic curve and sets
1483* @param out to 1 if so, 0 otherwise
1484* @returns 0 on success, a negative value on failure
1485*/
1487
1488/**
1489* Checks if in this build configuration botan_ec_group_from_name(group_ptr, name) will succeed and sets
1490* @param name the name of the group to check
1491* @param out to 1 if so, 0 otherwise.
1492* @returns negative number on error, or zero on success
1493*/
1494BOTAN_FFI_EXPORT(3, 8) int botan_ec_group_supports_named_group(const char* name, int* out);
1495
1496/**
1497* Create a new EC Group from parameters
1498* @warning use only elliptic curve parameters that you trust
1499*
1500* @param ec_group the new object will be placed here
1501* @param oid the OID to associate with the group
1502* @param p the elliptic curve prime (at most 521 bits)
1503* @param a the elliptic curve a param
1504* @param b the elliptic curve b param
1505* @param base_x the x coordinate of the group generator
1506* @param base_y the y coordinate of the group generator
1507* @param order the order of the group
1508* @returns negative number on error, or zero on success
1509*/
1510BOTAN_FFI_EXPORT(3, 8)
1512 botan_asn1_oid_t oid,
1513 botan_mp_t p,
1514 botan_mp_t a,
1515 botan_mp_t b,
1516 botan_mp_t base_x,
1517 botan_mp_t base_y,
1518 botan_mp_t order);
1519
1520/**
1521* Decode a BER encoded ECC domain parameter set
1522* @param ec_group the new object will be placed here
1523* @param ber encoding
1524* @param ber_len size of the encoding in bytes
1525* @returns negative number on error, or zero on success
1526*/
1527BOTAN_FFI_EXPORT(3, 8) int botan_ec_group_from_ber(botan_ec_group_t* ec_group, const uint8_t* ber, size_t ber_len);
1528
1529/**
1530* Initialize an EC Group from the PEM/ASN.1 encoding
1531* @param ec_group the new object will be placed here
1532* @param pem encoding
1533* @returns negative number on error, or zero on success
1534*/
1535BOTAN_FFI_EXPORT(3, 8) int botan_ec_group_from_pem(botan_ec_group_t* ec_group, const char* pem);
1536
1537/**
1538* Initialize an EC Group from a group named by an object identifier
1539* @param ec_group the new object will be placed here
1540* @param oid a known OID
1541* @returns negative number on error, or zero on success
1542*/
1544
1545/**
1546* Initialize an EC Group from a common group name (eg "secp256r1")
1547* @param ec_group the new object will be placed here
1548* @param name a known group name
1549* @returns negative number on error, or zero on success
1550*/
1551BOTAN_FFI_EXPORT(3, 8) int botan_ec_group_from_name(botan_ec_group_t* ec_group, const char* name);
1552
1553/**
1554* Unregister a previously registered group.
1555* @param oid the oid associated with the group to unregister
1556* @returns 1 if the group was found and unregistered, else 0
1557*
1558* Using this is discouraged for normal use. This is only useful or necessary if
1559* you are registering a very large number of distinct groups, and need to worry about memory constraints.
1560*/
1562
1563/**
1564* View an EC Group in DER encoding
1565*/
1566BOTAN_FFI_EXPORT(3, 8)
1568
1569/**
1570* View an EC Group in PEM encoding
1571*/
1572BOTAN_FFI_EXPORT(3, 8)
1574
1575/**
1576* Get the curve OID of an EC Group
1577*/
1579
1580/**
1581* Get the prime modulus of the field
1582*/
1584
1585/**
1586* Get the a parameter of the elliptic curve equation
1587*/
1589
1590/**
1591* Get the b parameter of the elliptic curve equation
1592*/
1594
1595/**
1596* Get the x coordinate of the base point
1597*/
1599
1600/**
1601* Get the y coordinate of the base point
1602*/
1604
1605/**
1606* Get the order of the base point
1607*/
1609
1610/**
1611* Test if two EC Groups describe the same curve
1612* @param curve1 the first group
1613* @param curve2 the second group
1614* @returns 0 if curve1 != curve2
1615* @returns 1 if curve1 == curve2
1616* @returns negative number on error
1617*/
1619
1620/**
1621* Opaque type of a scalar, that is an integer modulo the group order
1622*/
1623typedef struct botan_ec_scalar_struct* botan_ec_scalar_t;
1624
1625/**
1626* Opaque type of an elliptic curve point
1627*/
1628typedef struct botan_ec_point_struct* botan_ec_point_t;
1629
1630/**
1631* Frees all resources of the scalar object
1632* @param ec_scalar the scalar object to destroy
1633* @returns negative number on error, or zero on success
1634*/
1636
1637/**
1638* Create a new random scalar value
1639*/
1640BOTAN_FFI_EXPORT(3, 12)
1642
1643/**
1644* Convert from an MPI to a scalar
1645* @returns a negative number if the provided MPI is negative or too large, 0 on success
1646*/
1647BOTAN_FFI_EXPORT(3, 12)
1649
1650/**
1651* Convert from a scalar to an MPI
1652* @returns a negative number on failure, 0 on success
1653*/
1654BOTAN_FFI_EXPORT(3, 12)
1656
1657/**
1658* Frees all resources of the point object
1659* @param ec_point the point object to destroy
1660* @returns negative number on error, or zero on success
1661*/
1663
1664/**
1665* Create a point set to the identity element of the group
1666*/
1668
1669/**
1670* Create a point set to the standard group generator
1671*/
1673
1674/**
1675* Create a point from a pair (x,y) of integers
1676* The integers must be within the field and must satisfy the curve equation
1677*/
1678BOTAN_FFI_EXPORT(3, 12)
1680
1681/**
1682* Create a point from a SEC1 compressed or uncompressed format.
1683* @returns negative number on error
1684*/
1685BOTAN_FFI_EXPORT(3, 12)
1687 botan_ec_group_t ec_group,
1688 const uint8_t* bytes,
1689 size_t bytes_len);
1690
1691/**
1692* View the fixed length encoding of the affine x coordinate
1693* @returns negative number on error
1694*/
1695BOTAN_FFI_EXPORT(3, 12)
1697
1698/**
1699* View the fixed length encoding of the affine y coordinate
1700* @returns negative number on error
1701*/
1702BOTAN_FFI_EXPORT(3, 12)
1704
1705/**
1706* View the fixed length encoding of the affine x and y coordinates
1707* @returns negative number on error
1708*/
1709BOTAN_FFI_EXPORT(3, 12)
1711
1712/**
1713* View the fixed length SEC1 uncompressed encoding
1714* @returns negative number on error
1715*/
1716BOTAN_FFI_EXPORT(3, 12)
1718
1719/**
1720* View the fixed length SEC1 compressed encoding
1721* @returns negative number on error
1722*/
1723BOTAN_FFI_EXPORT(3, 12)
1725
1726/**
1727* Test if a point is the identity element of the group
1728* @param ec_point the point to test
1729* @returns 1 if ec_point is the identity element, else 0
1730* @returns negative number on error
1731*/
1733
1734/**
1735* Test if two points are equal
1736* @param x the first point
1737* @param y the second point
1738* @returns 1 if x == y, else 0
1739* @returns negative number on error
1740*/
1742
1743/**
1744* Compute the additive inverse of a point
1745* @param result the new object will be placed here
1746* @param ec_point point to negate
1747* @returns negative number on error, or zero on success
1748*/
1750
1751/**
1752* Add two points
1753* @param result the new object will be placed here
1754* @param x the first point
1755* @param y the second point
1756* @returns negative number on error, or zero on success
1757*/
1759
1760/**
1761* Multiply a point by a scalar
1762* @param result the new object will be placed here
1763* @param ec_point the point to multiply
1764* @param ec_scalar the scalar to multiply by
1765* @param rng a random number generator, used for blinding
1766* @returns negative number on error, or zero on success
1767*/
1768BOTAN_FFI_EXPORT(3, 12)
1770 botan_ec_point_t ec_point,
1771 botan_ec_scalar_t ec_scalar,
1772 botan_rng_t rng);
1773
1774/**
1775* Opaque type of a private key
1776*/
1777typedef struct botan_privkey_struct* botan_privkey_t;
1778
1779/**
1780* Create a new private key
1781* @param key the new object will be placed here
1782* @param algo_name something like "RSA" or "ECDSA"
1783* @param algo_params is specific to the algorithm. For RSA, specifies
1784* the modulus bit length. For ECC is the name of the curve.
1785* @param rng a random number generator
1786*/
1787BOTAN_FFI_EXPORT(2, 0)
1788int botan_privkey_create(botan_privkey_t* key, const char* algo_name, const char* algo_params, botan_rng_t rng);
1789
1790/**
1791* Create a new ec private key
1792* @param key the new object will be placed here
1793* @param algo_name something like "ECDSA" or "ECDH"
1794* @param ec_group a (possibly application specific) elliptic curve
1795* @param rng a random number generator
1796*/
1797BOTAN_FFI_EXPORT(3, 8)
1798int botan_ec_privkey_create(botan_privkey_t* key, const char* algo_name, botan_ec_group_t ec_group, botan_rng_t rng);
1799
1800#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS 1
1801
1802/**
1803* Test the consistency of a private key
1804* @param key the private key to check
1805* @param rng a random number generator
1806* @param flags either 0 or BOTAN_CHECK_KEY_EXPENSIVE_TESTS
1807* @return 0 if the key is valid, negative if invalid or some other error
1808*/
1809BOTAN_FFI_EXPORT(2, 0) int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags);
1810
1811/**
1812* Create a new RSA private key
1813* @param key the new object will be placed here
1814* @param rng a random number generator
1815* @param n_bits the bit length of the modulus
1816* @return 0 on success, a negative value on failure
1817*/
1818BOTAN_FFI_DEPRECATED("Use botan_privkey_create")
1819BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_rsa(botan_privkey_t* key, botan_rng_t rng, size_t n_bits);
1820
1821/**
1822* Create a new ECDSA private key
1823* @param key the new object will be placed here
1824* @param rng a random number generator
1825* @param params the name of the curve, eg "secp256r1"
1826* @return 0 on success, a negative value on failure
1827*/
1828BOTAN_FFI_DEPRECATED("Use botan_privkey_create")
1829BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_ecdsa(botan_privkey_t* key, botan_rng_t rng, const char* params);
1830
1831/**
1832* Create a new ECDH private key
1833* @param key the new object will be placed here
1834* @param rng a random number generator
1835* @param params the name of the curve, eg "secp256r1"
1836* @return 0 on success, a negative value on failure
1837*/
1838BOTAN_FFI_DEPRECATED("Use botan_privkey_create")
1839BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_ecdh(botan_privkey_t* key, botan_rng_t rng, const char* params);
1840
1841/**
1842* Create a new McEliece private key
1843* @param key the new object will be placed here
1844* @param rng a random number generator
1845* @param n the code length
1846* @param t the error correction capability
1847* @return 0 on success, a negative value on failure
1848*/
1849BOTAN_FFI_DEPRECATED("Use botan_privkey_create")
1850BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_mceliece(botan_privkey_t* key, botan_rng_t rng, size_t n, size_t t);
1851
1852/**
1853* Create a new Diffie-Hellman private key
1854* @param key the new object will be placed here
1855* @param rng a random number generator
1856* @param param the name of the group, eg "modp/ietf/2048"
1857* @return 0 on success, a negative value on failure
1858*/
1859BOTAN_FFI_DEPRECATED("Use botan_privkey_create")
1860BOTAN_FFI_EXPORT(2, 0) int botan_privkey_create_dh(botan_privkey_t* key, botan_rng_t rng, const char* param);
1861
1862/**
1863 * Generates DSA key pair. Gives to a caller control over key length
1864 * and order of a subgroup 'q'.
1865 *
1866 * @param key handler to the resulting key
1867 * @param rng initialized PRNG
1868 * @param pbits length of the key in bits. Must be between in range (1024, 3072)
1869 * and multiple of 64. Bit size of the prime 'p'
1870 * @param qbits order of the subgroup. Must be in range (160, 256) and multiple
1871 * of 8
1872 *
1873 * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
1874 * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
1875 * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
1876 * `qbits'
1877 * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
1878 *
1879*/
1880BOTAN_FFI_EXPORT(2, 5) int botan_privkey_create_dsa(botan_privkey_t* key, botan_rng_t rng, size_t pbits, size_t qbits);
1881
1882/**
1883 * Generates ElGamal key pair. Caller has a control over key length
1884 * and order of a subgroup 'q'. Function is able to use two types of
1885 * primes:
1886 * * if pbits-1 == qbits then safe primes are used for key generation
1887 * * otherwise generation uses group of prime order
1888 *
1889 * @param key handler to the resulting key
1890 * @param rng initialized PRNG
1891 * @param pbits length of the key in bits. Must be at least 1024
1892 * @param qbits order of the subgroup. Must be at least 160
1893 *
1894 * @returns BOTAN_FFI_SUCCESS Success, `key' initialized with DSA key
1895 * @returns BOTAN_FFI_ERROR_NULL_POINTER either `key' or `rng' is NULL
1896 * @returns BOTAN_FFI_ERROR_BAD_PARAMETER unexpected value for either `pbits' or
1897 * `qbits'
1898 * @returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED functionality not implemented
1899 *
1900*/
1901BOTAN_FFI_EXPORT(2, 5)
1902int botan_privkey_create_elgamal(botan_privkey_t* key, botan_rng_t rng, size_t pbits, size_t qbits);
1903
1904/**
1905* Input currently assumed to be PKCS #8 structure;
1906* Set password to NULL to indicate no encryption expected
1907* Starting in 2.8.0, the rng parameter is unused and may be set to null
1908*/
1909BOTAN_FFI_EXPORT(2, 0)
1910int botan_privkey_load(botan_privkey_t* key, botan_rng_t rng, const uint8_t bits[], size_t len, const char* password);
1911
1912/**
1913* Frees all resources of the private key object
1914* @param key the private key to destroy
1915* @return 0 if success, error if invalid object handle
1916*/
1918
1919#define BOTAN_PRIVKEY_EXPORT_FLAG_DER 0
1920#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM 1
1921#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW 2
1922
1923/**
1924* Export a private key in DER, PEM or raw encoding
1925*
1926* On input *out_len is number of bytes in out[]
1927* On output *out_len is number of bytes written (or required)
1928* If out is not big enough no output is written, *out_len is set and 1 is returned
1929* Returns 0 on success and sets
1930* If some other error occurs a negative integer is returned.
1931*
1932* @param key the private key to export
1933* @param out output buffer
1934* @param out_len on input the size of out, on output the number of bytes written or required
1935* @param flags one of BOTAN_PRIVKEY_EXPORT_FLAG_DER, _PEM or _RAW
1936* @return 0 on success, 1 if the buffer was too small, a negative value on other failures
1937*/
1938BOTAN_FFI_DEPRECATED("Use botan_privkey_view_{der,pem,raw}")
1939BOTAN_FFI_EXPORT(2, 0) int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t* out_len, uint32_t flags);
1940
1941/**
1942* View the private key's DER encoding
1943*/
1945
1946/**
1947* View the private key's PEM encoding
1948*/
1950
1951/**
1952* View the private key's raw encoding
1953*/
1955
1956/**
1957* Get the name of the algorithm this private key is for
1958* @param key the private key to query
1959* @param out output buffer
1960* @param out_len on input the length of out, on success the number of bytes written
1961* @return 0 on success, a negative value on failure
1962*/
1963BOTAN_FFI_EXPORT(2, 8) int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t* out_len);
1964
1965/**
1966* Export a private key encrypted with a passphrase
1967*
1968* Set encryption_algo to NULL or "" to have the library choose a default (recommended)
1969*
1970* @param key the private key to export
1971* @param out output buffer
1972* @param out_len on input the size of out, on output the number of bytes written or required
1973* @param rng a random number generator
1974* @param passphrase the passphrase to encrypt under
1975* @param encryption_algo the cipher to use, or NULL for the default
1976* @param flags either BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
1977* @return 0 on success, a negative value on failure
1978*/
1979BOTAN_FFI_DEPRECATED("Use botan_privkey_export_encrypted_pbkdf_{msec,iter}")
1980BOTAN_FFI_EXPORT(2, 0)
1982 uint8_t out[],
1983 size_t* out_len,
1984 botan_rng_t rng,
1985 const char* passphrase,
1986 const char* encryption_algo,
1987 uint32_t flags);
1988
1989/**
1990* Export a private key encrypted with a passphrase, running the PBKDF for a
1991* specified amount of time
1992*
1993* Note: starting in 3.0, the output iterations count is not provided
1994*
1995* @param key the private key to export
1996* @param out output buffer
1997* @param out_len on input the size of out, on output the number of bytes written or required
1998* @param rng a random number generator
1999* @param passphrase the passphrase to encrypt under
2000* @param pbkdf_msec_runtime desired PBKDF runtime in milliseconds
2001* @param pbkdf_iterations_out ignored since 3.0
2002* @param cipher_algo the cipher to use, or NULL for the default
2003* @param pbkdf_algo the password hash to use, or NULL for the default
2004* @param flags either BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
2005* @return 0 on success, a negative value on failure
2006*/
2007BOTAN_FFI_DEPRECATED("Use botan_privkey_view_encrypted_{der,pem}_timed")
2008BOTAN_FFI_EXPORT(2, 0)
2010 uint8_t out[],
2011 size_t* out_len,
2012 botan_rng_t rng,
2013 const char* passphrase,
2014 uint32_t pbkdf_msec_runtime,
2015 size_t* pbkdf_iterations_out,
2016 const char* cipher_algo,
2017 const char* pbkdf_algo,
2018 uint32_t flags);
2019
2020/**
2021* Export a private key encrypted with a passphrase, using the specified number
2022* of PBKDF iterations.
2023*
2024* @param key the private key to export
2025* @param out output buffer
2026* @param out_len on input the size of out, on output the number of bytes written or required
2027* @param rng a random number generator
2028* @param passphrase the passphrase to encrypt under
2029* @param pbkdf_iterations the number of PBKDF iterations to run
2030* @param cipher_algo the cipher to use, or NULL for the default
2031* @param pbkdf_algo the password hash to use, or NULL for the default
2032* @param flags either BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
2033* @return 0 on success, a negative value on failure
2034*/
2035BOTAN_FFI_DEPRECATED("Use botan_privkey_view_encrypted_{der,pem}")
2036BOTAN_FFI_EXPORT(2, 0)
2038 uint8_t out[],
2039 size_t* out_len,
2040 botan_rng_t rng,
2041 const char* passphrase,
2042 size_t pbkdf_iterations,
2043 const char* cipher_algo,
2044 const char* pbkdf_algo,
2045 uint32_t flags);
2046
2047/**
2048* View the encryption of a private key (binary DER encoding)
2049*
2050* Set cipher_algo, pbkdf_algo to NULL to use defaults
2051* Set pbkdf_iterations to 0 to use defaults
2052*/
2053BOTAN_FFI_EXPORT(3, 0)
2055 botan_rng_t rng,
2056 const char* passphrase,
2057 const char* cipher_algo,
2058 const char* pbkdf_algo,
2059 size_t pbkdf_iterations,
2060 botan_view_ctx ctx,
2061 botan_view_bin_fn view);
2062
2063/**
2064* View the encryption of a private key (binary DER encoding)
2065*
2066* Set cipher_algo, pbkdf_algo to NULL to use defaults
2067*/
2068BOTAN_FFI_EXPORT(3, 0)
2070 botan_rng_t rng,
2071 const char* passphrase,
2072 const char* cipher_algo,
2073 const char* pbkdf_algo,
2074 size_t pbkdf_runtime_msec,
2075 botan_view_ctx ctx,
2076 botan_view_bin_fn view);
2077
2078/**
2079* View the encryption of a private key (PEM encoding)
2080*
2081* Set cipher_algo, pbkdf_algo to NULL to use defaults
2082* Set pbkdf_iterations to 0 to use defaults
2083*/
2084BOTAN_FFI_EXPORT(3, 0)
2086 botan_rng_t rng,
2087 const char* passphrase,
2088 const char* cipher_algo,
2089 const char* pbkdf_algo,
2090 size_t pbkdf_iterations,
2091 botan_view_ctx ctx,
2092 botan_view_str_fn view);
2093
2094/**
2095* View the encryption of a private key (PEM encoding)
2096*
2097* Set cipher_algo, pbkdf_algo to NULL to use defaults
2098*/
2099BOTAN_FFI_EXPORT(3, 0)
2101 botan_rng_t rng,
2102 const char* passphrase,
2103 const char* cipher_algo,
2104 const char* pbkdf_algo,
2105 size_t pbkdf_runtime_msec,
2106 botan_view_ctx ctx,
2107 botan_view_str_fn view);
2108
2109/**
2110* Opaque type of a public key
2111*/
2112typedef struct botan_pubkey_struct* botan_pubkey_t;
2113
2114/**
2115* Load a public key from an X.509 SubjectPublicKeyInfo structure
2116* @param key the new object will be placed here
2117* @param bits the DER encoding to load
2118* @param len length of bits in bytes
2119* @return 0 on success, a negative value on failure
2120*/
2121BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t len);
2122
2123/**
2124* Extract the public key associated with a private key
2125* @param out the new object will be placed here
2126* @param in the private key to extract the public key from
2127* @return 0 on success, a negative value on failure
2128*/
2130
2131/**
2132* Export a public key in DER, PEM or raw encoding
2133* @param key the public key to export
2134* @param out output buffer
2135* @param out_len on input the size of out, on output the number of bytes written or required
2136* @param flags one of BOTAN_PRIVKEY_EXPORT_FLAG_DER, _PEM or _RAW
2137* @return 0 on success, a negative value on failure
2138*/
2139BOTAN_FFI_DEPRECATED("Use botan_pubkey_view_{der,pem,raw}")
2140BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags);
2141
2142/**
2143* View the public key's DER encoding
2144*/
2146
2147/**
2148* View the public key's PEM encoding
2149*/
2151
2152/**
2153* View the public key's raw encoding
2154*/
2156
2157/**
2158* Get the name of the algorithm this public key is for
2159* @param key the public key to query
2160* @param out output buffer
2161* @param out_len on input the length of out, on success the number of bytes written
2162* @return 0 on success, a negative value on failure
2163*/
2164BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len);
2165
2166/**
2167* Returns 0 if key is valid, negative if invalid key or some other error
2168*/
2169BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags);
2170
2171/**
2172* Estimate the strength of this key, in bits, against the best known attack
2173* @param key the public key to query
2174* @param estimate set to the estimated strength in bits
2175* @return 0 on success, a negative value on failure
2176*/
2177BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate);
2178
2179/**
2180* Compute a fingerprint (hash of the public key encoding)
2181* @param key the public key to fingerprint
2182* @param hash the name of the hash to use, eg "SHA-256"
2183* @param out output buffer
2184* @param out_len on input the size of out, on output the number of bytes written or required
2185* @return 0 on success, a negative value on failure
2186*/
2187BOTAN_FFI_EXPORT(2, 0)
2188int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash, uint8_t out[], size_t* out_len);
2189
2190/**
2191* Frees all resources of the public key object
2192* @param key the public key to destroy
2193* @return 0 if success, error if invalid object handle
2194*/
2196
2197/**
2198* Get an arbitrary named field from a public key, eg "n" or "e" for RSA
2199* @param output set to the value of the requested field
2200* @param key the public key to query
2201* @param field_name the name of the field to retrieve
2202* @return 0 on success, a negative value on failure
2203*/
2204BOTAN_FFI_EXPORT(2, 0) int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char* field_name);
2205
2206/**
2207* Get an arbitrary named field from a private key, eg "p" or "q" for RSA
2208* @param output set to the value of the requested field
2209* @param key the private key to query
2210* @param field_name the name of the field to retrieve
2211* @return 0 on success, a negative value on failure
2212*/
2213BOTAN_FFI_EXPORT(2, 0) int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char* field_name);
2214
2215/**
2216* Get the object identifier associated with a public key
2217* @param oid the new object will be placed here
2218* @param key the public key to query
2219* @return 0 on success, a negative value on failure
2220*/
2221BOTAN_FFI_EXPORT(3, 8)
2223
2224/**
2225* Get the object identifier associated with a private key
2226* @param oid the new object will be placed here
2227* @param key the private key to query
2228* @return 0 on success, a negative value on failure
2229*/
2230BOTAN_FFI_EXPORT(3, 8)
2232
2233/**
2234* Checks whether a key is stateful and sets
2235* @param key the private key to check
2236* @param out to 1 if it is, or 0 if the key is not stateful
2237* @return 0 on success, a negative value on failure
2238*/
2240
2241/**
2242* Gets information on many operations a (stateful) key has remaining and sets
2243* @param key the private key to check
2244* @param out to that value
2245* @return 0 on success, a negative value on failure or if the key is not stateful
2246*/
2248
2249/*
2250* Algorithm specific key operations: RSA
2251*/
2252
2253/**
2254* Load an RSA private key from its factors and public exponent
2255* @param key the new object will be placed here
2256* @param p the first prime factor
2257* @param q the second prime factor
2258* @param e the public exponent
2259* @return 0 on success, a negative value on failure
2260*/
2262
2263/**
2264* Load an RSA private key from a PKCS #1 RSAPrivateKey structure
2265* @param key the new object will be placed here
2266* @param bits the DER encoding to load
2267* @param len length of bits in bytes
2268* @return 0 on success, a negative value on failure
2269*/
2270BOTAN_FFI_EXPORT(2, 8) int botan_privkey_load_rsa_pkcs1(botan_privkey_t* key, const uint8_t bits[], size_t len);
2271
2272/**
2273* Get the first prime factor of an RSA private key
2274* @param p set to the value of the factor
2275* @param rsa_key the RSA private key
2276* @return 0 on success, a negative value on failure
2277*/
2278BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
2280
2281/**
2282* Get the second prime factor of an RSA private key
2283* @param q set to the value of the factor
2284* @param rsa_key the RSA private key
2285* @return 0 on success, a negative value on failure
2286*/
2287BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
2289
2290/**
2291* Get the private exponent of an RSA private key
2292* @param d set to the value of the private exponent
2293* @param rsa_key the RSA private key
2294* @return 0 on success, a negative value on failure
2295*/
2296BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
2298
2299/**
2300* Get the modulus of an RSA private key
2301* @param n set to the value of the modulus
2302* @param rsa_key the RSA private key
2303* @return 0 on success, a negative value on failure
2304*/
2305BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
2307
2308/**
2309* Get the public exponent of an RSA private key
2310* @param e set to the value of the public exponent
2311* @param rsa_key the RSA private key
2312* @return 0 on success, a negative value on failure
2313*/
2314BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
2316
2317/**
2318* Export an RSA private key as a PKCS #1 RSAPrivateKey structure
2319* @param rsa_key the RSA private key
2320* @param out output buffer
2321* @param out_len on input the size of out, on output the number of bytes written or required
2322* @param flags either BOTAN_PRIVKEY_EXPORT_FLAG_DER or BOTAN_PRIVKEY_EXPORT_FLAG_PEM
2323* @return 0 on success, a negative value on failure
2324*/
2325BOTAN_FFI_EXPORT(2, 8)
2326int botan_privkey_rsa_get_privkey(botan_privkey_t rsa_key, uint8_t out[], size_t* out_len, uint32_t flags);
2327
2328/**
2329* Load an RSA public key from its modulus and public exponent
2330* @param key the new object will be placed here
2331* @param n the modulus
2332* @param e the public exponent
2333* @return 0 on success, a negative value on failure
2334*/
2336
2337/**
2338* Load an RSA public key from a PKCS #1 RSAPublicKey structure
2339* @param key the new object will be placed here
2340* @param bits the DER encoding to load
2341* @param len length of bits in bytes
2342* @return 0 on success, a negative value on failure
2343*/
2344BOTAN_FFI_EXPORT(3, 11) int botan_pubkey_load_rsa_pkcs1(botan_pubkey_t* key, const uint8_t bits[], size_t len);
2345
2346/**
2347* Get the public exponent of an RSA public key
2348* @param e set to the value of the public exponent
2349* @param rsa_key the RSA public key
2350* @return 0 on success, a negative value on failure
2351*/
2352BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
2354
2355/**
2356* Get the modulus of an RSA public key
2357* @param n set to the value of the modulus
2358* @param rsa_key the RSA public key
2359* @return 0 on success, a negative value on failure
2360*/
2361BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
2363
2364/*
2365* Algorithm specific key operations: DSA
2366*/
2367
2368/**
2369* Load a DSA private key from its group parameters and secret value
2370* @param key the new object will be placed here
2371* @param p the group prime
2372* @param q the order of the subgroup
2373* @param g the subgroup generator
2374* @param x the private key
2375* @return 0 on success, a negative value on failure
2376*/
2377BOTAN_FFI_EXPORT(2, 0)
2379
2380/**
2381* Load a DSA public key from its group parameters and public value
2382* @param key the new object will be placed here
2383* @param p the group prime
2384* @param q the order of the subgroup
2385* @param g the subgroup generator
2386* @param y the public key
2387* @return 0 on success, a negative value on failure
2388*/
2389BOTAN_FFI_EXPORT(2, 0)
2391
2392/**
2393* Get the secret value of a DSA private key
2394* @param n set to the value of the private key
2395* @param key the DSA private key
2396* @return 0 on success, a negative value on failure
2397*/
2398BOTAN_FFI_DEPRECATED("Use botan_privkey_get_field")
2400
2401/**
2402* Get the group prime of a DSA public key
2403* @param p set to the value of the group prime
2404* @param key the DSA public key
2405* @return 0 on success, a negative value on failure
2406*/
2407BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
2409
2410/**
2411* Get the subgroup order of a DSA public key
2412* @param q set to the value of the subgroup order
2413* @param key the DSA public key
2414* @return 0 on success, a negative value on failure
2415*/
2416BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
2418
2419/**
2420* Get the subgroup generator of a DSA public key
2421* @param d set to the value of the generator
2422* @param key the DSA public key
2423* @return 0 on success, a negative value on failure
2424*/
2425BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
2427
2428/**
2429* Get the public value of a DSA public key
2430* @param y set to the value of the public key
2431* @param key the DSA public key
2432* @return 0 on success, a negative value on failure
2433*/
2434BOTAN_FFI_DEPRECATED("Use botan_pubkey_get_field")
2436
2437/**
2438* Loads Diffie Hellman private key
2439*
2440* @param key variable populated with key material
2441* @param p prime order of a Z_p group
2442* @param g group generator
2443* @param x private key
2444*
2445* @pre key is NULL on input
2446* @post function allocates memory and assigns to `key'
2447*
2448* @return 0 on success, a negative value on failure
2449*/
2451/**
2452* Loads Diffie Hellman public key
2453*
2454* @param key variable populated with key material
2455* @param p prime order of a Z_p group
2456* @param g group generator
2457* @param y public key
2458*
2459* @pre key is NULL on input
2460* @post function allocates memory and assigns to `key'
2461*
2462* @return 0 on success, a negative value on failure
2463*/
2465
2466/*
2467* Algorithm specific key operations: ElGamal
2468*/
2469
2470/**
2471* Loads ElGamal public key
2472* @param key variable populated with key material
2473* @param p prime order of a Z_p group
2474* @param g group generator
2475* @param y public key
2476*
2477* @pre key is NULL on input
2478* @post function allocates memory and assigns to `key'
2479*
2480* @return 0 on success, a negative value on failure
2481*/
2483
2484/**
2485* Loads ElGamal private key
2486*
2487* @param key variable populated with key material
2488* @param p prime order of a Z_p group
2489* @param g group generator
2490* @param x private key
2491*
2492* @pre key is NULL on input
2493* @post function allocates memory and assigns to `key'
2494*
2495* @return 0 on success, a negative value on failure
2496*/
2498
2499/*
2500* Algorithm specific key operations: EC keys
2501*/
2502
2503/**
2504* Get the secret scalar of an elliptic curve private key
2505* @param key the EC private key
2506* @param value the new object will be placed here
2507* @return 0 on success, a negative value on failure
2508*/
2510
2511/**
2512* Get the group of an elliptic curve private key
2513* @param key the EC private key
2514* @param ec_group the new object will be placed here
2515* @return 0 on success, a negative value on failure
2516*/
2518
2519/**
2520* Get the group of an elliptic curve public key
2521* @param key the EC public key
2522* @param ec_group the new object will be placed here
2523* @return 0 on success, a negative value on failure
2524*/
2526
2527/*
2528* Algorithm specific key operations: Ed25519
2529*/
2530
2531/**
2532* Load an Ed25519 private key from its raw 32 byte encoding
2533* @param key the new object will be placed here
2534* @param privkey the raw private key
2535* @return 0 on success, a negative value on failure
2536*/
2537BOTAN_FFI_EXPORT(2, 2) int botan_privkey_load_ed25519(botan_privkey_t* key, const uint8_t privkey[32]);
2538
2539/**
2540* Load an Ed25519 public key from its raw 32 byte encoding
2541* @param key the new object will be placed here
2542* @param pubkey the raw public key
2543* @return 0 on success, a negative value on failure
2544*/
2545BOTAN_FFI_EXPORT(2, 2) int botan_pubkey_load_ed25519(botan_pubkey_t* key, const uint8_t pubkey[32]);
2546
2547/**
2548* Get the raw encoding of an Ed25519 private key, followed by the public key
2549* @param key the Ed25519 private key
2550* @param output set to the 64 byte concatenation of the private and public keys
2551* @return 0 on success, a negative value on failure
2552*/
2553BOTAN_FFI_DEPRECATED("Use botan_privkey_view_raw")
2554BOTAN_FFI_EXPORT(2, 2) int botan_privkey_ed25519_get_privkey(botan_privkey_t key, uint8_t output[64]);
2555
2556/**
2557* Get the raw 32 byte encoding of an Ed25519 public key
2558* @param key the Ed25519 public key
2559* @param pubkey set to the raw public key
2560* @return 0 on success, a negative value on failure
2561*/
2562BOTAN_FFI_DEPRECATED("Use botan_pubkey_view_raw")
2563BOTAN_FFI_EXPORT(2, 2) int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key, uint8_t pubkey[32]);
2564
2565/*
2566* Algorithm specific key operations: Ed448
2567*/
2568
2569/**
2570* Load an Ed448 private key from its raw 57 byte encoding
2571* @param key the new object will be placed here
2572* @param privkey the raw private key
2573* @return 0 on success, a negative value on failure
2574*/
2575BOTAN_FFI_EXPORT(3, 4) int botan_privkey_load_ed448(botan_privkey_t* key, const uint8_t privkey[57]);
2576
2577/**
2578* Load an Ed448 public key from its raw 57 byte encoding
2579* @param key the new object will be placed here
2580* @param pubkey the raw public key
2581* @return 0 on success, a negative value on failure
2582*/
2583BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_load_ed448(botan_pubkey_t* key, const uint8_t pubkey[57]);
2584
2585/**
2586* Get the raw 57 byte encoding of an Ed448 private key
2587* @param key the Ed448 private key
2588* @param output set to the raw private key
2589* @return 0 on success, a negative value on failure
2590*/
2591BOTAN_FFI_DEPRECATED("Use botan_privkey_view_raw")
2592BOTAN_FFI_EXPORT(3, 4) int botan_privkey_ed448_get_privkey(botan_privkey_t key, uint8_t output[57]);
2593
2594/**
2595* Get the raw 57 byte encoding of an Ed448 public key
2596* @param key the Ed448 public key
2597* @param pubkey set to the raw public key
2598* @return 0 on success, a negative value on failure
2599*/
2600BOTAN_FFI_DEPRECATED("Use botan_pubkey_view_raw")
2601BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_ed448_get_pubkey(botan_pubkey_t key, uint8_t pubkey[57]);
2602
2603/*
2604* Algorithm specific key operations: X25519
2605*/
2606
2607/**
2608* Load an X25519 private key from its raw 32 byte encoding
2609* @param key the new object will be placed here
2610* @param privkey the raw private key
2611* @return 0 on success, a negative value on failure
2612*/
2613BOTAN_FFI_EXPORT(2, 8) int botan_privkey_load_x25519(botan_privkey_t* key, const uint8_t privkey[32]);
2614
2615/**
2616* Load an X25519 public key from its raw 32 byte encoding
2617* @param key the new object will be placed here
2618* @param pubkey the raw public key
2619* @return 0 on success, a negative value on failure
2620*/
2621BOTAN_FFI_EXPORT(2, 8) int botan_pubkey_load_x25519(botan_pubkey_t* key, const uint8_t pubkey[32]);
2622
2623/**
2624* Get the raw 32 byte encoding of an X25519 private key
2625* @param key the X25519 private key
2626* @param output set to the raw private key
2627* @return 0 on success, a negative value on failure
2628*/
2629BOTAN_FFI_DEPRECATED("Use botan_privkey_view_raw")
2630BOTAN_FFI_EXPORT(2, 8) int botan_privkey_x25519_get_privkey(botan_privkey_t key, uint8_t output[32]);
2631
2632/**
2633* Get the raw 32 byte encoding of an X25519 public key
2634* @param key the X25519 public key
2635* @param pubkey set to the raw public key
2636* @return 0 on success, a negative value on failure
2637*/
2638BOTAN_FFI_DEPRECATED("Use botan_pubkey_view_raw")
2639BOTAN_FFI_EXPORT(2, 8) int botan_pubkey_x25519_get_pubkey(botan_pubkey_t key, uint8_t pubkey[32]);
2640
2641/*
2642* Algorithm specific key operations: X448
2643*/
2644
2645/**
2646* Load an X448 private key from its raw 56 byte encoding
2647* @param key the new object will be placed here
2648* @param privkey the raw private key
2649* @return 0 on success, a negative value on failure
2650*/
2651BOTAN_FFI_EXPORT(3, 4) int botan_privkey_load_x448(botan_privkey_t* key, const uint8_t privkey[56]);
2652
2653/**
2654* Load an X448 public key from its raw 56 byte encoding
2655* @param key the new object will be placed here
2656* @param pubkey the raw public key
2657* @return 0 on success, a negative value on failure
2658*/
2659BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_load_x448(botan_pubkey_t* key, const uint8_t pubkey[56]);
2660
2661/**
2662* Get the raw 56 byte encoding of an X448 private key
2663* @param key the X448 private key
2664* @param output set to the raw private key
2665* @return 0 on success, a negative value on failure
2666*/
2667BOTAN_FFI_DEPRECATED("Use botan_privkey_view_raw")
2668BOTAN_FFI_EXPORT(3, 4) int botan_privkey_x448_get_privkey(botan_privkey_t key, uint8_t output[56]);
2669
2670/**
2671* Get the raw 56 byte encoding of an X448 public key
2672* @param key the X448 public key
2673* @param pubkey set to the raw public key
2674* @return 0 on success, a negative value on failure
2675*/
2676BOTAN_FFI_DEPRECATED("Use botan_pubkey_view_raw")
2677BOTAN_FFI_EXPORT(3, 4) int botan_pubkey_x448_get_pubkey(botan_pubkey_t key, uint8_t pubkey[56]);
2678
2679/*
2680* Algorithm specific key operations: ML-DSA
2681*/
2682
2683/**
2684* Load an ML-DSA private key from its raw encoding
2685* @param key the new object will be placed here
2686* @param privkey the raw private key
2687* @param key_len length of privkey in bytes
2688* @param mldsa_mode the parameter set, eg "ML-DSA-6x5"
2689* @return 0 on success, a negative value on failure
2690*/
2691BOTAN_FFI_EXPORT(3, 6)
2692int botan_privkey_load_ml_dsa(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* mldsa_mode);
2693
2694/**
2695* Load an ML-DSA public key from its raw encoding
2696* @param key the new object will be placed here
2697* @param pubkey the raw public key
2698* @param key_len length of pubkey in bytes
2699* @param mldsa_mode the parameter set, eg "ML-DSA-6x5"
2700* @return 0 on success, a negative value on failure
2701*/
2702BOTAN_FFI_EXPORT(3, 6)
2703int botan_pubkey_load_ml_dsa(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* mldsa_mode);
2704
2705/*
2706* Algorithm specific key operations: Kyber R3
2707*
2708* Note that Kyber R3 support is somewhat deprecated and may be removed in a
2709* future major release. Using the final ML-KEM is highly recommended in any new
2710* system.
2711*/
2712
2713/**
2714* Load a Kyber private key from its raw encoding. The parameter set is
2715* inferred from the key length.
2716* @param key the new object will be placed here
2717* @param privkey the raw private key
2718* @param key_len length of privkey in bytes
2719* @return 0 on success, a negative value on failure
2720*/
2721BOTAN_FFI_DEPRECATED("Kyber R3 support is deprecated")
2722BOTAN_FFI_EXPORT(3, 1) int botan_privkey_load_kyber(botan_privkey_t* key, const uint8_t privkey[], size_t key_len);
2723
2724/**
2725* Load a Kyber public key from its raw encoding. The parameter set is
2726* inferred from the key length.
2727* @param key the new object will be placed here
2728* @param pubkey the raw public key
2729* @param key_len length of pubkey in bytes
2730* @return 0 on success, a negative value on failure
2731*/
2732BOTAN_FFI_DEPRECATED("Kyber R3 support is deprecated")
2733BOTAN_FFI_EXPORT(3, 1) int botan_pubkey_load_kyber(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len);
2734
2735/**
2736* View the raw encoding of a Kyber private key
2737* @param key the Kyber private key
2738* @param ctx an application context passed to the view function
2739* @param view the view callback which receives the encoding
2740* @return 0 on success, a negative value on failure
2741*/
2742BOTAN_FFI_DEPRECATED("Use generic botan_privkey_view_raw")
2743BOTAN_FFI_EXPORT(3, 1)
2745
2746/**
2747* View the raw encoding of a Kyber public key
2748* @param key the Kyber public key
2749* @param ctx an application context passed to the view function
2750* @param view the view callback which receives the encoding
2751* @return 0 on success, a negative value on failure
2752*/
2753BOTAN_FFI_DEPRECATED("Use generic botan_pubkey_view_raw")
2754BOTAN_FFI_EXPORT(3, 1)
2756
2757/*
2758* Algorithm specific key operation: FrodoKEM
2759*/
2760
2761/**
2762* Load a FrodoKEM private key from its raw encoding
2763* @param key the new object will be placed here
2764* @param privkey the raw private key
2765* @param key_len length of privkey in bytes
2766* @param frodo_mode the parameter set, eg "FrodoKEM-640-SHAKE"
2767* @return 0 on success, a negative value on failure
2768*/
2769BOTAN_FFI_EXPORT(3, 6)
2770int botan_privkey_load_frodokem(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* frodo_mode);
2771
2772/**
2773* Load a FrodoKEM public key from its raw encoding
2774* @param key the new object will be placed here
2775* @param pubkey the raw public key
2776* @param key_len length of pubkey in bytes
2777* @param frodo_mode the parameter set, eg "FrodoKEM-640-SHAKE"
2778* @return 0 on success, a negative value on failure
2779*/
2780BOTAN_FFI_EXPORT(3, 6)
2781int botan_pubkey_load_frodokem(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* frodo_mode);
2782
2783/*
2784* Algorithm specific key operation: Classic McEliece
2785*/
2786
2787/**
2788* Load a Classic McEliece private key from its raw encoding
2789* @param key the new object will be placed here
2790* @param privkey the raw private key
2791* @param key_len length of privkey in bytes
2792* @param cmce_mode the parameter set, eg "348864"
2793* @return 0 on success, a negative value on failure
2794*/
2795BOTAN_FFI_EXPORT(3, 6)
2797 const uint8_t privkey[],
2798 size_t key_len,
2799 const char* cmce_mode);
2800
2801/**
2802* Load a Classic McEliece public key from its raw encoding
2803* @param key the new object will be placed here
2804* @param pubkey the raw public key
2805* @param key_len length of pubkey in bytes
2806* @param cmce_mode the parameter set, eg "348864"
2807* @return 0 on success, a negative value on failure
2808*/
2809BOTAN_FFI_EXPORT(3, 6)
2811 const uint8_t pubkey[],
2812 size_t key_len,
2813 const char* cmce_mode);
2814
2815/*
2816* Algorithm specific key operations: ML-KEM
2817*/
2818
2819/**
2820* Load an ML-KEM private key from its raw encoding
2821* @param key the new object will be placed here
2822* @param privkey the raw private key
2823* @param key_len length of privkey in bytes
2824* @param mlkem_mode the parameter set, eg "ML-KEM-768"
2825* @return 0 on success, a negative value on failure
2826*/
2827BOTAN_FFI_EXPORT(3, 6)
2828int botan_privkey_load_ml_kem(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* mlkem_mode);
2829
2830/**
2831* Load an ML-KEM public key from its raw encoding
2832* @param key the new object will be placed here
2833* @param pubkey the raw public key
2834* @param key_len length of pubkey in bytes
2835* @param mlkem_mode the parameter set, eg "ML-KEM-768"
2836* @return 0 on success, a negative value on failure
2837*/
2838BOTAN_FFI_EXPORT(3, 6)
2839int botan_pubkey_load_ml_kem(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* mlkem_mode);
2840
2841/*
2842* Algorithm specific key operations: SLH-DSA
2843*/
2844
2845/**
2846* Load an SLH-DSA private key from its raw encoding
2847* @param key the new object will be placed here
2848* @param privkey the raw private key
2849* @param key_len length of privkey in bytes
2850* @param slhdsa_mode the parameter set, eg "SLH-DSA-SHA2-128s"
2851* @return 0 on success, a negative value on failure
2852*/
2853BOTAN_FFI_EXPORT(3, 6)
2854int botan_privkey_load_slh_dsa(botan_privkey_t* key, const uint8_t privkey[], size_t key_len, const char* slhdsa_mode);
2855
2856/**
2857* Load an SLH-DSA public key from its raw encoding
2858* @param key the new object will be placed here
2859* @param pubkey the raw public key
2860* @param key_len length of pubkey in bytes
2861* @param slhdsa_mode the parameter set, eg "SLH-DSA-SHA2-128s"
2862* @return 0 on success, a negative value on failure
2863*/
2864BOTAN_FFI_EXPORT(3, 6)
2865int botan_pubkey_load_slh_dsa(botan_pubkey_t* key, const uint8_t pubkey[], size_t key_len, const char* slhdsa_mode);
2866
2867/*
2868* Algorithm specific key operations: ECDSA and ECDH
2869*/
2870
2871/**
2872* Check if the group of this EC key was encoded using explicit curve parameters
2873* rather than a named curve OID
2874* @param key the EC public key to examine
2875* @return 1 if explicit encoding was used, 0 if not, negative on error
2876*/
2877BOTAN_FFI_EXPORT(3, 2)
2879
2880/**
2881* Load an ECDSA private key from its secret scalar
2882* @param key the new object will be placed here
2883* @param scalar the private scalar
2884* @param curve_name the name of the curve, eg "secp256r1"
2885* @return 0 on success, a negative value on failure
2886*/
2887BOTAN_FFI_EXPORT(2, 2)
2888int botan_privkey_load_ecdsa(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
2889
2890/**
2891* Load an ECDSA public key from the affine coordinates of the public point
2892* @param key the new object will be placed here
2893* @param public_x the x coordinate of the public point
2894* @param public_y the y coordinate of the public point
2895* @param curve_name the name of the curve, eg "secp256r1"
2896* @return 0 on success, a negative value on failure
2897*/
2898BOTAN_FFI_EXPORT(2, 2)
2899int botan_pubkey_load_ecdsa(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
2900
2901/**
2902* Load an ECDSA public key from the SEC1 encoding of the public point
2903* @param key the new object will be placed here
2904* @param sec1 the SEC1 compressed or uncompressed point encoding
2905* @param sec1_len length of sec1 in bytes
2906* @param curve_name the name of the curve, eg "secp256r1"
2907* @return 0 on success, a negative value on failure
2908*/
2909BOTAN_FFI_EXPORT(3, 10)
2910int botan_pubkey_load_ecdsa_sec1(botan_pubkey_t* key, const uint8_t sec1[], size_t sec1_len, const char* curve_name);
2911
2912/**
2913* Load an ECDH public key from the affine coordinates of the public point
2914* @param key the new object will be placed here
2915* @param public_x the x coordinate of the public point
2916* @param public_y the y coordinate of the public point
2917* @param curve_name the name of the curve, eg "secp256r1"
2918* @return 0 on success, a negative value on failure
2919*/
2920BOTAN_FFI_EXPORT(2, 2)
2921int botan_pubkey_load_ecdh(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
2922
2923/**
2924* Load an ECDH public key from the SEC1 encoding of the public point
2925* @param key the new object will be placed here
2926* @param sec1 the SEC1 compressed or uncompressed point encoding
2927* @param sec1_len length of sec1 in bytes
2928* @param curve_name the name of the curve, eg "secp256r1"
2929* @return 0 on success, a negative value on failure
2930*/
2931BOTAN_FFI_EXPORT(3, 10)
2932int botan_pubkey_load_ecdh_sec1(botan_pubkey_t* key, const uint8_t sec1[], size_t sec1_len, const char* curve_name);
2933
2934/**
2935* Load an ECDH private key from its secret scalar
2936* @param key the new object will be placed here
2937* @param scalar the private scalar
2938* @param curve_name the name of the curve, eg "secp256r1"
2939* @return 0 on success, a negative value on failure
2940*/
2941BOTAN_FFI_EXPORT(2, 2)
2942int botan_privkey_load_ecdh(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
2943
2944/**
2945* Load an SM2 public key from the affine coordinates of the public point
2946* @param key the new object will be placed here
2947* @param public_x the x coordinate of the public point
2948* @param public_y the y coordinate of the public point
2949* @param curve_name the name of the curve, typically "sm2p256v1"
2950* @return 0 on success, a negative value on failure
2951*/
2952BOTAN_FFI_EXPORT(2, 2)
2953int botan_pubkey_load_sm2(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
2954
2955/**
2956* Load an SM2 public key from the SEC1 encoding of the public point
2957* @param key the new object will be placed here
2958* @param sec1 the SEC1 compressed or uncompressed point encoding
2959* @param sec1_len length of sec1 in bytes
2960* @param curve_name the name of the curve, typically "sm2p256v1"
2961* @return 0 on success, a negative value on failure
2962*/
2963BOTAN_FFI_EXPORT(3, 10)
2964int botan_pubkey_load_sm2_sec1(botan_pubkey_t* key, const uint8_t sec1[], size_t sec1_len, const char* curve_name);
2965
2966/**
2967* Load an SM2 private key from its secret scalar
2968* @param key the new object will be placed here
2969* @param scalar the private scalar
2970* @param curve_name the name of the curve, typically "sm2p256v1"
2971* @return 0 on success, a negative value on failure
2972*/
2973BOTAN_FFI_EXPORT(2, 2)
2974int botan_privkey_load_sm2(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
2975
2976/**
2977* Load an SM2 encryption public key; identical to botan_pubkey_load_sm2
2978* @param key the new object will be placed here
2979* @param public_x the x coordinate of the public point
2980* @param public_y the y coordinate of the public point
2981* @param curve_name the name of the curve, typically "sm2p256v1"
2982* @return 0 on success, a negative value on failure
2983*/
2984BOTAN_FFI_DEPRECATED("Use botan_pubkey_load_sm2")
2985BOTAN_FFI_EXPORT(2, 2)
2986int botan_pubkey_load_sm2_enc(botan_pubkey_t* key, botan_mp_t public_x, botan_mp_t public_y, const char* curve_name);
2987
2988/**
2989* Load an SM2 encryption private key; identical to botan_privkey_load_sm2
2990* @param key the new object will be placed here
2991* @param scalar the private scalar
2992* @param curve_name the name of the curve, typically "sm2p256v1"
2993* @return 0 on success, a negative value on failure
2994*/
2995BOTAN_FFI_DEPRECATED("Use botan_privkey_load_sm2")
2996BOTAN_FFI_EXPORT(2, 2)
2997int botan_privkey_load_sm2_enc(botan_privkey_t* key, botan_mp_t scalar, const char* curve_name);
2998
2999/**
3000* Compute the SM2 ZA value, the hash of the user identity and public key which
3001* is prefixed to the message before signing
3002* @param out output buffer
3003* @param out_len on input the size of out, on output the number of bytes written or required
3004* @param ident the user identifier
3005* @param hash_algo the hash to use, typically "SM3"
3006* @param key the SM2 public key
3007* @return 0 on success, a negative value on failure
3008*/
3009BOTAN_FFI_EXPORT(2, 3)
3011 uint8_t out[], size_t* out_len, const char* ident, const char* hash_algo, botan_pubkey_t key);
3012
3013/**
3014* View the uncompressed public point associated with the key
3015*/
3016BOTAN_FFI_EXPORT(3, 0)
3018
3019/*
3020* Public Key Encryption
3021*/
3022/**
3023* Opaque type of a public key encryption operation
3024*/
3025typedef struct botan_pk_op_encrypt_struct* botan_pk_op_encrypt_t;
3026
3027/**
3028* Create a public key encryption operation
3029* @param op the new object will be placed here
3030* @param key the public key to encrypt to
3031* @param padding the padding/encoding method, eg "OAEP(SHA-256)"
3032* @param flags should be 0 in current API revision
3033* @return 0 on success, a negative value on failure
3034*/
3035BOTAN_FFI_EXPORT(2, 0)
3036int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t* op, botan_pubkey_t key, const char* padding, uint32_t flags);
3037
3038/**
3039* Frees all resources of the encryption operation object
3040* @param op the operation to destroy
3041* @return 0 if success, error if invalid object handle
3042*/
3044
3045/**
3046* Return the ciphertext length for a given plaintext length
3047* @param op the encryption operation
3048* @param ptext_len the plaintext length in bytes
3049* @param ctext_len set to the resulting ciphertext length in bytes
3050* @return 0 on success, a negative value on failure
3051*/
3052BOTAN_FFI_EXPORT(2, 8)
3053int botan_pk_op_encrypt_output_length(botan_pk_op_encrypt_t op, size_t ptext_len, size_t* ctext_len);
3054
3055/**
3056* Encrypt a message with a public key
3057* @param op the encryption operation
3058* @param rng a random number generator
3059* @param out output buffer
3060* @param out_len on input the size of out, on output the number of bytes written or required
3061* @param plaintext the message to encrypt
3062* @param plaintext_len length of plaintext in bytes
3063* @return 0 on success, a negative value on failure
3064*/
3065BOTAN_FFI_EXPORT(2, 0)
3067 botan_rng_t rng,
3068 uint8_t out[],
3069 size_t* out_len,
3070 const uint8_t plaintext[],
3071 size_t plaintext_len);
3072
3073/**
3074* Opaque type of a public key decryption operation
3075*/
3076typedef struct botan_pk_op_decrypt_struct* botan_pk_op_decrypt_t;
3077
3078/**
3079* Create a public key decryption operation
3080* @param op the new object will be placed here
3081* @param key the private key to decrypt with
3082* @param padding the padding/encoding method, eg "OAEP(SHA-256)"
3083* @param flags should be 0 in current API revision
3084* @return 0 on success, a negative value on failure
3085*/
3086BOTAN_FFI_EXPORT(2, 0)
3087int botan_pk_op_decrypt_create(botan_pk_op_decrypt_t* op, botan_privkey_t key, const char* padding, uint32_t flags);
3088
3089/**
3090* Frees all resources of the decryption operation object
3091* @param op the operation to destroy
3092* @return 0 if success, error if invalid object handle
3093*/
3095
3096/**
3097* Return an upper bound on the plaintext length for a given ciphertext length
3098* @param op the decryption operation
3099* @param ctext_len the ciphertext length in bytes
3100* @param ptext_len set to the maximum plaintext length in bytes
3101* @return 0 on success, a negative value on failure
3102*/
3103BOTAN_FFI_EXPORT(2, 8)
3104int botan_pk_op_decrypt_output_length(botan_pk_op_decrypt_t op, size_t ctext_len, size_t* ptext_len);
3105
3106/**
3107* Decrypt a message with a private key
3108* @param op the decryption operation
3109* @param out output buffer
3110* @param out_len on input the size of out, on output the number of bytes written or required
3111* @param ciphertext the message to decrypt
3112* @param ciphertext_len length of ciphertext in bytes
3113* @return 0 on success, a negative value on failure
3114*/
3115BOTAN_FFI_EXPORT(2, 0)
3117 botan_pk_op_decrypt_t op, uint8_t out[], size_t* out_len, const uint8_t ciphertext[], size_t ciphertext_len);
3118
3119/*
3120* Signature Generation
3121*/
3122
3123#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE 1
3124
3125/**
3126* Opaque type of a signature generation operation
3127*/
3128typedef struct botan_pk_op_sign_struct* botan_pk_op_sign_t;
3129
3130/**
3131* Create a signature generation operation
3132* @param op the new object will be placed here
3133* @param key the private key to sign with
3134* @param hash_and_padding the signature padding and hash, eg "PSS(SHA-256)"
3135* @param flags 0, or BOTAN_PUBKEY_DER_FORMAT_SIGNATURE to request DER encoded signatures
3136* @return 0 on success, a negative value on failure
3137*/
3138BOTAN_FFI_EXPORT(2, 0)
3139int botan_pk_op_sign_create(botan_pk_op_sign_t* op, botan_privkey_t key, const char* hash_and_padding, uint32_t flags);
3140
3141/**
3142* Frees all resources of the signature generation operation object
3143* @param op the operation to destroy
3144* @return 0 if success, error if invalid object handle
3145*/
3147
3148/**
3149* Return the length of the signatures this operation produces
3150* @param op the signature operation
3151* @param olen set to the signature length in bytes
3152* @return 0 on success, a negative value on failure
3153*/
3155
3156/**
3157* Add more data to the message being signed
3158* @param op the signature operation
3159* @param in input buffer
3160* @param in_len number of bytes to read from the input buffer
3161* @return 0 on success, a negative value on failure
3162*/
3163BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_sign_update(botan_pk_op_sign_t op, const uint8_t in[], size_t in_len);
3164
3165/**
3166* Produce a signature over the message, then reset for signing another message
3167* @param op the signature operation
3168* @param rng a random number generator
3169* @param sig output buffer
3170* @param sig_len on input the size of sig, on output the number of bytes written or required
3171* @return 0 on success, a negative value on failure
3172*/
3173BOTAN_FFI_EXPORT(2, 0)
3174int botan_pk_op_sign_finish(botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t* sig_len);
3175
3176/**
3177* Opaque type of a signature verification operation
3178*/
3179typedef struct botan_pk_op_verify_struct* botan_pk_op_verify_t;
3180
3181/**
3182* Create a signature verification operation
3183* @param op the new object will be placed here
3184* @param key the public key to verify with
3185* @param hash_and_padding the signature padding and hash, eg "PSS(SHA-256)"
3186* @param flags 0, or BOTAN_PUBKEY_DER_FORMAT_SIGNATURE if the signature is DER encoded
3187* @return 0 on success, a negative value on failure
3188*/
3189BOTAN_FFI_EXPORT(2, 0)
3191 botan_pubkey_t key,
3192 const char* hash_and_padding,
3193 uint32_t flags);
3194
3195/**
3196* Frees all resources of the signature verification operation object
3197* @param op the operation to destroy
3198* @return 0 if success, error if invalid object handle
3199*/
3201
3202/**
3203* Add more data to the message being verified
3204* @param op the verification operation
3205* @param in input buffer
3206* @param in_len number of bytes to read from the input buffer
3207* @return 0 on success, a negative value on failure
3208*/
3209BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_len);
3210
3211/**
3212* Check the signature over the message, then reset for verifying another message
3213* @param op the verification operation
3214* @param sig the signature to check
3215* @param sig_len length of sig in bytes
3216* @return 0 if the signature is valid, BOTAN_FFI_INVALID_VERIFIER if it is not,
3217* or some other negative value on error
3218*/
3219BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len);
3220
3221/**
3222* Opaque type of a key agreement operation
3223*/
3224typedef struct botan_pk_op_ka_struct* botan_pk_op_ka_t;
3225
3226/**
3227* Create a key agreement operation
3228* @param op the new object will be placed here
3229* @param key our private key
3230* @param kdf the KDF applied to the shared secret, or "Raw" for no KDF
3231* @param flags should be 0 in current API revision
3232* @return 0 on success, a negative value on failure
3233*/
3234BOTAN_FFI_EXPORT(2, 0)
3235int botan_pk_op_key_agreement_create(botan_pk_op_ka_t* op, botan_privkey_t key, const char* kdf, uint32_t flags);
3236
3237/**
3238* Frees all resources of the key agreement operation object
3239* @param op the operation to destroy
3240* @return 0 if success, error if invalid object handle
3241*/
3243
3244/**
3245* Export the public value of a key agreement private key, in the format
3246* expected by botan_pk_op_key_agreement
3247* @param key the key agreement private key
3248* @param out output buffer
3249* @param out_len on input the size of out, on output the number of bytes written or required
3250* @return 0 on success, a negative value on failure
3251*/
3252BOTAN_FFI_EXPORT(2, 0) int botan_pk_op_key_agreement_export_public(botan_privkey_t key, uint8_t out[], size_t* out_len);
3253
3254/**
3255* View the public value of a key agreement private key
3256* @param key the key agreement private key
3257* @param ctx an application context passed to the view function
3258* @param view the view callback which receives the encoding
3259* @return 0 on success, a negative value on failure
3260*/
3261BOTAN_FFI_EXPORT(3, 0)
3263
3264/**
3265* Return the length of the shared secret this operation produces
3266* @param op the key agreement operation
3267* @param out_len set to the output length in bytes
3268* @return 0 on success, a negative value on failure
3269*/
3271
3272/**
3273* Perform key agreement with the counterparty's public value
3274* @param op the key agreement operation
3275* @param out output buffer
3276* @param out_len on input the size of out, on output the number of bytes written or required
3277* @param other_key the counterparty's public value
3278* @param other_key_len length of other_key in bytes
3279* @param salt a salt passed to the KDF, may be NULL if salt_len is 0
3280* @param salt_len length of salt in bytes
3281* @return 0 on success, a negative value on failure
3282*/
3283BOTAN_FFI_EXPORT(2, 0)
3285 uint8_t out[],
3286 size_t* out_len,
3287 const uint8_t other_key[],
3288 size_t other_key_len,
3289 const uint8_t salt[],
3290 size_t salt_len);
3291
3292/**
3293* Opaque type of a key encapsulation (KEM encryption) operation
3294*/
3295typedef struct botan_pk_op_kem_encrypt_struct* botan_pk_op_kem_encrypt_t;
3296
3297/**
3298* Create a key encapsulation operation
3299* @param op the new object will be placed here
3300* @param key the public key to encapsulate to
3301* @param kdf the KDF applied to the shared secret, or "Raw" for no KDF
3302* @return 0 on success, a negative value on failure
3303*/
3304BOTAN_FFI_EXPORT(3, 0)
3306
3307/**
3308* Frees all resources of the key encapsulation operation object
3309* @param op the operation to destroy
3310* @return 0 if success, error if invalid object handle
3311*/
3313
3314/**
3315* Return the length of the shared key this operation will produce
3316* @param op the encapsulation operation
3317* @param desired_shared_key_length the requested shared key length in bytes
3318* @param output_shared_key_length set to the shared key length that will result
3319* @return 0 on success, a negative value on failure
3320*/
3321BOTAN_FFI_EXPORT(3, 0)
3323 size_t desired_shared_key_length,
3324 size_t* output_shared_key_length);
3325
3326/**
3327* Return the length of the encapsulated key this operation produces
3328* @param op the encapsulation operation
3329* @param output_encapsulated_key_length set to the encapsulated key length in bytes
3330* @return 0 on success, a negative value on failure
3331*/
3332BOTAN_FFI_EXPORT(3, 0)
3334 size_t* output_encapsulated_key_length);
3335
3336/**
3337* Generate a shared key along with the encapsulation of it for the counterparty
3338* @param op the encapsulation operation
3339* @param rng a random number generator
3340* @param salt a salt passed to the KDF, may be NULL if salt_len is 0
3341* @param salt_len length of salt in bytes
3342* @param desired_shared_key_len the requested shared key length in bytes
3343* @param shared_key output buffer for the shared key
3344* @param shared_key_len on input the size of shared_key, on output the number of bytes written
3345* @param encapsulated_key output buffer for the encapsulated key
3346* @param encapsulated_key_len on input the size of encapsulated_key, on output the number of bytes written
3347* @return 0 on success, a negative value on failure
3348*/
3349BOTAN_FFI_EXPORT(3, 0)
3351 botan_rng_t rng,
3352 const uint8_t salt[],
3353 size_t salt_len,
3354 size_t desired_shared_key_len,
3355 uint8_t shared_key[],
3356 size_t* shared_key_len,
3357 uint8_t encapsulated_key[],
3358 size_t* encapsulated_key_len);
3359
3360/**
3361* Opaque type of a key decapsulation (KEM decryption) operation
3362*/
3363typedef struct botan_pk_op_kem_decrypt_struct* botan_pk_op_kem_decrypt_t;
3364
3365/**
3366* Create a key decapsulation operation
3367* @param op the new object will be placed here
3368* @param key the private key to decapsulate with
3369* @param kdf the KDF applied to the shared secret, or "Raw" for no KDF
3370* @return 0 on success, a negative value on failure
3371*/
3372BOTAN_FFI_EXPORT(3, 0)
3374
3375/**
3376* Frees all resources of the key decapsulation operation object
3377* @param op the operation to destroy
3378* @return 0 if success, error if invalid object handle
3379*/
3381
3382/**
3383* Return the length of the shared key this operation will produce
3384* @param op the decapsulation operation
3385* @param desired_shared_key_length the requested shared key length in bytes
3386* @param output_shared_key_length set to the shared key length that will result
3387* @return 0 on success, a negative value on failure
3388*/
3389BOTAN_FFI_EXPORT(3, 0)
3391 size_t desired_shared_key_length,
3392 size_t* output_shared_key_length);
3393
3394/**
3395* Recover the shared key from an encapsulated key
3396* @param op the decapsulation operation
3397* @param salt a salt passed to the KDF, may be NULL if salt_len is 0
3398* @param salt_len length of salt in bytes
3399* @param encapsulated_key the encapsulated key from the counterparty
3400* @param encapsulated_key_len length of encapsulated_key in bytes
3401* @param desired_shared_key_len the requested shared key length in bytes
3402* @param shared_key output buffer for the shared key
3403* @param shared_key_len on input the size of shared_key, on output the number of bytes written
3404* @return 0 on success, a negative value on failure
3405*/
3406BOTAN_FFI_EXPORT(3, 0)
3408 const uint8_t salt[],
3409 size_t salt_len,
3410 const uint8_t encapsulated_key[],
3411 size_t encapsulated_key_len,
3412 size_t desired_shared_key_len,
3413 uint8_t shared_key[],
3414 size_t* shared_key_len);
3415
3416/**
3417* Signature Scheme Utility Functions
3418*/
3419
3420BOTAN_FFI_EXPORT(2, 0) int botan_pkcs_hash_id(const char* hash_name, uint8_t pkcs_id[], size_t* pkcs_id_len);
3421
3422/**
3423* Formerly encrypted a message using McEliece with an AEAD.
3424*
3425* Always returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED
3426*
3427* @param mce_key ignored
3428* @param rng ignored
3429* @param aead ignored
3430* @param pt ignored
3431* @param pt_len ignored
3432* @param ad ignored
3433* @param ad_len ignored
3434* @param ct ignored
3435* @param ct_len ignored
3436* @return BOTAN_FFI_ERROR_NOT_IMPLEMENTED
3437*/
3438BOTAN_FFI_DEPRECATED("No longer implemented")
3439BOTAN_FFI_EXPORT(2, 0)
3441 botan_rng_t rng,
3442 const char* aead,
3443 const uint8_t pt[],
3444 size_t pt_len,
3445 const uint8_t ad[],
3446 size_t ad_len,
3447 uint8_t ct[],
3448 size_t* ct_len);
3449
3450/**
3451* Formerly decrypted a message using McEliece with an AEAD.
3452*
3453* Always returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED
3454*
3455* @param mce_key ignored
3456* @param aead ignored
3457* @param ct ignored
3458* @param ct_len ignored
3459* @param ad ignored
3460* @param ad_len ignored
3461* @param pt ignored
3462* @param pt_len ignored
3463* @return BOTAN_FFI_ERROR_NOT_IMPLEMENTED
3464*/
3465BOTAN_FFI_DEPRECATED("No longer implemented")
3466BOTAN_FFI_EXPORT(2, 0)
3468 const char* aead,
3469 const uint8_t ct[],
3470 size_t ct_len,
3471 const uint8_t ad[],
3472 size_t ad_len,
3473 uint8_t pt[],
3474 size_t* pt_len);
3475
3476/*
3477* X.509 certificates
3478**************************/
3479
3480/**
3481* Opaque type of an X.509 certificate
3482*/
3483typedef struct botan_x509_cert_struct* botan_x509_cert_t;
3484
3485/**
3486 * Generic values that may be retrieved from X.509 certificates or CRLs via
3487 * the generic getter functions.
3488 *
3489 * When extending this list the existing entries must stay backward-compatible
3490 * to remain ABI compatible across versions. Therefore, new values must be added
3491 * to the end of this list.
3492 *
3493 * See:
3494 * * botan_x509_cert_view_binary_values()
3495 * * botan_x509_crl_view_binary_values()
3496 * * botan_x509_cert_view_string_values()
3497 */
3498typedef enum /* NOLINT(*-enum-size,*-use-enum-class) */ {
3499 BOTAN_X509_SERIAL_NUMBER = 0, /** singleton binary big-endian encoding */
3500 BOTAN_X509_SUBJECT_DN_BITS = 1, /** singleton binary DER encoding of the subject distinguished name */
3501 BOTAN_X509_ISSUER_DN_BITS = 2, /** singleton binary DER encoding of the issuer distinguished name */
3502 BOTAN_X509_SUBJECT_KEY_IDENTIFIER = 3, /** singleton binary encoding */
3503 BOTAN_X509_AUTHORITY_KEY_IDENTIFIER = 4, /** singleton binary encoding */
3504
3505 BOTAN_X509_PUBLIC_KEY_PKCS8_BITS = 200, /** singleton binary DER encoding of the PKCS#8 public key */
3506 BOTAN_X509_TBS_DATA_BITS = 201, /** singleton binary DER encoding */
3507 BOTAN_X509_SIGNATURE_SCHEME_BITS = 202, /** singleton binary DER encoding of the algorithm identifier */
3508 BOTAN_X509_SIGNATURE_BITS = 203, /** singleton binary signature bits */
3509
3510 BOTAN_X509_DER_ENCODING = 300, /** singleton binary DER encoding of the whole object */
3511 BOTAN_X509_PEM_ENCODING = 301, /** singleton string value PEM encoding of the whole object */
3512
3513 BOTAN_X509_CRL_DISTRIBUTION_URLS = 400, /** multi-value string of the CRL distribution points */
3514 BOTAN_X509_OCSP_RESPONDER_URLS = 401, /** multi-value string of the OCSP responder URLs */
3515 BOTAN_X509_CA_ISSUERS_URLS = 402, /** multi-value string of the CA issuer URLs */
3517
3518/**
3519* Load a certificate from a DER or PEM encoding
3520* @param cert_obj the new object will be placed here
3521* @param cert the encoding to load
3522* @param cert_len length of cert in bytes
3523* @return 0 on success, a negative value on failure
3524*/
3525BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_load(botan_x509_cert_t* cert_obj, const uint8_t cert[], size_t cert_len);
3526
3527/**
3528* Load a certificate from a file containing a DER or PEM encoding
3529* @param cert_obj the new object will be placed here
3530* @param filename path of the file to read
3531* @return 0 on success, a negative value on failure
3532*/
3533BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* filename);
3534
3535/**
3536* Frees all resources of the certificate object
3537* @param cert the certificate to destroy
3538* @return 0 if success, error if invalid object handle
3539*/
3541
3542/**
3543* Create a new handle referring to the same certificate
3544* @param new_cert the new object will be placed here
3545* @param cert the certificate to duplicate
3546* @return 0 on success, a negative value on failure
3547*/
3549
3550/**
3551 * Retrieve a specific binary value from an X.509 certificate.
3552 *
3553 * For multi-values @p index allows enumerating the available entries, until
3554 * BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an @p index
3555 * of value "0" is expected.
3556 *
3557 * @returns BOTAN_FFI_ERROR_NO_VALUE if the provided @p cert does not provide
3558 * the requested @p value_type at all or not in binary format.
3559 */
3560BOTAN_FFI_EXPORT(3, 11)
3562 botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view);
3563
3564/**
3565 * Count the binary values of the given type available in an X.509 certificate.
3566 *
3567 * @param cert the certificate to inspect
3568 * @param value_type the value type to count
3569 * @param count set to the number of available entries
3570 * @returns 0 on success, a negative value on failure
3571 */
3572BOTAN_FFI_EXPORT(3, 11)
3574
3575/**
3576 * Retrieve a specific string value from an X.509 certificate.
3577 *
3578 * For multi-values @p index allows enumerating the available entries, until
3579 * BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an @p index
3580 * of value "0" is expected.
3581 *
3582 * @returns BOTAN_FFI_ERROR_NO_VALUE if the provided @p cert does not provide
3583 * the requested @p value_type at all or not in string format.
3584 */
3585BOTAN_FFI_EXPORT(3, 11)
3587 botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view);
3588
3589/**
3590 * Count the string values of the given type available in an X.509 certificate.
3591 *
3592 * @param cert the certificate to inspect
3593 * @param value_type the value type to count
3594 * @param count set to the number of available entries
3595 * @returns 0 on success, a negative value on failure
3596 */
3597BOTAN_FFI_EXPORT(3, 11)
3599
3600/**
3601* Get the start of the validity period as a string
3602*
3603* Prefer botan_x509_cert_not_before
3604*
3605* @param cert the certificate to inspect
3606* @param out output buffer
3607* @param out_len on input the size of out, on output the number of bytes written or required
3608* @return 0 on success, a negative value on failure
3609*/
3610BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* out_len);
3611
3612/**
3613* Get the end of the validity period as a string
3614*
3615* Prefer botan_x509_cert_not_after
3616*
3617* @param cert the certificate to inspect
3618* @param out output buffer
3619* @param out_len on input the size of out, on output the number of bytes written or required
3620* @return 0 on success, a negative value on failure
3621*/
3622BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* out_len);
3623
3624/**
3625* Get the start of the validity period as seconds since the Unix epoch
3626* @param cert the certificate to inspect
3627* @param time_since_epoch set to the notBefore time
3628* @return 0 on success, a negative value on failure
3629*/
3630BOTAN_FFI_EXPORT(2, 8) int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t* time_since_epoch);
3631
3632/**
3633* Get the end of the validity period as seconds since the Unix epoch
3634* @param cert the certificate to inspect
3635* @param time_since_epoch set to the notAfter time
3636* @return 0 on success, a negative value on failure
3637*/
3638BOTAN_FFI_EXPORT(2, 8) int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t* time_since_epoch);
3639
3640/**
3641* Compute the fingerprint of the certificate, formatted as a hex string with
3642* colons between the bytes
3643*
3644* @param cert the certificate to inspect
3645* @param hash the name of the hash to use, eg "SHA-256"
3646* @param out output buffer
3647* @param out_len on input the size of out, on output the number of bytes written or required
3648* @return 0 on success, a negative value on failure
3649*
3650* TODO(Botan4) this should use char for the out param
3651*/
3652BOTAN_FFI_EXPORT(2, 0)
3653int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char* hash, uint8_t out[], size_t* out_len);
3654
3655/**
3656* Get the serial number of the certificate as a big-endian binary string
3657* @param cert the certificate to inspect
3658* @param out output buffer
3659* @param out_len on input the size of out, on output the number of bytes written or required
3660* @return 0 on success, a negative value on failure
3661*/
3662BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
3663
3664/**
3665* Get the serial number of the certificate as an integer
3666* @param cert the certificate to inspect
3667* @param serial_number the new object will be placed here
3668* @return 0 on success, a negative value on failure
3669*/
3671
3672/**
3673* Get the key identifier from the authority key identifier extension
3674* @param cert the certificate to inspect
3675* @param out output buffer
3676* @param out_len on input the size of out, on output the number of bytes written or required
3677* @return 0 on success, a negative value on failure
3678*/
3679BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
3680
3681/**
3682* Get the subject key identifier extension
3683* @param cert the certificate to inspect
3684* @param out output buffer
3685* @param out_len on input the size of out, on output the number of bytes written or required
3686* @return 0 on success, a negative value on failure
3687*/
3688BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
3689
3690/**
3691* Get the DER encoded SubjectPublicKeyInfo of the certificate
3692* @param cert the certificate to inspect
3693* @param out output buffer
3694* @param out_len on input the size of out, on output the number of bytes written or required
3695* @return 0 on success, a negative value on failure
3696*/
3697BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], size_t* out_len);
3698
3699/**
3700* View the DER encoded SubjectPublicKeyInfo of the certificate
3701* @param cert the certificate to inspect
3702* @param ctx an application context passed to the view function
3703* @param view the view callback which receives the encoding
3704* @return 0 on success, a negative value on failure
3705*/
3706BOTAN_FFI_EXPORT(3, 0)
3708
3709/**
3710* Get the public key of the certificate
3711* @param cert the certificate to inspect
3712* @param key the new object will be placed here
3713* @return 0 on success, a negative value on failure
3714*/
3716
3717/**
3718 * Returns 1 iff the cert is a CA certificate
3719 */
3721
3722/**
3723 * Retrieves the path length constraint from the certificate.
3724 * If no such constraint is present, BOTAN_FFI_ERROR_NO_VALUE is returned.
3725 */
3727
3728/**
3729 * Enumerates the names of the given @p key in the issuer DN. If @p index is
3730 * out of bounds, BOTAN_FFI_ERROR_BAD_PARAMETER is returned.
3731 *
3732 * TODO(Botan4) use BOTAN_FFI_ERROR_OUT_OF_RANGE instead of BAD_PARAMETER
3733 * TODO(Botan4) this should use char for the out param
3734 */
3735BOTAN_FFI_EXPORT(2, 0)
3737 botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len);
3738/**
3739 * Count the names of the given @p key present in the issuer DN.
3740 *
3741 * @param cert the certificate to inspect
3742 * @param key the DN component to count, eg "Name"
3743 * @param count set to the number of available entries
3744 * @return 0 on success, a negative value on failure
3745 */
3746BOTAN_FFI_EXPORT(3, 11) int botan_x509_cert_get_issuer_dn_count(botan_x509_cert_t cert, const char* key, size_t* count);
3747
3748/**
3749 * Enumerates the names of the given @p key in the subject DN. If @p index is
3750 * out of bounds, BOTAN_FFI_ERROR_BAD_PARAMETER is returned.
3751 *
3752 * TODO(Botan4) use BOTAN_FFI_ERROR_OUT_OF_RANGE instead of BAD_PARAMETER
3753 * TODO(Botan4) this should use char for the out param
3754 */
3755BOTAN_FFI_EXPORT(2, 0)
3757 botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len);
3758/**
3759 * Count the names of the given @p key present in the subject DN.
3760 *
3761 * @param cert the certificate to inspect
3762 * @param key the DN component to count, eg "Name"
3763 * @param count set to the number of available entries
3764 * @return 0 on success, a negative value on failure
3765 */
3766BOTAN_FFI_EXPORT(3, 11)
3767int botan_x509_cert_get_subject_dn_count(botan_x509_cert_t cert, const char* key, size_t* count);
3768
3769/**
3770* Format the certificate as a human readable string
3771* @param cert the certificate to format
3772* @param out output buffer
3773* @param out_len on input the size of out, on output the number of bytes written or required
3774* @return 0 on success, a negative value on failure
3775*/
3776BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_len);
3777
3778/**
3779* View the certificate formatted as a human readable string
3780* @param cert the certificate to format
3781* @param ctx an application context passed to the view function
3782* @param view the view callback which receives the string
3783* @return 0 on success, a negative value on failure
3784*/
3785BOTAN_FFI_EXPORT(3, 0)
3787
3788/**
3789* Key usage constraints from the key usage extension
3790*
3791* Must match values of Key_Constraints in pkix_enums.h
3792*/
3805
3806/**
3807* Check if the certificate allows the specified key usage. If no key usage
3808* extension is found in the certificate, this always returns success.
3809* @param cert the certificate to inspect
3810* @param key_usage one or more values from botan_x509_cert_key_constraints, ORed together
3811* @return 0 if the usage is allowed, 1 if it is not, negative on error
3812*/
3813BOTAN_FFI_EXPORT(2, 0) int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage);
3814
3815/**
3816* Check if the certificate allows the specified extended usage OID. See RFC 5280
3817* Section 4.2.1.12 for OIDs to query for this. If no extended key usage
3818* extension is found in the certificate, this always returns "not success".
3819*
3820* Typical OIDs to check for:
3821* * "PKIX.ServerAuth"
3822* * "PKIX.ClientAuth"
3823* * "PKIX.CodeSigning"
3824* * "PKIX.OCSPSigning"
3825*
3826* The @p oid parameter can be either a canonical OID string or identifiers as
3827* indicated in the examples above.
3828*/
3830
3831/**
3832* Check if the certificate allows the specified extended usage OID. See RFC 5280
3833* Section 4.2.1.12 for OIDs to query for this. If no extended key usage
3834* extension is found in the certificate, this always returns "not success".
3835*
3836* This is similar to botan_x509_cert_allowed_extended_usage_str but takes an OID
3837* object instead of a string describing the OID.
3838*/
3840
3841/**
3842* Opaque type of an X.509 GeneralName value
3843*/
3844typedef struct botan_x509_general_name_struct* botan_x509_general_name_t;
3845
3846/**
3847* GeneralName type identifiers as defined in RFC 5280 A.2 (GeneralName ::= CHOICE)
3848* Type identifiers that are omitted here are (currently) not supported. Also,
3849* there is currently no way to access OTHER_NAME values via the FFI.
3850*/
3859
3860/**
3861* Provides the contained type of the @p name and returns BOTAN_FFI_SUCCESS if
3862* that type is supported and may be retrieved via the view functions below.
3863* Otherwise BOTAN_FFI_ERROR_INVALID_OBJECT_STATE is returned.
3864*/
3866
3867/**
3868* Views the name as a string or returns BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
3869* if the contained GeneralName value cannot be represented as a string.
3870*
3871* The types BOTAN_X509_EMAIL_ADDRESS, BOTAN_X509_DNS_NAME, BOTAN_X509_URI,
3872* BOTAN_X509_IP_ADDRESS may be viewed as "string".
3873*/
3874BOTAN_FFI_EXPORT(3, 11)
3876 botan_view_ctx ctx,
3877 botan_view_str_fn view);
3878
3879/**
3880* Views the name as a bit string or returns BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
3881* if the contained GeneralName value cannot be represented as a binary string.
3882*
3883* The types BOTAN_X509_DIRECTORY_NAME, BOTAN_X509_IP_ADDRESS may be viewed as
3884* "binary".
3885*/
3886BOTAN_FFI_EXPORT(3, 11)
3888 botan_view_ctx ctx,
3889 botan_view_bin_fn view);
3890
3891/**
3892* Frees all resources of the GeneralName object
3893* @param alt_names the GeneralName to destroy
3894* @return 0 if success, error if invalid object handle
3895*/
3897
3898/**
3899* Extracts "permitted" name constraints from a given @p cert one-by-one.
3900* Returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given @p index is larger than the
3901* available number of "permitted" name constraints.
3902*/
3903BOTAN_FFI_EXPORT(3, 11)
3905 size_t index,
3906 botan_x509_general_name_t* constraint);
3907/**
3908* Count the "permitted" name constraints of a given @p cert.
3909* @param cert the certificate to inspect
3910* @param count set to the number of available entries
3911* @return 0 on success, a negative value on failure
3912*/
3914
3915/**
3916* Extracts "excluded" name constraints from a given @p cert one-by-one.
3917* Returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given @p index is larger than the
3918* available number of "excluded" name constraints.
3919*/
3920BOTAN_FFI_EXPORT(3, 11)
3922 size_t index,
3923 botan_x509_general_name_t* constraint);
3924/**
3925* Count the "excluded" name constraints of a given @p cert.
3926* @param cert the certificate to inspect
3927* @param count set to the number of available entries
3928* @return 0 on success, a negative value on failure
3929*/
3931
3932/**
3933* Provides access to all "subject alternative names", where each entry is
3934* returned as a botan_x509_general_name_t. If the given @p index is not
3935* within range of the available entries, BOTAN_FFI_ERROR_OUT_OF_RANGE is
3936* returned. If @p cert does not contain a SubjectAlternativeNames extension,
3937* BOTAN_FFI_ERROR_NO_VALUE is returned.
3938*/
3939BOTAN_FFI_EXPORT(3, 11)
3941 size_t index,
3942 botan_x509_general_name_t* alt_name);
3943/**
3944* Count the "subject alternative names" of a given @p cert.
3945* @param cert the certificate to inspect
3946* @param count set to the number of available entries
3947* @return 0 on success, a negative value on failure
3948*/
3950
3951/**
3952* Provides access to all "issuer alternative names", where each entry is
3953* returned as a botan_x509_general_name_t. If the given @p index is not
3954* within range of the available entries, BOTAN_FFI_ERROR_OUT_OF_RANGE is
3955* returned. If @p cert does not contain an IssuerAlternativeNames extension,
3956* BOTAN_FFI_ERROR_NO_VALUE is returned.
3957*/
3958BOTAN_FFI_EXPORT(3, 11)
3960/**
3961* Count the "issuer alternative names" of a given @p cert.
3962* @param cert the certificate to inspect
3963* @param count set to the number of available entries
3964* @return 0 on success, a negative value on failure
3965*/
3967
3968/**
3969* Check if the certificate matches the specified hostname via alternative name or CN match.
3970* RFC 5280 wildcards also supported.
3971*/
3972BOTAN_FFI_EXPORT(2, 5) int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname);
3973
3974/**
3975* Returns 0 if the validation was successful, 1 if validation failed,
3976* and negative on error. A status code with details is written to
3977* *validation_result
3978*
3979* Intermediates or trusted lists can be null
3980* Trusted path can be null
3981*/
3982BOTAN_FFI_EXPORT(2, 8)
3983int botan_x509_cert_verify(int* validation_result,
3984 botan_x509_cert_t cert,
3985 const botan_x509_cert_t* intermediates,
3986 size_t intermediates_len,
3987 const botan_x509_cert_t* trusted,
3988 size_t trusted_len,
3989 const char* trusted_path,
3990 size_t required_strength,
3991 const char* hostname,
3992 uint64_t reference_time);
3993
3994/**
3995* Returns a pointer to a static character string explaining the status code,
3996* or else NULL if unknown.
3997*/
3998BOTAN_FFI_EXPORT(2, 8) const char* botan_x509_cert_validation_status(int code);
3999
4000/*
4001* X.509 Extensions
4002*/
4003
4004/**
4005* Get info about the IP Address Blocks extension from RFC 3779
4006* @param cert the certificate to inspect
4007* @param v4_count is set to the number of v4 families contained in the extension
4008* @param v6_count is set to the number of v6 families
4009* @returns 0 on success, negative number on error
4010*
4011* If the extension is not present or an error occurs, `v4_count` and `v6_count` are not modified
4012*/
4013BOTAN_FFI_EXPORT(3, 13)
4014int botan_x509_ext_ip_addr_blocks_get_counts(botan_x509_cert_t cert, size_t* v4_count, size_t* v6_count);
4015
4016/**
4017* Get info about a specific family in the IP Address Blocks extension from RFC 3779
4018* @param cert the certificate to inspect
4019* @param ipv6 must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
4020* @param i is the (local) index for this family kind (the first v4 family is at i = 0, ipv6 = 0; the first v6 family is at i = 0, ipv6 = 1)
4021* @param has_safi will be set to 1 if the family has an associated SAFI
4022* @param safi will be set to the families' SAFI, if it has one, otherwise `safi` is not modified
4023* @param present is set to 1 if the family contains values (ranges), 0 if it is marked as "inherit"
4024* @param count is set to the number of values (ranges), if they were present, otherwise `count` is not modified
4025* @returns 0 on success, negative number on error
4026*
4027* The output parameters `has_safi`, `safi`, `present` and `count` may be modified even if the extension is not present or some other error occurs.
4028* In this event, the value of each output parameter after the call returns is undefined.
4029*/
4030BOTAN_FFI_EXPORT(3, 13)
4032 botan_x509_cert_t cert, int ipv6, size_t i, int* has_safi, uint8_t* safi, int* present, size_t* count);
4033
4034/**
4035* Get info about a specific range in the IP Address Blocks extension from RFC 3779
4036* @param cert the certificate to inspect
4037* @param ipv6 must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
4038* @param i is the (local) index of the family, see `botan_x509_ext_ip_addr_blocks_get_family`
4039* @param entry is the index of the range
4040* @param min_out is set to the lower address of the range
4041* @param max_out is set to the upper address of the range
4042* @param out_len is set to the length of the addresses (4 for IPv4, 16 for IPv6)
4043* @returns 0 on success, negative number on error
4044*
4045* The output parameters `min_out`, `max_out` and `out_len` may be modified even if the extension is not present or some other error occurs.
4046* In this event, the value of each output parameter after the call returns is undefined.
4047*/
4048BOTAN_FFI_EXPORT(3, 13)
4050 botan_x509_cert_t cert, int ipv6, size_t i, size_t entry, uint8_t min_out[], uint8_t max_out[], size_t* out_len);
4051
4052/**
4053* Get basic info about the AS Blocks extension from RFC 3779
4054* @param cert the certificate to inspect
4055* @param asnum must be set to 1 to get info about AS numbers, 0 for RDIs (the type)
4056* @param present is set to 1 if the extension contains entries for the type, 0 if it is marked as "inherit"
4057* @param count is set to number of entries for this type, if it was present, otherwise `count` is not modified
4058* @returns 0 on success, negative number on error
4059*
4060* If the extension is not present or an error occurs, `present` and `count` are not modified
4061*/
4062BOTAN_FFI_EXPORT(3, 13)
4063int botan_x509_ext_as_blocks_get_info(botan_x509_cert_t cert, int asnum, int* present, size_t* count);
4064
4065/**
4066* Get a specific entry in the AS Blocks extension from RFC 3779
4067* @param cert the certificate to inspect
4068* @param asnum Set to 1 to get info about AS numbers, 0 for RDIs (the type)
4069* @param i The index of the entry to get
4070* @param min is set to the min value of the range
4071* @param max is set to the max value of the range
4072* @returns 0 on success, negative number on error
4073*
4074* If the extension is not present or an error occurs, `min` and `max` are not modified
4075*/
4076BOTAN_FFI_EXPORT(3, 13)
4077int botan_x509_ext_as_blocks_get_entry_at(botan_x509_cert_t cert, int asnum, size_t i, uint32_t* min, uint32_t* max);
4078
4079/*
4080* X.509 CRL
4081**************************/
4082
4083/**
4084* Opaque type of an X.509 certificate revocation list
4085*/
4086typedef struct botan_x509_crl_struct* botan_x509_crl_t;
4087
4088/**
4089* Opaque type of a single entry within an X.509 certificate revocation list
4090*/
4091typedef struct botan_x509_crl_entry_struct* botan_x509_crl_entry_t;
4092
4093/**
4094* Load a CRL from a file containing a DER or PEM encoding
4095* @param crl_obj the new object will be placed here
4096* @param crl_path path of the file to read
4097* @return 0 on success, a negative value on failure
4098*/
4099BOTAN_FFI_EXPORT(2, 13) int botan_x509_crl_load_file(botan_x509_crl_t* crl_obj, const char* crl_path);
4100
4101/**
4102* Load a CRL from a DER or PEM encoding
4103* @param crl_obj the new object will be placed here
4104* @param crl_bits the encoding to load
4105* @param crl_bits_len length of crl_bits in bytes
4106* @return 0 on success, a negative value on failure
4107*/
4108BOTAN_FFI_EXPORT(2, 13)
4109int botan_x509_crl_load(botan_x509_crl_t* crl_obj, const uint8_t crl_bits[], size_t crl_bits_len);
4110
4111/**
4112* Get the thisUpdate field of the CRL as seconds since the Unix epoch
4113* @param crl the CRL to inspect
4114* @param time_since_epoch set to the thisUpdate time
4115* @return 0 on success, a negative value on failure
4116*/
4117BOTAN_FFI_EXPORT(3, 11) int botan_x509_crl_this_update(botan_x509_crl_t crl, uint64_t* time_since_epoch);
4118
4119/**
4120* Get the nextUpdate field of the CRL as seconds since the Unix epoch
4121* @param crl the CRL to inspect
4122* @param time_since_epoch set to the nextUpdate time
4123* @return 0 on success, or BOTAN_FFI_ERROR_NO_VALUE if the field is absent
4124*/
4125BOTAN_FFI_EXPORT(3, 11) int botan_x509_crl_next_update(botan_x509_crl_t crl, uint64_t* time_since_epoch);
4126
4127/**
4128* Create a new CRL
4129* @param crl_obj The newly created CRL
4130* @param rng a random number generator object
4131* @param ca_cert The CA Certificate the CRL belongs to
4132* @param ca_key The private key of that CA
4133* @param issue_time The time when the CRL becomes valid
4134* @param next_update The number of seconds after issue_time until the CRL expires
4135* @param hash_fn The hash function to use, may be null
4136* @param padding The padding to use, may be null
4137*/
4138BOTAN_FFI_EXPORT(3, 11)
4140 botan_rng_t rng,
4141 botan_x509_cert_t ca_cert,
4142 botan_privkey_t ca_key,
4143 uint64_t issue_time,
4144 uint32_t next_update,
4145 const char* hash_fn,
4146 const char* padding);
4147
4148/**
4149* Revocation reason codes for CRL entries, see RFC 5280 Section 5.3.1
4150*
4151* Must match values of CRL_Code in pkix_enums.h
4152*/
4165
4166/**
4167* Create a new CRL entry that marks @p cert as revoked
4168* @param entry The newly created CRL entry
4169* @param cert The certificate to mark as revoked
4170* @param reason_code The reason code for revocation
4171*/
4172BOTAN_FFI_EXPORT(3, 11)
4174
4175/**
4176* Update a CRL with new revoked entries. This does not modify the old crl, and instead creates a new one.
4177* @param crl_obj The newly created CRL
4178* @param last_crl The CRL to update
4179* @param rng a random number generator object
4180* @param ca_cert The CA Certificate the CRL belongs to
4181* @param ca_key The private key of that CA
4182* @param issue_time The time when the CRL becomes valid
4183* @param next_update The number of seconds after issue_time until the CRL expires
4184* @param new_entries The entries to add to the CRL
4185* @param new_entries_len The number of entries
4186* @param hash_fn The hash function to use, may be null
4187* @param padding The padding to use, may be null
4188*/
4189BOTAN_FFI_EXPORT(3, 11)
4191 botan_x509_crl_t last_crl,
4192 botan_rng_t rng,
4193 botan_x509_cert_t ca_cert,
4194 botan_privkey_t ca_key,
4195 uint64_t issue_time,
4196 uint32_t next_update,
4197 const botan_x509_crl_entry_t* new_entries,
4198 size_t new_entries_len,
4199 const char* hash_fn,
4200 const char* padding);
4201
4202/**
4203* Check the signature on a CRL against the issuer's public key
4204* @param crl the CRL to verify
4205* @param key the public key of the issuing CA
4206* @return 1 if the signature is valid, 0 if it is not, negative on error
4207*/
4209
4210/**
4211* Frees all resources of the CRL object
4212* @param crl the CRL to destroy
4213* @return 0 if success, error if invalid object handle
4214*/
4216
4217/**
4218 * Retrieve a specific binary value from an X.509 certificate revocation list.
4219 *
4220 * For multi-values @p index allows enumerating the available entries, until
4221 * BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an @p index
4222 * of value "0" is expected.
4223 *
4224 * @returns BOTAN_FFI_ERROR_NO_VALUE if the provided @p crl_obj does not provide
4225 * the requested @p value_type at all or not in binary format.
4226 */
4227BOTAN_FFI_EXPORT(3, 11)
4229 botan_x509_value_type value_type,
4230 size_t index,
4231 botan_view_ctx ctx,
4232 botan_view_bin_fn view);
4233
4234/**
4235 * Count the binary values of the given type available in a CRL.
4236 *
4237 * @param crl_obj the CRL to inspect
4238 * @param value_type the value type to count
4239 * @param count set to the number of available entries
4240 * @returns 0 on success, a negative value on failure
4241 */
4242BOTAN_FFI_EXPORT(3, 11)
4244
4245/**
4246 * Retrieve a specific string value from an X.509 certificate revocation list.
4247 *
4248 * For multi-values @p index allows enumerating the available entries, until
4249 * BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an @p index
4250 * of value "0" is expected.
4251 *
4252 * @returns BOTAN_FFI_ERROR_NO_VALUE if the provided @p crl_obj does not provide
4253 * the requested @p value_type at all or not in string format.
4254 */
4255BOTAN_FFI_EXPORT(3, 11)
4257 botan_x509_value_type value_type,
4258 size_t index,
4259 botan_view_ctx ctx,
4260 botan_view_str_fn view);
4261
4262/**
4263 * Count the string values of the given type available in a CRL.
4264 *
4265 * @param crl_obj the CRL to inspect
4266 * @param value_type the value type to count
4267 * @param count set to the number of available entries
4268 * @returns 0 on success, a negative value on failure
4269 */
4270BOTAN_FFI_EXPORT(3, 11)
4272
4273/**
4274 * Given a CRL and a certificate,
4275 * check if the certificate is revoked on that particular CRL
4276 */
4278
4279/**
4280* Allows iterating all entries of the CRL.
4281*
4282* @param crl the CRL whose entries should be listed
4283* @param index the index of the CRL entry to return
4284* @param entry an object handle containing the CRL entry data
4285*
4286* @returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given @p index is out of range of
4287* the CRL entry list.
4288*/
4289BOTAN_FFI_EXPORT(3, 11)
4291
4292/**
4293* Count the entries of the CRL.
4294*
4295* @param crl the CRL whose entries should be counted
4296* @param count set to the number of available entries
4297* @returns 0 on success, a negative value on failure
4298*/
4300
4301/**
4302* Return the revocation reason code for the given CRL @p entry.
4303* See `botan_x509_crl_reason_code` and RFC 5280 - 5.3.1 for possible reason codes.
4304*/
4305BOTAN_FFI_EXPORT(3, 11) int botan_x509_crl_entry_reason(botan_x509_crl_entry_t entry, int* reason_code);
4306
4307/**
4308* Return the revocation date for the given CRL @p entry as time since epoch
4309* in seconds.
4310*/
4311BOTAN_FFI_EXPORT(3, 11)
4312int botan_x509_crl_entry_revocation_date(botan_x509_crl_entry_t entry, uint64_t* time_since_epoch);
4313
4314/**
4315* Return the serial number associated with the given CRL @p entry.
4316*/
4317BOTAN_FFI_EXPORT(3, 11)
4319
4320/**
4321* View the serial number associated with the given CRL @p entry.
4322*/
4323BOTAN_FFI_EXPORT(3, 11)
4325
4326/**
4327* Frees all resources of the CRL entry object
4328* @param entry the CRL entry to destroy
4329* @return 0 if success, error if invalid object handle
4330*/
4332
4333/**
4334 * Different flavor of `botan_x509_cert_verify`, supports revocation lists.
4335 * CRLs are passed as an array, same as intermediates and trusted CAs
4336 */
4337BOTAN_FFI_EXPORT(2, 13)
4338int botan_x509_cert_verify_with_crl(int* validation_result,
4339 botan_x509_cert_t cert,
4340 const botan_x509_cert_t* intermediates,
4341 size_t intermediates_len,
4342 const botan_x509_cert_t* trusted,
4343 size_t trusted_len,
4344 const botan_x509_crl_t* crls,
4345 size_t crls_len,
4346 const char* trusted_path,
4347 size_t required_strength,
4348 const char* hostname,
4349 uint64_t reference_time);
4350
4351/**
4352 * Key wrapping as per RFC 3394
4353 */
4354BOTAN_FFI_DEPRECATED("Use botan_nist_kw_enc")
4355BOTAN_FFI_EXPORT(2, 2)
4356int botan_key_wrap3394(const uint8_t key[],
4357 size_t key_len,
4358 const uint8_t kek[],
4359 size_t kek_len,
4360 uint8_t wrapped_key[],
4361 size_t* wrapped_key_len);
4362
4363/**
4364 * Key unwrapping as per RFC 3394
4365 * @param wrapped_key the wrapped key to unwrap
4366 * @param wrapped_key_len length of wrapped_key in bytes
4367 * @param kek the key encryption key
4368 * @param kek_len length of kek in bytes
4369 * @param key output buffer for the unwrapped key
4370 * @param key_len on input the size of key, on output the number of bytes written or required
4371 * @return 0 on success, a negative value on failure
4372 */
4373BOTAN_FFI_DEPRECATED("Use botan_nist_kw_dec")
4374BOTAN_FFI_EXPORT(2, 2)
4375int botan_key_unwrap3394(const uint8_t wrapped_key[],
4376 size_t wrapped_key_len,
4377 const uint8_t kek[],
4378 size_t kek_len,
4379 uint8_t key[],
4380 size_t* key_len);
4381
4382/**
4383 * Key wrapping as per NIST SP 800-38F
4384 * @param cipher_algo the block cipher to use, eg "AES-256"
4385 * @param padded if non-zero use KWP (the padded variant), otherwise KW
4386 * @param key the key to wrap
4387 * @param key_len length of key in bytes
4388 * @param kek the key encryption key
4389 * @param kek_len length of kek in bytes
4390 * @param wrapped_key output buffer for the wrapped key
4391 * @param wrapped_key_len on input the size of wrapped_key, on output the number of bytes written or required
4392 * @return 0 on success, a negative value on failure
4393 */
4394BOTAN_FFI_EXPORT(3, 0)
4395int botan_nist_kw_enc(const char* cipher_algo,
4396 int padded,
4397 const uint8_t key[],
4398 size_t key_len,
4399 const uint8_t kek[],
4400 size_t kek_len,
4401 uint8_t wrapped_key[],
4402 size_t* wrapped_key_len);
4403
4404/**
4405 * Key unwrapping as per NIST SP 800-38F
4406 * @param cipher_algo the block cipher to use, eg "AES-256"
4407 * @param padded if non-zero use KWP (the padded variant), otherwise KW
4408 * @param wrapped_key the wrapped key to unwrap
4409 * @param wrapped_key_len length of wrapped_key in bytes
4410 * @param kek the key encryption key
4411 * @param kek_len length of kek in bytes
4412 * @param key output buffer for the unwrapped key
4413 * @param key_len on input the size of key, on output the number of bytes written or required
4414 * @return 0 on success, a negative value on failure
4415 */
4416BOTAN_FFI_EXPORT(3, 0)
4417int botan_nist_kw_dec(const char* cipher_algo,
4418 int padded,
4419 const uint8_t wrapped_key[],
4420 size_t wrapped_key_len,
4421 const uint8_t kek[],
4422 size_t kek_len,
4423 uint8_t key[],
4424 size_t* key_len);
4425
4426/**
4427* HOTP
4428*/
4429
4430typedef struct botan_hotp_struct* botan_hotp_t;
4431
4432/**
4433* Initialize a HOTP instance
4434*/
4435BOTAN_FFI_EXPORT(2, 8)
4436int botan_hotp_init(botan_hotp_t* hotp, const uint8_t key[], size_t key_len, const char* hash_algo, size_t digits);
4437
4438/**
4439* Destroy a HOTP instance
4440* @return 0 if success, error if invalid object handle
4441*/
4442BOTAN_FFI_EXPORT(2, 8)
4444
4445/**
4446* Generate a HOTP code for the provided counter
4447*/
4448BOTAN_FFI_EXPORT(2, 8)
4449int botan_hotp_generate(botan_hotp_t hotp, uint32_t* hotp_code, uint64_t hotp_counter);
4450
4451/**
4452* Verify a HOTP code
4453*/
4454BOTAN_FFI_EXPORT(2, 8)
4456 botan_hotp_t hotp, uint64_t* next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range);
4457
4458/**
4459* TOTP
4460*/
4461
4462typedef struct botan_totp_struct* botan_totp_t;
4463
4464/**
4465* Initialize a TOTP instance
4466*/
4467BOTAN_FFI_EXPORT(2, 8)
4468int botan_totp_init(
4469 botan_totp_t* totp, const uint8_t key[], size_t key_len, const char* hash_algo, size_t digits, size_t time_step);
4470
4471/**
4472* Destroy a TOTP instance
4473* @return 0 if success, error if invalid object handle
4474*/
4475BOTAN_FFI_EXPORT(2, 8)
4477
4478/**
4479* Generate a TOTP code for the provided timestamp
4480* @param totp the TOTP object
4481* @param totp_code the OTP code will be written here
4482* @param timestamp the current local timestamp
4483*/
4484BOTAN_FFI_EXPORT(2, 8)
4485int botan_totp_generate(botan_totp_t totp, uint32_t* totp_code, uint64_t timestamp);
4486
4487/**
4488* Verify a TOTP code
4489* @param totp the TOTP object
4490* @param totp_code the presented OTP
4491* @param timestamp the current local timestamp
4492* @param acceptable_clock_drift specifies the acceptable amount
4493* of clock drift (in terms of time steps) between the two hosts.
4494*/
4495BOTAN_FFI_EXPORT(2, 8)
4496int botan_totp_check(botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift);
4497
4498/**
4499* Format Preserving Encryption
4500*/
4501
4502typedef struct botan_fpe_struct* botan_fpe_t;
4503
4504#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE 1
4505
4506/**
4507* Initialize an FE1 format preserving encryption object, which encrypts
4508* integers in the range [0, n)
4509* @param fpe the new object will be placed here
4510* @param n the modulus defining the range of the permutation
4511* @param key the key
4512* @param key_len length of key in bytes
4513* @param rounds the number of Feistel rounds; at least 16 is recommended
4514* @param flags 0, or BOTAN_FPE_FLAG_FE1_COMPAT_MODE to match the encoding used
4515* by Botan versions prior to 2.5
4516* @return 0 on success, a negative value on failure
4517*/
4518BOTAN_FFI_EXPORT(2, 8)
4520 botan_fpe_t* fpe, botan_mp_t n, const uint8_t key[], size_t key_len, size_t rounds, uint32_t flags);
4521
4522/**
4523* Frees all resources of the FPE object
4524* @param fpe the FPE object to destroy
4525* @return 0 if success, error if invalid object handle
4526*/
4527BOTAN_FFI_EXPORT(2, 8)
4529
4530/**
4531* Encrypt an integer, replacing it with the result
4532* @param fpe the FPE object
4533* @param x the value to encrypt, modified in place; must be less than n
4534* @param tweak the tweak, may be NULL if tweak_len is 0
4535* @param tweak_len length of tweak in bytes
4536* @return 0 on success, a negative value on failure
4537*/
4538BOTAN_FFI_EXPORT(2, 8)
4539int botan_fpe_encrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len);
4540
4541/**
4542* Decrypt an integer, replacing it with the result
4543* @param fpe the FPE object
4544* @param x the value to decrypt, modified in place; must be less than n
4545* @param tweak the tweak, may be NULL if tweak_len is 0
4546* @param tweak_len length of tweak in bytes
4547* @return 0 on success, a negative value on failure
4548*/
4549BOTAN_FFI_EXPORT(2, 8)
4550int botan_fpe_decrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len);
4551
4552/**
4553* SRP-6 Server Session type
4554*/
4555typedef struct botan_srp6_server_session_struct* botan_srp6_server_session_t;
4556
4557/**
4558* Initialize an SRP-6 server session object
4559* @param srp6 SRP-6 server session object
4560*/
4561BOTAN_FFI_EXPORT(3, 0)
4563
4564/**
4565* Frees all resources of the SRP-6 server session object
4566* @param srp6 SRP-6 server session object
4567* @return 0 if success, error if invalid object handle
4568*/
4569BOTAN_FFI_EXPORT(3, 0)
4571
4572/**
4573* SRP-6 Server side step 1
4574* @param srp6 SRP-6 server session object
4575* @param verifier the verification value saved from client registration
4576* @param verifier_len SRP-6 verifier value length
4577* @param group_id the SRP group id
4578* @param hash_id the SRP hash in use
4579* @param rng_obj a random number generator object
4580* @param B_pub out buffer to store the SRP-6 B value
4581* @param B_pub_len SRP-6 B value length
4582* @return 0 on success, negative on failure
4583*/
4584BOTAN_FFI_EXPORT(3, 0)
4586 const uint8_t verifier[],
4587 size_t verifier_len,
4588 const char* group_id,
4589 const char* hash_id,
4590 botan_rng_t rng_obj,
4591 uint8_t B_pub[],
4592 size_t* B_pub_len);
4593
4594/**
4595* SRP-6 Server side step 2
4596* @param srp6 SRP-6 server session object
4597* @param A the client's value
4598* @param A_len the client's value length
4599* @param key out buffer to store the symmetric key value
4600* @param key_len symmetric key length
4601* @return 0 on success, negative on failure
4602*/
4603BOTAN_FFI_EXPORT(3, 0)
4605 botan_srp6_server_session_t srp6, const uint8_t A[], size_t A_len, uint8_t key[], size_t* key_len);
4606
4607/**
4608* Generate a new SRP-6 verifier
4609* @param identifier a username or other client identifier
4610* @param password the secret used to authenticate user
4611* @param salt a randomly chosen value, at least 128 bits long
4612* @param salt_len the length of salt
4613* @param group_id specifies the shared SRP group
4614* @param hash_id specifies a secure hash function
4615* @param verifier out buffer to store the SRP-6 verifier value
4616* @param verifier_len SRP-6 verifier value length
4617* @return 0 on success, negative on failure
4618*/
4619BOTAN_FFI_EXPORT(3, 0)
4620int botan_srp6_generate_verifier(const char* identifier,
4621 const char* password,
4622 const uint8_t salt[],
4623 size_t salt_len,
4624 const char* group_id,
4625 const char* hash_id,
4626 uint8_t verifier[],
4627 size_t* verifier_len);
4628
4629/**
4630* SRP6a Client side
4631* @param username the username we are attempting login for
4632* @param password the password we are attempting to use
4633* @param group_id specifies the shared SRP group
4634* @param hash_id specifies a secure hash function
4635* @param salt is the salt value sent by the server
4636* @param salt_len the length of salt
4637* @param B is the server's public value
4638* @param B_len is the server's public value length
4639* @param rng_obj is a random number generator object
4640* @param A out buffer to store the SRP-6 A value
4641* @param A_len SRP-6 A verifier value length
4642* @param K out buffer to store the symmetric value
4643* @param K_len symmetric key length
4644* @return 0 on success, negative on failure
4645*/
4646BOTAN_FFI_EXPORT(3, 0)
4647int botan_srp6_client_agree(const char* username,
4648 const char* password,
4649 const char* group_id,
4650 const char* hash_id,
4651 const uint8_t salt[],
4652 size_t salt_len,
4653 const uint8_t B[],
4654 size_t B_len,
4655 botan_rng_t rng_obj,
4656 uint8_t A[],
4657 size_t* A_len,
4658 uint8_t K[],
4659 size_t* K_len);
4660
4661/**
4662* Return the size, in bytes, of the prime associated with group_id
4663*/
4664BOTAN_FFI_EXPORT(3, 0)
4665int botan_srp6_group_size(const char* group_id, size_t* group_p_bytes);
4666
4667/**
4668* SPAKE2+ (RFC 9383) password authenticated key exchange
4669*
4670* All operations are relative to a set of system parameters, which select
4671* the elliptic curve group, the SPAKE2+ M/N group elements, and the hash
4672* function. The parameters are created either from the name of one of the
4673* RFC 9383 ciphersuites using HMAC key confirmation ("P256-SHA256",
4674* "P256-SHA512", "P384-SHA256", "P384-SHA512", or "P521-SHA512"), or for
4675* an application specific group using botan_spake2p_params_init_custom.
4676*
4677* The identity, salt, and context parameters may be null, if the
4678* corresponding length is zero.
4679*
4680* Since the lengths of the outputs vary with the system parameters, all
4681* outputs are produced using view callbacks. The expected lengths of the
4682* messages received from the peer can be obtained from
4683* botan_spake2p_params_share_size and
4684* botan_spake2p_params_confirmation_size.
4685*/
4686
4687/**
4688* SPAKE2+ system parameters
4689*/
4690typedef struct botan_spake2p_params_struct* botan_spake2p_params_t;
4691
4692/**
4693* Create SPAKE2+ system parameters from an RFC 9383 ciphersuite name
4694*
4695* Objects created from the system parameters hold their own copy, so the
4696* parameters may be destroyed at any time.
4697*
4698* @param params output parameter for the created system parameters
4699* @param ciphersuite the SPAKE2+ ciphersuite name
4700*/
4701BOTAN_FFI_EXPORT(3, 13)
4702int botan_spake2p_params_init(botan_spake2p_params_t* params, const char* ciphersuite);
4703
4704/**
4705* Create custom SPAKE2+ system parameters for an arbitrary group
4706*
4707* The M/N group elements are derived from the seed using hash to curve;
4708* returns BOTAN_FFI_ERROR_NOT_IMPLEMENTED if the group does not support
4709* hash to curve. Both peers must use the same group, seed, and hash.
4710*
4711* If the seed includes the identities of the participants, this
4712* additionally makes the scheme "quantum annoying", in that an attacker
4713* with a discrete logarithm oracle must compute a new discrete log for
4714* each (prover, verifier) pair they wish to attack.
4715*
4716* @param params output parameter for the created system parameters
4717* @param group the elliptic curve group to use
4718* @param seed the seed bytes used to derive the M/N group elements
4719* @param seed_len length of seed in bytes
4720* @param hash_fn the hash function to use (eg "SHA-256")
4721*/
4722BOTAN_FFI_EXPORT(3, 13)
4724 botan_spake2p_params_t* params, botan_ec_group_t group, const uint8_t seed[], size_t seed_len, const char* hash_fn);
4725
4726/**
4727* Frees all resources of SPAKE2+ system parameters
4728*/
4729BOTAN_FFI_EXPORT(3, 13)
4731
4732/**
4733* Return the size in bytes of a SPAKE2+ key share (shareP or shareV)
4734*
4735* @param params the SPAKE2+ system parameters
4736* @param share_size output parameter for the key share size
4737*/
4738BOTAN_FFI_EXPORT(3, 13)
4739int botan_spake2p_params_share_size(botan_spake2p_params_t params, size_t* share_size);
4740
4741/**
4742* Return the size in bytes of a SPAKE2+ key confirmation message (confirmP or confirmV)
4743*
4744* @param params the SPAKE2+ system parameters
4745* @param confirmation_size output parameter for the key confirmation size
4746*/
4747BOTAN_FFI_EXPORT(3, 13)
4748int botan_spake2p_params_confirmation_size(botan_spake2p_params_t params, size_t* confirmation_size);
4749
4750/**
4751* Derive a SPAKE2+ prover secret (w0 and w1) from a password, using Argon2id
4752*
4753* The view callback is invoked with the serialized prover secret, which is
4754* password equivalent and must be protected accordingly. It is used with
4755* botan_spake2p_registration_record and botan_spake2p_prover_init.
4756*
4757* @param params the SPAKE2+ system parameters
4758* @param password the (null terminated) password
4759* @param prover_id the identity of the prover
4760* @param prover_id_len length of prover_id in bytes
4761* @param verifier_id the identity of the verifier
4762* @param verifier_id_len length of verifier_id in bytes
4763* @param salt a salt value, ideally random and stored with the registration record
4764* @param salt_len length of salt in bytes
4765* @param ctx a context pointer passed to the view callback
4766* @param view a view callback which is invoked with the serialized prover secret
4767*/
4768BOTAN_FFI_EXPORT(3, 13)
4770 const char* password,
4771 const uint8_t prover_id[],
4772 size_t prover_id_len,
4773 const uint8_t verifier_id[],
4774 size_t verifier_id_len,
4775 const uint8_t salt[],
4776 size_t salt_len,
4777 botan_view_ctx ctx,
4778 botan_view_bin_fn view);
4779
4780/**
4781* Compute a SPAKE2+ registration record (w0 and L) from a prover secret
4782*
4783* The registration record is provided to the verifier during registration.
4784* While it does not allow directly impersonating the prover, it does allow
4785* offline password guessing attacks, so it should be protected.
4786*
4787* @param params the SPAKE2+ system parameters
4788* @param rng a random number generator
4789* @param secret the serialized prover secret
4790* @param secret_len length of secret in bytes
4791* @param ctx a context pointer passed to the view callback
4792* @param view a view callback which is invoked with the serialized registration record
4793*/
4794BOTAN_FFI_EXPORT(3, 13)
4796 botan_rng_t rng,
4797 const uint8_t secret[],
4798 size_t secret_len,
4799 botan_view_ctx ctx,
4800 botan_view_bin_fn view);
4801
4802/**
4803* SPAKE2+ prover
4804*/
4805typedef struct botan_spake2p_prover_struct* botan_spake2p_prover_t;
4806
4807/**
4808* SPAKE2+ verifier
4809*/
4810typedef struct botan_spake2p_verifier_struct* botan_spake2p_verifier_t;
4811
4812/**
4813* Initialize a SPAKE2+ prover
4814*
4815* The identities and context must be agreed upon by both parties; the
4816* identities must additionally match the values used when deriving the
4817* prover secret.
4818*
4819* @param prover output parameter for the created prover object
4820* @param params the SPAKE2+ system parameters
4821* @param secret the serialized prover secret
4822* @param secret_len length of secret in bytes
4823* @param prover_id the identity of the prover
4824* @param prover_id_len length of prover_id in bytes
4825* @param verifier_id the identity of the verifier
4826* @param verifier_id_len length of verifier_id in bytes
4827* @param context an application specific context string
4828* @param context_len length of context in bytes
4829*/
4830BOTAN_FFI_EXPORT(3, 13)
4833 const uint8_t secret[],
4834 size_t secret_len,
4835 const uint8_t prover_id[],
4836 size_t prover_id_len,
4837 const uint8_t verifier_id[],
4838 size_t verifier_id_len,
4839 const uint8_t context[],
4840 size_t context_len);
4841
4842/**
4843* Frees all resources of a SPAKE2+ prover
4844*/
4845BOTAN_FFI_EXPORT(3, 13)
4847
4848/**
4849* Generate the prover's key share (shareP), which is sent to the verifier
4850*
4851* This can be called only once per prover object.
4852*
4853* @param prover the prover object
4854* @param rng a random number generator
4855* @param ctx a context pointer passed to the view callback
4856* @param view a view callback which is invoked with the key share
4857*/
4858BOTAN_FFI_EXPORT(3, 13)
4860 botan_rng_t rng,
4861 botan_view_ctx ctx,
4862 botan_view_bin_fn view);
4863
4864/**
4865* Consume the verifier's response (shareV followed by confirmV) and produce
4866* the prover's key confirmation (confirmP), which is sent to the verifier.
4867*
4868* Returns BOTAN_FFI_ERROR_BAD_MAC if the verifier's key confirmation is
4869* wrong, typically meaning the passwords do not match.
4870*
4871* @param prover the prover object
4872* @param rng a random number generator
4873* @param peer_message the verifier's response
4874* @param peer_message_len length of peer_message in bytes
4875* @param ctx a context pointer passed to the view callback
4876* @param view a view callback which is invoked with the prover's key confirmation
4877*/
4878BOTAN_FFI_EXPORT(3, 13)
4880 botan_rng_t rng,
4881 const uint8_t peer_message[],
4882 size_t peer_message_len,
4883 botan_view_ctx ctx,
4884 botan_view_bin_fn view);
4885
4886/**
4887* Return the prover's shared secret (K_shared)
4888*
4889* This may be called only after botan_spake2p_prover_process_message
4890* has succeeded.
4891*
4892* @param prover the prover object
4893* @param ctx a context pointer passed to the view callback
4894* @param view a view callback which is invoked with the shared secret
4895*/
4896BOTAN_FFI_EXPORT(3, 13)
4898
4899/**
4900* Initialize a SPAKE2+ verifier
4901*
4902* The identities and context must be agreed upon by both parties; the
4903* identities must additionally match the values used when deriving the
4904* prover secret.
4905*
4906* @param verifier output parameter for the created verifier object
4907* @param params the SPAKE2+ system parameters
4908* @param record the serialized registration record
4909* @param record_len length of record in bytes
4910* @param prover_id the identity of the prover
4911* @param prover_id_len length of prover_id in bytes
4912* @param verifier_id the identity of the verifier
4913* @param verifier_id_len length of verifier_id in bytes
4914* @param context an application specific context string
4915* @param context_len length of context in bytes
4916*/
4917BOTAN_FFI_EXPORT(3, 13)
4920 const uint8_t record[],
4921 size_t record_len,
4922 const uint8_t prover_id[],
4923 size_t prover_id_len,
4924 const uint8_t verifier_id[],
4925 size_t verifier_id_len,
4926 const uint8_t context[],
4927 size_t context_len);
4928
4929/**
4930* Frees all resources of a SPAKE2+ verifier
4931*/
4932BOTAN_FFI_EXPORT(3, 13)
4934
4935/**
4936* Consume the prover's key share (shareP) and produce the verifier's
4937* response (shareV followed by confirmV), which is sent to the prover.
4938*
4939* This can be called only once per verifier object.
4940*
4941* @param verifier the verifier object
4942* @param rng a random number generator
4943* @param peer_message the prover's key share
4944* @param peer_message_len length of peer_message in bytes
4945* @param ctx a context pointer passed to the view callback
4946* @param view a view callback which is invoked with the verifier's response
4947*/
4948BOTAN_FFI_EXPORT(3, 13)
4950 botan_rng_t rng,
4951 const uint8_t peer_message[],
4952 size_t peer_message_len,
4953 botan_view_ctx ctx,
4954 botan_view_bin_fn view);
4955
4956/**
4957* Check the prover's key confirmation (confirmP)
4958*
4959* Returns BOTAN_FFI_ERROR_BAD_MAC if the confirmation is wrong, meaning
4960* the prover does not know the password.
4961*
4962* @param verifier the verifier object
4963* @param confirmation the prover's key confirmation
4964* @param confirmation_len length of confirmation in bytes
4965*/
4966BOTAN_FFI_EXPORT(3, 13)
4968 const uint8_t confirmation[],
4969 size_t confirmation_len);
4970
4971/**
4972* Skip checking the prover's key confirmation (confirmP)
4973*
4974* This can be called after botan_spake2p_verifier_process_message, in
4975* place of botan_spake2p_verifier_verify_confirmation, to allow extracting
4976* the shared secret without having checked the prover's key confirmation.
4977*
4978* Warning: after calling this, nothing is known about the peer; only a
4979* prover which knows the password can compute the same shared secret, but
4980* no evidence of this has been received. It is intended solely for
4981* protocols which embed SPAKE2+ and perform the prover's key confirmation
4982* themselves, for example the proposed TLS PAKE extension, where the TLS
4983* handshake takes the place of confirmP. Anywhere else, use
4984* botan_spake2p_verifier_verify_confirmation.
4985*
4986* @param verifier the verifier object
4987*/
4988BOTAN_FFI_EXPORT(3, 13)
4990
4991/**
4992* Return the verifier's shared secret (K_shared)
4993*
4994* This may be called only after botan_spake2p_verifier_verify_confirmation
4995* has succeeded, or after botan_spake2p_verifier_skip_confirmation.
4996*
4997* @param verifier the verifier object
4998* @param ctx a context pointer passed to the view callback
4999* @param view a view callback which is invoked with the shared secret
5000*/
5001BOTAN_FFI_EXPORT(3, 13)
5003
5004/**
5005 * ZFEC
5006 */
5007
5008/**
5009 * Encode some bytes with certain ZFEC parameters.
5010 *
5011 * @param K the number of shares needed for recovery
5012 * @param N the number of shares generated
5013 * @param input the data to FEC
5014 * @param size the length in bytes of input, which must be a multiple of K
5015 *
5016 * @param outputs An out parameter pointing to a fully allocated array of size
5017 * [N][size / K]. For all n in range, an encoded block will be
5018 * written to the memory starting at outputs[n][0].
5019 *
5020 * @return 0 on success, negative on failure
5021 */
5022BOTAN_FFI_EXPORT(3, 0)
5023int botan_zfec_encode(size_t K, size_t N, const uint8_t* input, size_t size, uint8_t** outputs);
5024
5025/**
5026 * Decode some previously encoded shares using certain ZFEC parameters.
5027 *
5028 * @param K the number of shares needed for recovery
5029 * @param N the total number of shares
5030 *
5031 * @param indexes The index into the encoder's outputs for the corresponding
5032 * element of the inputs array. Must be of length K.
5033 *
5034 * @param inputs K previously encoded shares to decode
5035 * @param shareSize the length in bytes of each input
5036 *
5037 * @param outputs An out parameter pointing to a fully allocated array of size
5038 * [K][shareSize]. For all k in range, a decoded block will
5039 * written to the memory starting at outputs[k][0].
5040 *
5041 * @return 0 on success, negative on failure
5042 */
5043BOTAN_FFI_EXPORT(3, 0)
5045 size_t K, size_t N, const size_t* indexes, uint8_t* const* inputs, size_t shareSize, uint8_t** outputs);
5046
5047/**
5048* TPM2 context
5049*/
5050typedef struct botan_tpm2_ctx_struct* botan_tpm2_ctx_t;
5051
5052/**
5053* TPM2 session
5054*/
5055typedef struct botan_tpm2_session_struct* botan_tpm2_session_t;
5056
5057/**
5058* TPM2 crypto backend state object
5059*/
5060typedef struct botan_tpm2_crypto_backend_state_struct* botan_tpm2_crypto_backend_state_t;
5061
5062struct ESYS_CONTEXT;
5063
5064/**
5065* Checks if Botan's TSS2 crypto backend can be used in this build
5066* @returns 1 if the crypto backend can be enabled
5067*/
5068BOTAN_FFI_EXPORT(3, 6)
5070
5071/**
5072* Initialize a TPM2 context
5073* @param ctx_out output TPM2 context
5074* @param tcti_nameconf TCTI config (may be nullptr)
5075* @return 0 on success
5076*/
5077BOTAN_FFI_EXPORT(3, 6) int botan_tpm2_ctx_init(botan_tpm2_ctx_t* ctx_out, const char* tcti_nameconf);
5078
5079/**
5080* Initialize a TPM2 context
5081* @param ctx_out output TPM2 context
5082* @param tcti_name TCTI name (may be nullptr)
5083* @param tcti_conf TCTI config (may be nullptr)
5084* @return 0 on success
5085*/
5086BOTAN_FFI_EXPORT(3, 6)
5087int botan_tpm2_ctx_init_ex(botan_tpm2_ctx_t* ctx_out, const char* tcti_name, const char* tcti_conf);
5088
5089/**
5090* Wrap an existing ESYS_CONTEXT for use in Botan.
5091* Note that destroying the created botan_tpm2_ctx_t won't
5092* finalize @p esys_ctx
5093* @param ctx_out output TPM2 context
5094* @param esys_ctx ESYS_CONTEXT to wrap
5095* @return 0 on success
5096*/
5097BOTAN_FFI_EXPORT(3, 7)
5098int botan_tpm2_ctx_from_esys(botan_tpm2_ctx_t* ctx_out, struct ESYS_CONTEXT* esys_ctx);
5099
5100/**
5101* Enable Botan's TSS2 crypto backend that replaces the cryptographic functions
5102* required for the communication with the TPM with implementations provided
5103* by Botan instead of using TSS' defaults OpenSSL or mbedTLS.
5104* Note that the provided @p rng should not be dependent on the TPM and the
5105* caller must ensure that it remains usable for the lifetime of the @p ctx.
5106* @param ctx TPM2 context
5107* @param rng random number generator to be used by the crypto backend
5108*/
5109BOTAN_FFI_EXPORT(3, 6)
5111
5112/**
5113* Frees all resources of a TPM2 context
5114* @param ctx TPM2 context
5115* @return 0 on success
5116*/
5118
5119/**
5120* Use this if you just need Botan's crypto backend but do not want to wrap any
5121* other ESYS functionality using Botan's TPM2 wrapper.
5122* A Crypto Backend State is created that the user needs to keep alive for as
5123* long as the crypto backend is used and needs to be destroyed after.
5124* Note that the provided @p rng should not be dependent on the TPM and the
5125* caller must ensure that it remains usable for the lifetime of the @p esys_ctx.
5126* @param cbs_out To be created Crypto Backend State
5127* @param esys_ctx TPM2 context
5128* @param rng random number generator to be used by the crypto backend
5129*/
5130BOTAN_FFI_EXPORT(3, 7)
5132 struct ESYS_CONTEXT* esys_ctx,
5133 botan_rng_t rng);
5134
5135/**
5136* Frees all resources of a TPM2 Crypto Callback State
5137* Note that this does not attempt to de-register the crypto backend,
5138* it just frees the resource pointed to by @p cbs. Use the ESAPI function
5139* ``Esys_SetCryptoCallbacks(ctx, nullptr)`` to deregister manually.
5140* @param cbs TPM2 Crypto Callback State
5141* @return 0 on success
5142*/
5144
5145/**
5146* Initialize a random number generator object via TPM2
5147* @param rng_out rng object to create
5148* @param ctx TPM2 context
5149* @param s1 the first session to use (optional, may be nullptr)
5150* @param s2 the second session to use (optional, may be nullptr)
5151* @param s3 the third session to use (optional, may be nullptr)
5152*/
5153BOTAN_FFI_EXPORT(3, 6)
5154int botan_tpm2_rng_init(botan_rng_t* rng_out,
5155 botan_tpm2_ctx_t ctx,
5159
5160/**
5161* Create an unauthenticated session for use with TPM2
5162* @param session_out the session object to create
5163* @param ctx TPM2 context
5164*/
5165BOTAN_FFI_EXPORT(3, 6)
5167
5168/**
5169* Create an unauthenticated session for use with TPM2
5170* @param session the session object to destroy
5171*/
5172BOTAN_FFI_EXPORT(3, 6)
5174
5175/* NOLINTEND(*-macro-usage,*-misplaced-const) */
5176
5177#ifdef __cplusplus
5178}
5179#endif
5180
5181#endif
uint32_t botan_version_datestamp()
Definition ffi.cpp:323
int botan_same_mem(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:336
const char * botan_version_string()
Definition ffi.cpp:307
int botan_base64_decode(const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition ffi.cpp:379
uint32_t botan_version_patch()
Definition ffi.cpp:319
int botan_base64_encode(const uint8_t *in, size_t len, char *out, size_t *out_len)
Definition ffi.cpp:369
int botan_scrub_mem(void *mem, size_t bytes)
Definition ffi.cpp:340
int botan_hex_encode(const uint8_t *in, size_t len, char *out, uint32_t flags)
Definition ffi.cpp:348
uint32_t botan_version_major()
Definition ffi.cpp:311
uint32_t botan_ffi_api_version()
Definition ffi.cpp:223
int botan_ffi_supports_api(uint32_t api_version)
Definition ffi.cpp:227
const char * botan_error_description(int err)
Definition ffi.cpp:146
uint32_t botan_version_minor()
Definition ffi.cpp:315
int botan_constant_time_compare(const uint8_t *x, const uint8_t *y, size_t len)
Definition ffi.cpp:327
int botan_hex_decode(const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len)
Definition ffi.cpp:359
const char * botan_error_last_exception_message()
Definition ffi.cpp:142
int botan_mp_lshift(botan_mp_t out, botan_mp_t in, size_t shift)
Definition ffi_mp.cpp:252
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:98
int botan_block_cipher_init(botan_block_cipher_t *bc, const char *cipher_name)
Definition ffi_block.cpp:19
int botan_pk_op_sign_finish(botan_pk_op_sign_t op, botan_rng_t rng, uint8_t sig[], size_t *sig_len)
int botan_spake2p_params_init(botan_spake2p_params_t *params, const char *ciphersuite)
int botan_x509_cert_get_subject_dn_count(botan_x509_cert_t cert, const char *key, size_t *count)
Definition ffi_cert.cpp:515
int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert)
int botan_mp_is_prime(botan_mp_t n, botan_rng_t rng, size_t test_prob)
Definition ffi_mp.cpp:286
int botan_rng_reseed_from_rng(botan_rng_t rng, botan_rng_t source_rng, size_t bits)
Definition ffi_rng.cpp:196
int botan_x509_crl_destroy(botan_x509_crl_t crl)
int botan_ec_point_add(botan_ec_point_t *result, botan_ec_point_t x, botan_ec_point_t y)
Definition ffi_ec.cpp:346
int botan_privkey_load_x448(botan_privkey_t *key, const uint8_t privkey[56])
int botan_ec_group_get_g_x(botan_mp_t *g_x, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:175
int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:211
int botan_mp_set_from_int(botan_mp_t mp, int initial_value)
Definition ffi_mp.cpp:39
int botan_mp_to_bin(botan_mp_t mp, uint8_t vec[])
Definition ffi_mp.cpp:136
int botan_x509_cert_destroy(botan_x509_cert_t cert)
Definition ffi_cert.cpp:583
int botan_pubkey_load_ml_dsa(botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mldsa_mode)
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:177
int botan_pk_op_sign_output_length(botan_pk_op_sign_t op, size_t *olen)
struct botan_pk_op_kem_decrypt_struct * botan_pk_op_kem_decrypt_t
Definition ffi.h:3363
int botan_x509_ext_ip_addr_blocks_get_address(botan_x509_cert_t cert, int ipv6, size_t i, size_t entry, uint8_t min_out[], uint8_t max_out[], size_t *out_len)
int botan_x509_cert_view_string_values(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:352
int botan_x509_crl_entry_serial_number(botan_x509_crl_entry_t entry, botan_mp_t *serial_number)
int botan_rng_init_drbg(botan_rng_t *rng_out, const char *drbg_name, const uint8_t *seed, size_t seed_len)
Definition ffi_rng.cpp:200
struct botan_spake2p_prover_struct * botan_spake2p_prover_t
Definition ffi.h:4805
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:178
int botan_xof_clear(botan_xof_t xof)
Definition ffi_xof.cpp:65
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:277
int botan_pk_op_decrypt(botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, const uint8_t ciphertext[], size_t ciphertext_len)
int botan_srp6_server_session_step1(botan_srp6_server_session_t srp6, const uint8_t verifier[], size_t verifier_len, const char *group_id, const char *hash_id, botan_rng_t rng_obj, uint8_t B_pub[], size_t *B_pub_len)
int botan_privkey_rsa_get_q(botan_mp_t q, botan_privkey_t rsa_key)
int botan_hash_update(botan_hash_t hash, const uint8_t *in, size_t in_len)
Definition ffi_hash.cpp:66
int botan_pubkey_load_ecdh(botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
int botan_mp_rshift(botan_mp_t out, botan_mp_t in, size_t shift)
Definition ffi_mp.cpp:256
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)
int botan_privkey_view_kyber_raw_key(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_privkey_create_ecdsa(botan_privkey_t *key, botan_rng_t rng, const char *params)
struct botan_pubkey_struct * botan_pubkey_t
Definition ffi.h:2112
int botan_ec_point_equal(botan_ec_point_t x, botan_ec_point_t y)
Definition ffi_ec.cpp:319
int botan_mp_set_from_radix_str(botan_mp_t dest, const char *str, size_t radix)
Definition ffi_mp.cpp:51
int botan_rng_add_entropy(botan_rng_t rng, const uint8_t *entropy, size_t entropy_len)
Definition ffi_rng.cpp:189
int botan_key_unwrap3394(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_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:161
int botan_oid_cmp(int *result, botan_asn1_oid_t a, botan_asn1_oid_t b)
Definition ffi_oid.cpp:63
int botan_mp_powmod(botan_mp_t out, botan_mp_t base, botan_mp_t exponent, botan_mp_t modulus)
Definition ffi_mp.cpp:247
int botan_ec_point_destroy(botan_ec_point_t ec_point)
Definition ffi_ec.cpp:230
int botan_x509_crl_next_update(botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_spake2p_prover_init(botan_spake2p_prover_t *prover, botan_spake2p_params_t params, const uint8_t secret[], size_t secret_len, const uint8_t prover_id[], size_t prover_id_len, const uint8_t verifier_id[], size_t verifier_id_len, const uint8_t context[], size_t context_len)
int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl)
int botan_ec_group_view_pem(botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_ec.cpp:133
int botan_mac_init(botan_mac_t *mac, const char *mac_name, uint32_t flags)
Definition ffi_mac.cpp:18
int botan_ec_group_get_curve_oid(botan_asn1_oid_t *oid, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:139
int botan_srp6_server_session_step2(botan_srp6_server_session_t srp6, const uint8_t A[], size_t A_len, uint8_t key[], size_t *key_len)
Definition ffi_srp6.cpp:102
int botan_mp_to_uint32(botan_mp_t mp, uint32_t *val)
Definition ffi_mp.cpp:150
int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t *estimate)
Definition ffi_pkey.cpp:452
int botan_mceies_encrypt(botan_pubkey_t mce_key, botan_rng_t rng, const char *aead, const uint8_t pt[], size_t pt_len, const uint8_t ad[], size_t ad_len, uint8_t ct[], size_t *ct_len)
int botan_pkcs_hash_id(const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
Definition ffi_pkey.cpp:469
int botan_privkey_rsa_get_privkey(botan_privkey_t rsa_key, uint8_t out[], size_t *out_len, uint32_t flags)
int botan_privkey_create_dh(botan_privkey_t *key, botan_rng_t rng, const char *param)
int botan_privkey_load_rsa_pkcs1(botan_privkey_t *key, const uint8_t bits[], size_t len)
int botan_hash_name(botan_hash_t hash, char *name, size_t *name_len)
Definition ffi_hash.cpp:93
int botan_spake2p_derive_secret(botan_spake2p_params_t params, const char *password, const uint8_t prover_id[], size_t prover_id_len, const uint8_t verifier_id[], size_t verifier_id_len, const uint8_t salt[], size_t salt_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_cert_get_issuer_dn_count(botan_x509_cert_t cert, const char *key, size_t *count)
Definition ffi_cert.cpp:478
int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t *tag_size)
int botan_ec_group_from_params(botan_ec_group_t *ec_group, botan_asn1_oid_t oid, botan_mp_t p, botan_mp_t a, botan_mp_t b, botan_mp_t base_x, botan_mp_t base_y, botan_mp_t order)
Definition ffi_ec.cpp:51
int botan_pubkey_load_slh_dsa(botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *slhdsa_mode)
int botan_ec_group_get_g_y(botan_mp_t *g_y, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:180
int botan_pk_op_key_agreement_export_public(botan_privkey_t key, uint8_t out[], size_t *out_len)
int botan_x509_ext_as_blocks_get_info(botan_x509_cert_t cert, int asnum, int *present, size_t *count)
int botan_x509_crl_entry_destroy(botan_x509_crl_entry_t entry)
int botan_x509_cert_issuer_alternative_names_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:922
int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char *field_name)
int botan_x509_cert_view_binary_values(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_cert.cpp:285
int botan_x509_crl_view_binary_values_count(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_srp6_generate_verifier(const char *identifier, const char *password, const uint8_t salt[], size_t salt_len, const char *group_id, const char *hash_id, uint8_t verifier[], size_t *verifier_len)
Definition ffi_srp6.cpp:123
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:81
int botan_hotp_generate(botan_hotp_t hotp, uint32_t *hotp_code, uint64_t hotp_counter)
Definition ffi_hotp.cpp:53
#define BOTAN_FFI_EXPORT(maj, min)
Definition ffi.h:89
int botan_spake2p_verifier_verify_confirmation(botan_spake2p_verifier_t verifier, const uint8_t confirmation[], size_t confirmation_len)
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:93
struct botan_srp6_server_session_struct * botan_srp6_server_session_t
Definition ffi.h:4555
int botan_rng_reseed(botan_rng_t rng, size_t bits)
Definition ffi_rng.cpp:185
int botan_mp_init(botan_mp_t *mp)
Definition ffi_mp.cpp:24
int botan_tpm2_ctx_enable_crypto_backend(botan_tpm2_ctx_t ctx, botan_rng_t rng)
Definition ffi_tpm2.cpp:150
int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:300
int botan_tpm2_ctx_init_ex(botan_tpm2_ctx_t *ctx_out, const char *tcti_name, const char *tcti_conf)
Definition ffi_tpm2.cpp:100
int botan_pk_op_decrypt_create(botan_pk_op_decrypt_t *op, botan_privkey_t key, const char *padding, uint32_t flags)
Definition ffi_pk_op.cpp:74
int botan_pubkey_load_classic_mceliece(botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *cmce_mode)
int botan_x509_general_name_view_binary_value(botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_cert.cpp:757
int botan_spake2p_verifier_process_message(botan_spake2p_verifier_t verifier, botan_rng_t rng, const uint8_t peer_message[], size_t peer_message_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t rsa_key)
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:87
int botan_x509_ext_as_blocks_get_entry_at(botan_x509_cert_t cert, int asnum, size_t i, uint32_t *min, uint32_t *max)
int botan_totp_generate(botan_totp_t totp, uint32_t *totp_code, uint64_t timestamp)
Definition ffi_totp.cpp:54
int botan_ec_point_mul(botan_ec_point_t *result, botan_ec_point_t ec_point, botan_ec_scalar_t ec_scalar, botan_rng_t rng)
Definition ffi_ec.cpp:323
struct botan_pk_op_decrypt_struct * botan_pk_op_decrypt_t
Definition ffi.h:3076
struct botan_mac_struct * botan_mac_t
Definition ffi.h:578
int botan_mp_to_str(botan_mp_t mp, uint8_t radix, char *out, size_t *out_len)
Definition ffi_mp.cpp:112
int botan_x509_crl_this_update(botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_cert_view_binary_values_count(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
Definition ffi_cert.cpp:340
int botan_zfec_decode(size_t K, size_t N, const size_t *indexes, uint8_t *const *inputs, size_t shareSize, uint8_t **outputs)
Definition ffi_zfec.cpp:35
int botan_mac_destroy(botan_mac_t mac)
Definition ffi_mac.cpp:36
int botan_mp_is_odd(botan_mp_t mp)
Definition ffi_mp.cpp:227
struct botan_asn1_oid_struct * botan_asn1_oid_t
Definition ffi.h:1415
int botan_totp_init(botan_totp_t *totp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits, size_t time_step)
Definition ffi_totp.cpp:26
int botan_x509_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t *key)
Definition ffi_cert.cpp:439
int botan_cipher_requires_entire_message(botan_cipher_t cipher)
int botan_tpm2_enable_crypto_backend(botan_tpm2_crypto_backend_state_t *cbs_out, struct ESYS_CONTEXT *esys_ctx, botan_rng_t rng)
Definition ffi_tpm2.cpp:181
int botan_privkey_load_classic_mceliece(botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *cmce_mode)
int botan_privkey_load_x25519(botan_privkey_t *key, const uint8_t privkey[32])
struct botan_privkey_struct * botan_privkey_t
Definition ffi.h:1777
int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t *out_len)
int botan_oid_from_string(botan_asn1_oid_t *oid, const char *oid_str)
Definition ffi_oid.cpp:22
struct botan_x509_crl_entry_struct * botan_x509_crl_entry_t
Definition ffi.h:4091
int botan_x509_cert_allowed_extended_usage_oid(botan_x509_cert_t cert, botan_asn1_oid_t oid)
Definition ffi_cert.cpp:574
int botan_hash_security_level(botan_hash_t hash, size_t *security_level)
Definition ffi_hash.cpp:55
int botan_cipher_reset(botan_cipher_t cipher)
int botan_spake2p_params_share_size(botan_spake2p_params_t params, size_t *share_size)
int botan_cipher_init(botan_cipher_t *cipher, const char *name, uint32_t flags)
int botan_ec_point_generator(botan_ec_point_t *ec_point, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:243
int botan_privkey_view_encrypted_der(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:346
int botan_block_cipher_clear(botan_block_cipher_t bc)
Definition ffi_block.cpp:43
int botan_pubkey_fingerprint(botan_pubkey_t key, const char *hash, uint8_t out[], size_t *out_len)
Definition ffi_pkey.cpp:459
int botan_xof_block_size(botan_xof_t xof, size_t *block_size)
Definition ffi_xof.cpp:46
int botan_ec_privkey_get_private_key(botan_privkey_t key, botan_ec_scalar_t *value)
int botan_pubkey_dsa_get_p(botan_mp_t p, botan_pubkey_t key)
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:212
int botan_hash_destroy(botan_hash_t hash)
Definition ffi_hash.cpp:37
int botan_pubkey_load_ecdh_sec1(botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, const char *curve_name)
int botan_pk_op_kem_encrypt_shared_key_length(botan_pk_op_kem_encrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
int botan_pk_op_key_agreement_size(botan_pk_op_ka_t op, size_t *out_len)
int botan_x509_cert_load_file(botan_x509_cert_t *cert_obj, const char *filename)
Definition ffi_cert.cpp:176
int botan_pk_op_sign_update(botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
int botan_mac_set_nonce(botan_mac_t mac, const uint8_t *nonce, size_t nonce_len)
Definition ffi_mac.cpp:47
const char * botan_x509_cert_validation_status(int code)
int botan_ec_scalar_to_mp(botan_ec_scalar_t ec_scalar, botan_mp_t *mp)
Definition ffi_ec.cpp:219
int botan_pubkey_ecc_key_used_explicit_encoding(botan_pubkey_t key)
int botan_block_cipher_block_size(botan_block_cipher_t bc)
Definition ffi_block.cpp:61
int botan_pubkey_load_frodokem(botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *frodo_mode)
int botan_x509_crl_update(botan_x509_crl_t *crl_obj, botan_x509_crl_t last_crl, botan_rng_t rng, botan_x509_cert_t ca_cert, botan_privkey_t ca_key, uint64_t issue_time, uint32_t next_update, const botan_x509_crl_entry_t *new_entries, size_t new_entries_len, const char *hash_fn, const char *padding)
int botan_privkey_ed25519_get_privkey(botan_privkey_t key, uint8_t output[64])
struct botan_x509_crl_struct * botan_x509_crl_t
Definition ffi.h:4086
int botan_srp6_server_session_init(botan_srp6_server_session_t *srp6)
Definition ffi_srp6.cpp:32
struct botan_tpm2_session_struct * botan_tpm2_session_t
Definition ffi.h:5055
int botan_privkey_export_pubkey(botan_pubkey_t *out, botan_privkey_t in)
Definition ffi_pkey.cpp:152
int botan_tpm2_ctx_init(botan_tpm2_ctx_t *ctx_out, const char *tcti_nameconf)
Definition ffi_tpm2.cpp:75
int botan_cipher_destroy(botan_cipher_t cipher)
int botan_x509_cert_verify_with_crl(int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const botan_x509_crl_t *crls, size_t crls_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
#define BOTAN_FFI_DEPRECATED(msg)
Definition ffi.h:104
int botan_pubkey_load_rsa_pkcs1(botan_pubkey_t *key, const uint8_t bits[], size_t len)
int botan_mp_num_bytes(botan_mp_t n, size_t *bytes)
Definition ffi_mp.cpp:309
int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:677
int botan_x509_cert_get_issuer_dn(botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:457
int botan_x509_general_name_destroy(botan_x509_general_name_t alt_names)
Definition ffi_cert.cpp:779
int botan_pubkey_oid(botan_asn1_oid_t *oid, botan_pubkey_t key)
Definition ffi_pkey.cpp:396
int botan_x509_cert_subject_alternative_names_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:883
int botan_pk_op_decrypt_destroy(botan_pk_op_decrypt_t op)
Definition ffi_pk_op.cpp:94
botan_x509_crl_reason_code
Definition ffi.h:4153
@ BOTAN_CRL_ENTRY_PRIVILEGE_WITHDRAWN
Definition ffi.h:4162
@ BOTAN_CRL_ENTRY_UNSPECIFIED
Definition ffi.h:4154
@ BOTAN_CRL_ENTRY_SUPERSEDED
Definition ffi.h:4158
@ BOTAN_CRL_ENTRY_CERTIFICATE_HOLD
Definition ffi.h:4160
@ BOTAN_CRL_ENTRY_CESSATION_OF_OPERATION
Definition ffi.h:4159
@ BOTAN_CRL_ENTRY_CA_COMPROMISE
Definition ffi.h:4156
@ BOTAN_CRL_ENTRY_REMOVE_FROM_CRL
Definition ffi.h:4161
@ BOTAN_CRL_ENTRY_AA_COMPROMISE
Definition ffi.h:4163
@ BOTAN_CRL_ENTRY_KEY_COMPROMISE
Definition ffi.h:4155
@ BOTAN_CRL_ENTRY_AFFILIATION_CHANGED
Definition ffi.h:4157
int botan_x509_cert_excluded_name_constraints(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
Definition ffi_cert.cpp:823
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_mp_view_hex(botan_mp_t mp, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_mp.cpp:105
int botan_x509_crl_entries_count(botan_x509_crl_t crl, size_t *count)
int botan_privkey_load_rsa(botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t e)
int botan_privkey_destroy(botan_privkey_t key)
Definition ffi_pkey.cpp:120
int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:166
struct botan_pk_op_encrypt_struct * botan_pk_op_encrypt_t
Definition ffi.h:3025
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:202
int botan_mp_from_bin(botan_mp_t mp, const uint8_t vec[], size_t vec_len)
Definition ffi_mp.cpp:84
int botan_ec_group_get_a(botan_mp_t *a, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:167
int botan_spake2p_prover_shared_secret(botan_spake2p_prover_t prover, botan_view_ctx ctx, botan_view_bin_fn view)
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:83
int botan_spake2p_params_confirmation_size(botan_spake2p_params_t params, size_t *confirmation_size)
int botan_hash_clear(botan_hash_t hash)
Definition ffi_hash.cpp:62
int botan_x509_crl_entries(botan_x509_crl_t crl, size_t index, botan_x509_crl_entry_t *entry)
int botan_pubkey_dsa_get_y(botan_mp_t y, botan_pubkey_t key)
int botan_spake2p_verifier_destroy(botan_spake2p_verifier_t verifier)
int botan_mp_add_u32(botan_mp_t result, botan_mp_t x, uint32_t y)
Definition ffi_mp.cpp:181
int botan_pubkey_load_ml_kem(botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len, const char *mlkem_mode)
int botan_mp_to_hex(botan_mp_t mp, char *out)
Definition ffi_mp.cpp:91
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:224
int botan_privkey_stateful_operation(botan_privkey_t key, int *out)
Definition ffi_pkey.cpp:422
int botan_srp6_client_agree(const char *username, const char *password, const char *group_id, const char *hash_id, const uint8_t salt[], size_t salt_len, const uint8_t B[], size_t B_len, botan_rng_t rng_obj, uint8_t A[], size_t *A_len, uint8_t K[], size_t *K_len)
Definition ffi_srp6.cpp:153
int botan_x509_cert_subject_alternative_names(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
Definition ffi_cert.cpp:858
int botan_mp_swap(botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:242
struct botan_totp_struct * botan_totp_t
Definition ffi.h:4462
int botan_fpe_decrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
Definition ffi_fpe.cpp:82
int botan_privkey_load_ed448(botan_privkey_t *key, const uint8_t privkey[57])
int botan_mp_destroy(botan_mp_t mp)
Definition ffi_mp.cpp:157
int botan_x509_ext_ip_addr_blocks_get_counts(botan_x509_cert_t cert, size_t *v4_count, size_t *v6_count)
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:266
int botan_pk_op_encrypt(botan_pk_op_encrypt_t op, botan_rng_t rng, uint8_t out[], size_t *out_len, const uint8_t plaintext[], size_t plaintext_len)
Definition ffi_pk_op.cpp:56
int botan_x509_crl_entry_revocation_date(botan_x509_crl_entry_t entry, uint64_t *time_since_epoch)
int botan_x509_cert_issuer_alternative_names(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
Definition ffi_cert.cpp:897
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:234
int botan_spake2p_verifier_skip_confirmation(botan_spake2p_verifier_t verifier)
int botan_hash_output_length(botan_hash_t hash, size_t *output_length)
Definition ffi_hash.cpp:41
struct botan_x509_general_name_struct * botan_x509_general_name_t
Definition ffi.h:3844
int botan_ec_group_equal(botan_ec_group_t curve1, botan_ec_group_t curve2)
Definition ffi_ec.cpp:190
int botan_pubkey_load_ed25519(botan_pubkey_t *key, const uint8_t pubkey[32])
int botan_x509_ext_ip_addr_blocks_get_family(botan_x509_cert_t cert, int ipv6, size_t i, int *has_safi, uint8_t *safi, int *present, size_t *count)
int botan_spake2p_prover_process_message(botan_spake2p_prover_t prover, botan_rng_t rng, const uint8_t peer_message[], size_t peer_message_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits)
Definition ffi_mp.cpp:273
int botan_tpm2_rng_init(botan_rng_t *rng_out, botan_tpm2_ctx_t ctx, botan_tpm2_session_t s1, botan_tpm2_session_t s2, botan_tpm2_session_t s3)
Definition ffi_tpm2.cpp:212
int botan_pubkey_view_ec_public_point(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_cert_serial_number(botan_x509_cert_t cert, botan_mp_t *serial_number)
Definition ffi_cert.cpp:645
int botan_pk_op_kem_decrypt_shared_key(botan_pk_op_kem_decrypt_t op, const uint8_t salt[], size_t salt_len, const uint8_t encapsulated_key[], size_t encapsulated_key_len, size_t desired_shared_key_len, uint8_t shared_key[], size_t *shared_key_len)
int botan_pubkey_load_sm2_sec1(botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, const char *curve_name)
int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t *key, size_t key_len)
int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t *out_len)
Definition ffi_cert.cpp:602
int botan_mp_equal(botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:219
int botan_ec_point_view_x_bytes(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_ec.cpp:280
int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, size_t pbkdf_iterations, const char *cipher_algo, const char *pbkdf_algo, uint32_t flags)
Definition ffi_pkey.cpp:326
int botan_srp6_server_session_destroy(botan_srp6_server_session_t srp6)
Definition ffi_srp6.cpp:45
int botan_privkey_rsa_get_n(botan_mp_t n, botan_privkey_t rsa_key)
int botan_ec_group_view_der(botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_ec.cpp:128
int botan_totp_destroy(botan_totp_t totp)
Definition ffi_totp.cpp:45
int botan_pk_op_key_agreement_create(botan_pk_op_ka_t *op, botan_privkey_t key, const char *kdf, uint32_t flags)
int botan_oid_register(botan_asn1_oid_t oid, const char *name)
Definition ffi_oid.cpp:40
int botan_pk_op_key_agreement_destroy(botan_pk_op_ka_t op)
int botan_mp_set_from_str(botan_mp_t dest, const char *str)
Definition ffi_mp.cpp:43
int botan_privkey_view_encrypted_der_timed(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:274
int botan_mp_flip_sign(botan_mp_t mp)
Definition ffi_mp.cpp:80
int botan_xof_name(botan_xof_t xof, char *name, size_t *name_len)
Definition ffi_xof.cpp:53
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:166
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:197
int botan_privkey_remaining_operations(botan_privkey_t key, uint64_t *out)
Definition ffi_pkey.cpp:437
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:298
int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
int botan_mceies_decrypt(botan_privkey_t mce_key, const char *aead, const uint8_t ct[], size_t ct_len, const uint8_t ad[], size_t ad_len, uint8_t pt[], size_t *pt_len)
int botan_spake2p_params_init_custom(botan_spake2p_params_t *params, botan_ec_group_t group, const uint8_t seed[], size_t seed_len, const char *hash_fn)
int botan_x509_cert_permitted_name_constraints(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
Definition ffi_cert.cpp:788
struct botan_pk_op_kem_encrypt_struct * botan_pk_op_kem_encrypt_t
Definition ffi.h:3295
int botan_xof_output(botan_xof_t xof, uint8_t *out, size_t out_len)
Definition ffi_xof.cpp:81
int botan_x509_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:535
int botan_pubkey_x448_get_pubkey(botan_pubkey_t key, uint8_t pubkey[56])
int botan_mp_is_zero(botan_mp_t mp)
Definition ffi_mp.cpp:223
int botan_mp_mod_inverse(botan_mp_t out, botan_mp_t in, botan_mp_t modulus)
Definition ffi_mp.cpp:260
int botan_mp_cmp(int *result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:235
int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t *out_len)
Definition ffi_cert.cpp:592
int botan_pk_op_kem_decrypt_create(botan_pk_op_kem_decrypt_t *op, botan_privkey_t key, const char *kdf)
int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:185
int botan_xof_init(botan_xof_t *xof, const char *xof_name, uint32_t flags)
Definition ffi_xof.cpp:19
int botan_privkey_load_slh_dsa(botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *slhdsa_mode)
struct botan_hotp_struct * botan_hotp_t
Definition ffi.h:4430
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:23
int botan_pubkey_rsa_get_e(botan_mp_t e, botan_pubkey_t rsa_key)
int botan_mp_gcd(botan_mp_t out, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:282
struct botan_block_cipher_struct * botan_block_cipher_t
Definition ffi.h:974
struct botan_ec_group_struct * botan_ec_group_t
Definition ffi.h:1472
int botan_system_rng_get(uint8_t *out, size_t out_len)
Definition ffi_rng.cpp:175
int botan_fpe_destroy(botan_fpe_t fpe)
Definition ffi_fpe.cpp:56
int botan_privkey_oid(botan_asn1_oid_t *oid, botan_privkey_t key)
Definition ffi_pkey.cpp:409
int botan_x509_crl_load(botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_len)
int botan_mp_clear(botan_mp_t mp)
Definition ffi_mp.cpp:35
int botan_pubkey_load_ed448(botan_pubkey_t *key, const uint8_t pubkey[57])
int botan_ec_group_supports_named_group(const char *name, int *out)
Definition ffi_ec.cpp:37
int botan_xof_copy_state(botan_xof_t *dest, botan_xof_t source)
Definition ffi_xof.cpp:39
int botan_x509_cert_get_subject_dn(botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:494
int botan_cipher_is_authenticated(botan_cipher_t cipher)
int botan_ec_point_from_bytes(botan_ec_point_t *ec_point, botan_ec_group_t ec_group, const uint8_t *bytes, size_t bytes_len)
Definition ffi_ec.cpp:267
int botan_mp_view_str(botan_mp_t mp, uint8_t radix, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_mp.cpp:124
int botan_privkey_view_encrypted_pem(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:371
int botan_privkey_load_ml_kem(botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *mlkem_mode)
int botan_mp_get_bit(botan_mp_t n, size_t bit)
Definition ffi_mp.cpp:290
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:76
int botan_pubkey_destroy(botan_pubkey_t key)
Definition ffi_pkey.cpp:148
int botan_ec_group_get_order(botan_mp_t *order, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:185
int botan_x509_cert_dup(botan_x509_cert_t *new_cert, botan_x509_cert_t cert)
Definition ffi_cert.cpp:193
int botan_ec_point_identity(botan_ec_point_t *ec_point, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:234
int botan_x509_cert_verify(int *validation_result, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const char *trusted_path, size_t required_strength, const char *hostname, uint64_t reference_time)
Definition ffi_cert.cpp:949
int botan_privkey_export_encrypted(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, const char *encryption_algo, uint32_t flags)
Definition ffi_pkey.cpp:239
int botan_block_cipher_name(botan_block_cipher_t cipher, char *name, size_t *name_len)
Definition ffi_block.cpp:90
int botan_pk_op_kem_encrypt_create(botan_pk_op_kem_encrypt_t *op, botan_pubkey_t key, const char *kdf)
int botan_rng_get(botan_rng_t rng, uint8_t *out, size_t out_len)
Definition ffi_rng.cpp:168
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
Definition ffi.h:161
int botan_pubkey_load_sm2_enc(botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t *time_since_epoch)
Definition ffi_cert.cpp:612
int botan_hotp_destroy(botan_hotp_t hotp)
Definition ffi_hotp.cpp:44
int botan_mp_sub_u32(botan_mp_t result, botan_mp_t x, uint32_t y)
Definition ffi_mp.cpp:191
int botan_pubkey_x25519_get_pubkey(botan_pubkey_t key, uint8_t pubkey[32])
int botan_pk_op_verify_destroy(botan_pk_op_verify_t op)
int botan_mp_view_bin(botan_mp_t mp, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_mp.cpp:143
int botan_srp6_group_size(const char *group_id, size_t *group_p_bytes)
Definition ffi_srp6.cpp:49
int botan_ec_group_from_oid(botan_ec_group_t *ec_group, botan_asn1_oid_t oid)
Definition ffi_ec.cpp:98
int botan_x509_crl_entry_view_serial_number(botan_x509_crl_entry_t entry, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_xof_destroy(botan_xof_t xof)
Definition ffi_xof.cpp:93
struct botan_x509_cert_struct * botan_x509_cert_t
Definition ffi.h:3483
int botan_mp_num_bits(botan_mp_t n, size_t *bits)
Definition ffi_mp.cpp:302
int botan_privkey_rsa_get_p(botan_mp_t p, botan_privkey_t rsa_key)
int botan_oid_view_string(botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_oid.cpp:50
int botan_ec_scalar_from_mp(botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_mp_t mp)
Definition ffi_ec.cpp:209
struct botan_tpm2_ctx_struct * botan_tpm2_ctx_t
Definition ffi.h:5050
int botan_x509_cert_excluded_name_constraints_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:845
int botan_x509_cert_is_ca(botan_x509_cert_t cert)
Definition ffi_cert.cpp:410
botan_x509_general_name_types
Definition ffi.h:3851
@ BOTAN_X509_DNS_NAME
Definition ffi.h:3854
@ BOTAN_X509_DIRECTORY_NAME
Definition ffi.h:3855
@ BOTAN_X509_OTHER_NAME
Definition ffi.h:3852
@ BOTAN_X509_EMAIL_ADDRESS
Definition ffi.h:3853
@ BOTAN_X509_IP_ADDRESS
Definition ffi.h:3857
@ BOTAN_X509_URI
Definition ffi.h:3856
int botan_privkey_create(botan_privkey_t *key, const char *algo_name, const char *algo_params, botan_rng_t rng)
Definition ffi_pkey.cpp:30
int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char *hostname)
Definition ffi_cert.cpp:936
int botan_mac_update(botan_mac_t mac, const uint8_t *buf, size_t len)
Definition ffi_mac.cpp:66
int botan_privkey_rsa_get_e(botan_mp_t e, botan_privkey_t rsa_key)
int botan_hotp_check(botan_hotp_t hotp, uint64_t *next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range)
Definition ffi_hotp.cpp:67
int botan_privkey_create_mceliece(botan_privkey_t *key, botan_rng_t rng, size_t n, size_t t)
int botan_x509_cert_load(botan_x509_cert_t *cert_obj, const uint8_t cert[], size_t cert_len)
Definition ffi_cert.cpp:211
int botan_mp_mul(botan_mp_t result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:201
struct botan_pk_op_ka_struct * botan_pk_op_ka_t
Definition ffi.h:3224
int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:162
int botan_hash_block_size(botan_hash_t hash, size_t *block_size)
Definition ffi_hash.cpp:48
int botan_ec_group_from_name(botan_ec_group_t *ec_group, const char *name)
Definition ffi_ec.cpp:111
int botan_pubkey_load(botan_pubkey_t *key, const uint8_t bits[], size_t len)
Definition ffi_pkey.cpp:124
int botan_ec_group_supports_application_specific_group(int *out)
Definition ffi_ec.cpp:25
int botan_pk_op_verify_create(botan_pk_op_verify_t *op, botan_pubkey_t key, const char *hash_and_padding, uint32_t flags)
int botan_pubkey_load_x25519(botan_pubkey_t *key, const uint8_t pubkey[32])
int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_privkey_load_ecdh(botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
int botan_cipher_get_keyspec(botan_cipher_t cipher, size_t *min_keylen, size_t *max_keylen, size_t *mod_keylen)
int botan_zfec_encode(size_t K, size_t N, const uint8_t *input, size_t size, uint8_t **outputs)
Definition ffi_zfec.cpp:18
int botan_pk_op_kem_encrypt_encapsulated_key_length(botan_pk_op_kem_encrypt_t op, size_t *output_encapsulated_key_length)
int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
struct botan_pk_op_sign_struct * botan_pk_op_sign_t
Definition ffi.h:3128
int botan_x509_crl_entry_create(botan_x509_crl_entry_t *entry, botan_x509_cert_t cert, int reason_code)
int botan_tpm2_ctx_from_esys(botan_tpm2_ctx_t *ctx_out, struct ESYS_CONTEXT *esys_ctx)
Definition ffi_tpm2.cpp:133
int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:636
int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:686
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:207
botan_x509_cert_key_constraints
Definition ffi.h:3793
@ KEY_ENCIPHERMENT
Definition ffi.h:3797
@ NO_CONSTRAINTS
Definition ffi.h:3794
@ CRL_SIGN
Definition ffi.h:3801
@ DIGITAL_SIGNATURE
Definition ffi.h:3795
@ KEY_AGREEMENT
Definition ffi.h:3799
@ DATA_ENCIPHERMENT
Definition ffi.h:3798
@ KEY_CERT_SIGN
Definition ffi.h:3800
@ ENCIPHER_ONLY
Definition ffi.h:3802
@ NON_REPUDIATION
Definition ffi.h:3796
@ DECIPHER_ONLY
Definition ffi.h:3803
int botan_hash_copy_state(botan_hash_t *dest, botan_hash_t source)
Definition ffi_hash.cpp:86
int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char *field_name)
int botan_spake2p_verifier_init(botan_spake2p_verifier_t *verifier, botan_spake2p_params_t params, const uint8_t record[], size_t record_len, const uint8_t prover_id[], size_t prover_id_len, const uint8_t verifier_id[], size_t verifier_id_len, const uint8_t context[], size_t context_len)
int botan_x509_crl_create(botan_x509_crl_t *crl_obj, botan_rng_t rng, botan_x509_cert_t ca_cert, botan_privkey_t ca_key, uint64_t issue_time, uint32_t next_update, const char *hash_fn, const char *padding)
int botan_pubkey_load_ecdsa(botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
int botan_ec_group_destroy(botan_ec_group_t ec_group)
Definition ffi_ec.cpp:21
int botan_ec_privkey_create(botan_privkey_t *key, const char *algo_name, botan_ec_group_t ec_group, botan_rng_t rng)
Definition ffi_pkey.cpp:61
int botan_pubkey_load_sm2(botan_pubkey_t *key, botan_mp_t public_x, botan_mp_t public_y, const char *curve_name)
int botan_pk_op_kem_encrypt_create_shared_key(botan_pk_op_kem_encrypt_t op, botan_rng_t rng, const uint8_t salt[], size_t salt_len, size_t desired_shared_key_len, uint8_t shared_key[], size_t *shared_key_len, uint8_t encapsulated_key[], size_t *encapsulated_key_len)
struct botan_mp_struct * botan_mp_t
Definition ffi.h:1040
int botan_ec_point_negate(botan_ec_point_t *result, botan_ec_point_t ec_point)
Definition ffi_ec.cpp:336
int botan_pubkey_load_dsa(botan_pubkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t y)
int botan_privkey_dsa_get_x(botan_mp_t n, botan_privkey_t key)
int botan_ec_point_view_xy_bytes(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_ec.cpp:294
struct botan_xof_struct * botan_xof_t
Definition ffi.h:410
int botan_ec_point_from_xy(botan_ec_point_t *ec_point, botan_ec_group_t ec_group, botan_mp_t x, botan_mp_t y)
Definition ffi_ec.cpp:252
void * botan_view_ctx
Definition ffi.h:152
struct botan_rng_struct * botan_rng_t
Definition ffi.h:289
int botan_xof_update(botan_xof_t xof, const uint8_t *in, size_t in_len)
Definition ffi_xof.cpp:69
int botan_ec_group_unregister(botan_asn1_oid_t oid)
Definition ffi_ec.cpp:124
int botan_ec_group_get_b(botan_mp_t *b, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:171
int botan_x509_cert_allowed_extended_usage_str(botan_x509_cert_t cert, const char *oid)
Definition ffi_cert.cpp:559
int botan_block_cipher_destroy(botan_block_cipher_t bc)
Definition ffi_block.cpp:39
int botan_tpm2_supports_crypto_backend(void)
Definition ffi_tpm2.cpp:67
struct botan_ec_scalar_struct * botan_ec_scalar_t
Definition ffi.h:1623
BOTAN_FFI_ERROR
Definition ffi.h:113
@ BOTAN_FFI_ERROR_TPM_ERROR
Definition ffi.h:144
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
@ BOTAN_FFI_ERROR_INVALID_KEY_LENGTH
Definition ffi.h:134
@ BOTAN_FFI_ERROR_KEY_NOT_SET
Definition ffi.h:133
@ BOTAN_FFI_ERROR_TLS_ERROR
Definition ffi.h:141
@ BOTAN_FFI_ERROR_EXCEPTION_THROWN
Definition ffi.h:125
@ BOTAN_FFI_ERROR_OUT_OF_MEMORY
Definition ffi.h:126
@ BOTAN_FFI_ERROR_OUT_OF_RANGE
Definition ffi.h:136
@ BOTAN_FFI_ERROR_INTERNAL_ERROR
Definition ffi.h:128
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:116
@ BOTAN_FFI_ERROR_INVALID_OBJECT
Definition ffi.h:139
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:146
@ BOTAN_FFI_ERROR_HTTP_ERROR
Definition ffi.h:142
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:130
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:118
@ BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR
Definition ffi.h:123
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:131
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
@ BOTAN_FFI_ERROR_SYSTEM_ERROR
Definition ffi.h:127
@ BOTAN_FFI_ERROR_ROUGHTIME_ERROR
Definition ffi.h:143
@ BOTAN_FFI_ERROR_NO_VALUE
Definition ffi.h:120
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition ffi.h:135
@ BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE
Definition ffi.h:122
@ BOTAN_FFI_ERROR_BAD_MAC
Definition ffi.h:119
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:132
int botan_privkey_load_sm2_enc(botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
struct botan_tpm2_crypto_backend_state_struct * botan_tpm2_crypto_backend_state_t
Definition ffi.h:5060
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:54
int botan_pubkey_load_kyber(botan_pubkey_t *key, const uint8_t pubkey[], size_t key_len)
int botan_spake2p_prover_destroy(botan_spake2p_prover_t prover)
int botan_mac_name(botan_mac_t mac, char *name, size_t *name_len)
Definition ffi_mac.cpp:83
int botan_oid_view_name(botan_asn1_oid_t oid, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_oid.cpp:54
int botan_hotp_init(botan_hotp_t *hotp, const uint8_t key[], size_t key_len, const char *hash_algo, size_t digits)
Definition ffi_hotp.cpp:26
int botan_cipher_clear(botan_cipher_t hash)
struct botan_ec_point_struct * botan_ec_point_t
Definition ffi.h:1628
struct botan_pk_op_verify_struct * botan_pk_op_verify_t
Definition ffi.h:3179
int botan_ec_pubkey_get_group(botan_pubkey_t key, botan_ec_group_t *ec_group)
int botan_x509_cert_view_public_key_bits(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_cert.cpp:699
int botan_pk_op_decrypt_output_length(botan_pk_op_decrypt_t op, size_t ctext_len, size_t *ptext_len)
Definition ffi_pk_op.cpp:98
int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t *op, botan_pubkey_t key, const char *padding, uint32_t flags)
Definition ffi_pk_op.cpp:28
int botan_mp_is_even(botan_mp_t mp)
Definition ffi_mp.cpp:231
int botan_ec_group_get_p(botan_mp_t *p, botan_ec_group_t ec_group)
Definition ffi_ec.cpp:163
int botan_tpm2_ctx_destroy(botan_tpm2_ctx_t ctx)
Definition ffi_tpm2.cpp:172
int botan_spake2p_verifier_shared_secret(botan_spake2p_verifier_t verifier, botan_view_ctx ctx, botan_view_bin_fn view)
struct botan_spake2p_verifier_struct * botan_spake2p_verifier_t
Definition ffi.h:4810
int botan_x509_crl_view_string_values(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)
int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:170
int botan_x509_crl_verify_signature(botan_x509_crl_t crl, botan_pubkey_t key)
int botan_fpe_encrypt(botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
Definition ffi_fpe.cpp:65
int botan_tpm2_unauthenticated_session_init(botan_tpm2_session_t *session_out, botan_tpm2_ctx_t ctx)
Definition ffi_tpm2.cpp:232
int botan_ec_group_from_ber(botan_ec_group_t *ec_group, const uint8_t *ber, size_t ber_len)
Definition ffi_ec.cpp:72
int botan_rng_destroy(botan_rng_t rng)
Definition ffi_rng.cpp:164
int botan_x509_crl_load_file(botan_x509_crl_t *crl_obj, const char *crl_path)
int botan_spake2p_params_destroy(botan_spake2p_params_t params)
int botan_pubkey_sm2_compute_za(uint8_t out[], size_t *out_len, const char *ident, const char *hash_algo, botan_pubkey_t key)
int botan_tpm2_crypto_backend_state_destroy(botan_tpm2_crypto_backend_state_t cbs)
Definition ffi_tpm2.cpp:203
int botan_oid_equal(botan_asn1_oid_t a, botan_asn1_oid_t b)
Definition ffi_oid.cpp:59
int botan_ec_privkey_get_group(botan_privkey_t key, botan_ec_group_t *ec_group)
int botan_hash_final(botan_hash_t hash, uint8_t out[])
Definition ffi_hash.cpp:78
int botan_privkey_load_dsa(botan_privkey_t *key, botan_mp_t p, botan_mp_t q, botan_mp_t g, botan_mp_t x)
int botan_hash_init(botan_hash_t *hash, const char *hash_name, uint32_t flags)
Definition ffi_hash.cpp:18
struct botan_spake2p_params_struct * botan_spake2p_params_t
Definition ffi.h:4690
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:87
int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key, uint8_t pubkey[32])
struct botan_cipher_struct * botan_cipher_t
Definition ffi.h:674
int botan_ec_scalar_destroy(botan_ec_scalar_t ec_scalar)
Definition ffi_ec.cpp:196
int botan_tpm2_session_destroy(botan_tpm2_session_t session)
Definition ffi_tpm2.cpp:249
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_privkey_load_kyber(botan_privkey_t *key, const uint8_t privkey[], size_t key_len)
int botan_mac_output_length(botan_mac_t mac, size_t *output_length)
Definition ffi_mac.cpp:55
int botan_pk_op_sign_create(botan_pk_op_sign_t *op, botan_privkey_t key, const char *hash_and_padding, uint32_t flags)
int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage)
Definition ffi_cert.cpp:544
int botan_pk_op_encrypt_output_length(botan_pk_op_encrypt_t op, size_t ptext_len, size_t *ctext_len)
Definition ffi_pk_op.cpp:49
int botan_pk_op_key_agreement(botan_pk_op_ka_t op, uint8_t out[], size_t *out_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)
int botan_fpe_fe1_init(botan_fpe_t *fpe, botan_mp_t n, const uint8_t key[], size_t key_len, size_t rounds, uint32_t flags)
Definition ffi_fpe.cpp:28
int botan_x509_cert_view_string_values_count(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
Definition ffi_cert.cpp:398
int botan_pk_op_kem_encrypt_destroy(botan_pk_op_kem_encrypt_t op)
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:170
int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t *time_since_epoch)
Definition ffi_cert.cpp:624
int botan_key_wrap3394(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_pubkey_ed448_get_pubkey(botan_pubkey_t key, uint8_t pubkey[57])
int botan_privkey_rsa_get_d(botan_mp_t d, botan_privkey_t rsa_key)
int botan_pubkey_load_ecdsa_sec1(botan_pubkey_t *key, const uint8_t sec1[], size_t sec1_len, const char *curve_name)
int botan_x509_general_name_view_string_value(botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:734
int botan_ec_group_from_pem(botan_ec_group_t *ec_group, const char *pem)
Definition ffi_ec.cpp:85
int botan_mp_is_negative(botan_mp_t mp)
Definition ffi_mp.cpp:72
int botan_pk_op_encrypt_destroy(botan_pk_op_encrypt_t op)
Definition ffi_pk_op.cpp:45
int botan_pubkey_dsa_get_g(botan_mp_t d, botan_pubkey_t key)
int botan_x509_crl_entry_reason(botan_x509_crl_entry_t entry, int *reason_code)
int botan_ec_scalar_random(botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_rng_t rng)
Definition ffi_ec.cpp:200
int botan_mac_set_key(botan_mac_t mac, const uint8_t *key, size_t key_len)
Definition ffi_mac.cpp:40
int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:695
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:143
int botan_pubkey_dsa_get_q(botan_mp_t q, botan_pubkey_t key)
int botan_privkey_load_frodokem(botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *frodo_mode)
int botan_mp_sub(botan_mp_t result, botan_mp_t x, botan_mp_t y)
Definition ffi_mp.cpp:171
int botan_privkey_create_ecdh(botan_privkey_t *key, botan_rng_t rng, const char *params)
int botan_privkey_load_ecdsa(botan_privkey_t *key, botan_mp_t scalar, const char *curve_name)
int botan_ec_point_view_uncompressed(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_ec.cpp:301
int botan_xof_accepts_input(botan_xof_t xof)
Definition ffi_xof.cpp:61
int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:661
int botan_ec_point_view_y_bytes(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_ec.cpp:287
int botan_rng_init(botan_rng_t *rng, const char *rng_type)
Definition ffi_rng.cpp:38
int botan_x509_cert_get_path_length_constraint(botan_x509_cert_t cert, size_t *path_limit)
Definition ffi_cert.cpp:419
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:76
int botan_spake2p_prover_generate_message(botan_spake2p_prover_t prover, botan_rng_t rng, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_privkey_load_ml_dsa(botan_privkey_t *key, const uint8_t privkey[], size_t key_len, const char *mldsa_mode)
int botan_pk_op_kem_decrypt_shared_key_length(botan_pk_op_kem_decrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
int botan_totp_check(botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift)
Definition ffi_totp.cpp:68
int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t *out_len)
Definition ffi_cert.cpp:531
int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t *nl)
int botan_pk_op_kem_decrypt_destroy(botan_pk_op_kem_decrypt_t op)
int botan_pk_op_sign_destroy(botan_pk_op_sign_t op)
int botan_privkey_x448_get_privkey(botan_privkey_t key, uint8_t output[56])
int botan_mp_is_positive(botan_mp_t mp)
Definition ffi_mp.cpp:76
int botan_spake2p_registration_record(botan_spake2p_params_t params, botan_rng_t rng, const uint8_t secret[], size_t secret_len, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_privkey_load_ed25519(botan_privkey_t *key, const uint8_t privkey[32])
int botan_ec_point_is_identity(botan_ec_point_t ec_point)
Definition ffi_ec.cpp:315
struct botan_fpe_struct * botan_fpe_t
Definition ffi.h:4502
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:229
int botan_oid_destroy(botan_asn1_oid_t oid)
Definition ffi_oid.cpp:18
int botan_ec_point_view_compressed(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_ec.cpp:308
int botan_privkey_x25519_get_privkey(botan_privkey_t key, uint8_t output[32])
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_privkey_ed448_get_privkey(botan_privkey_t key, uint8_t output[57])
int botan_privkey_export_encrypted_pbkdf_msec(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, uint32_t pbkdf_msec_runtime, size_t *pbkdf_iterations_out, const char *cipher_algo, const char *pbkdf_algo, uint32_t flags)
Definition ffi_pkey.cpp:249
int botan_x509_crl_view_string_values_count(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_cipher_query_keylen(botan_cipher_t cipher, size_t *out_minimum_keylength, size_t *out_maximum_keylength)
int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t *ug)
int botan_pubkey_load_rsa(botan_pubkey_t *key, botan_mp_t n, botan_mp_t e)
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:33
int botan_x509_general_name_get_type(botan_x509_general_name_t name, unsigned int *type)
Definition ffi_cert.cpp:709
int botan_mac_clear(botan_mac_t mac)
Definition ffi_mac.cpp:62
int botan_pubkey_view_kyber_raw_key(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_cert_permitted_name_constraints_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:810
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:294
int botan_bcrypt_is_valid(const char *pass, const char *hash)
Definition ffi_kdf.cpp:209
int botan_mp_set_from_mp(botan_mp_t dest, botan_mp_t source)
Definition ffi_mp.cpp:68
struct botan_hash_struct * botan_hash_t
Definition ffi.h:488
botan_x509_value_type
Definition ffi.h:3498
@ BOTAN_X509_AUTHORITY_KEY_IDENTIFIER
Definition ffi.h:3503
@ BOTAN_X509_SUBJECT_KEY_IDENTIFIER
Definition ffi.h:3502
@ BOTAN_X509_TBS_DATA_BITS
Definition ffi.h:3506
@ BOTAN_X509_SIGNATURE_BITS
Definition ffi.h:3508
@ BOTAN_X509_PUBLIC_KEY_PKCS8_BITS
Definition ffi.h:3505
@ BOTAN_X509_DER_ENCODING
Definition ffi.h:3510
@ BOTAN_X509_PEM_ENCODING
Definition ffi.h:3511
@ BOTAN_X509_OCSP_RESPONDER_URLS
Definition ffi.h:3514
@ BOTAN_X509_SIGNATURE_SCHEME_BITS
Definition ffi.h:3507
@ BOTAN_X509_SUBJECT_DN_BITS
Definition ffi.h:3500
@ BOTAN_X509_CRL_DISTRIBUTION_URLS
Definition ffi.h:3513
@ BOTAN_X509_SERIAL_NUMBER
Definition ffi.h:3499
@ BOTAN_X509_ISSUER_DN_BITS
Definition ffi.h:3501
@ BOTAN_X509_CA_ISSUERS_URLS
Definition ffi.h:3515
int botan_x509_crl_view_binary_values(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_rng_generate_with_input(botan_rng_t rng, uint8_t *out, size_t out_len, const uint8_t *addl_input, size_t addl_len)
Definition ffi_rng.cpp:230
int botan_pubkey_load_x448(botan_pubkey_t *key, const uint8_t pubkey[56])
int botan_privkey_create_elgamal(botan_privkey_t *key, botan_rng_t rng_obj, size_t pbits, size_t qbits)
int botan_pubkey_load_dh(botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
int botan_privkey_load_dh(botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)
int botan_pubkey_load_elgamal(botan_pubkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t y)
int botan_privkey_create_dsa(botan_privkey_t *key, botan_rng_t rng_obj, size_t pbits, size_t qbits)
int botan_privkey_load_elgamal(botan_privkey_t *key, botan_mp_t p, botan_mp_t g, botan_mp_t x)