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