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