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