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