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