diff options
author | lloyd <[email protected]> | 2015-02-19 04:02:04 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-19 04:02:04 +0000 |
commit | aa4b1ae32e96429a18c7d53a50febc4fa0e6f124 (patch) | |
tree | 29e5c3d9b6aa0962af17d1d70890b80346f6a50c /src/lib/ffi | |
parent | 888aed4ec2f08684a9707c1251f27285942578c5 (diff) |
FFI cleanups
Diffstat (limited to 'src/lib/ffi')
-rw-r--r-- | src/lib/ffi/ffi.cpp | 19 | ||||
-rw-r--r-- | src/lib/ffi/ffi.h | 44 |
2 files changed, 29 insertions, 34 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index cb2efceda..6c29a6f7e 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -102,7 +102,7 @@ int apply_fn(botan_struct<T, M>* o, const char* func_name, F func) return -1; } -int write_output(uint8_t out[], size_t* out_len, const uint8_t buf[], size_t buf_len) +inline int write_output(uint8_t out[], size_t* out_len, const uint8_t buf[], size_t buf_len) { Botan::clear_mem(out, *out_len); const size_t avail = *out_len; @@ -121,14 +121,14 @@ int write_vec_output(uint8_t out[], size_t* out_len, const std::vector<uint8_t, return write_output(out, out_len, &buf[0], buf.size()); } -int write_str_output(uint8_t out[], size_t* out_len, const std::string& str) +inline int write_str_output(uint8_t out[], size_t* out_len, const std::string& str) { return write_output(out, out_len, reinterpret_cast<const uint8_t*>(str.c_str()), str.size() + 1); } -int write_str_output(char out[], size_t* out_len, const std::string& str) +inline int write_str_output(char out[], size_t* out_len, const std::string& str) { return write_str_output(reinterpret_cast<uint8_t*>(out), out_len, str); } @@ -899,15 +899,10 @@ int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate) int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash_fn, uint8_t out[], size_t* out_len) { - return apply_fn(key, BOTAN_CURRENT_FUNCTION, - [hash_fn,out,out_len](Botan::Public_Key& k) - { - std::unique_ptr<Botan::HashFunction> h(Botan::get_hash(hash_fn)); - auto z = h->process(k.x509_subject_public_key()); - *out_len = std::min(z.size(), *out_len); - Botan::copy_mem(out, &z[0], *out_len); - return 0; - }); + return BOTAN_FFI_DO(Botan::Public_Key, key, { + std::unique_ptr<Botan::HashFunction> h(Botan::get_hash(hash_fn)); + return write_vec_output(out, out_len, h->process(key.x509_subject_public_key())); + }); } int botan_pk_op_encrypt_create(botan_pk_op_encrypt_t* op, diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h index 34e706e2a..4b4d5904d 100644 --- a/src/lib/ffi/ffi.h +++ b/src/lib/ffi/ffi.h @@ -56,10 +56,9 @@ BOTAN_DLL int botan_same_mem(const uint8_t* x, const uint8_t* y, size_t len); typedef struct botan_rng_struct* botan_rng_t; BOTAN_DLL int botan_rng_init(botan_rng_t* rng, const char* rng_type); -BOTAN_DLL int botan_rng_destroy(botan_rng_t rng); - BOTAN_DLL int botan_rng_get(botan_rng_t rng, uint8_t* out, size_t out_len); BOTAN_DLL int botan_rng_reseed(botan_rng_t rng, size_t bits); +BOTAN_DLL int botan_rng_destroy(botan_rng_t rng); /* * Hashing @@ -67,12 +66,11 @@ BOTAN_DLL int botan_rng_reseed(botan_rng_t rng, size_t bits); typedef struct botan_hash_struct* botan_hash_t; BOTAN_DLL int botan_hash_init(botan_hash_t* hash, const char* hash_name, uint32_t flags); -BOTAN_DLL int botan_hash_destroy(botan_hash_t hash); -BOTAN_DLL int botan_hash_clear(botan_hash_t hash); - +BOTAN_DLL int botan_hash_output_length(botan_hash_t hash, size_t* output_length); BOTAN_DLL int botan_hash_update(botan_hash_t hash, const uint8_t* in, size_t in_len); BOTAN_DLL int botan_hash_final(botan_hash_t hash, uint8_t out[]); -BOTAN_DLL int botan_hash_output_length(botan_hash_t hash, size_t* output_length); +BOTAN_DLL int botan_hash_clear(botan_hash_t hash); +BOTAN_DLL int botan_hash_destroy(botan_hash_t hash); /* * Message Authentication @@ -80,13 +78,12 @@ BOTAN_DLL int botan_hash_output_length(botan_hash_t hash, size_t* output_length) typedef struct botan_mac_struct* botan_mac_t; BOTAN_DLL int botan_mac_init(botan_mac_t* mac, const char* mac_name, uint32_t flags); -BOTAN_DLL int botan_mac_destroy(botan_mac_t mac); -BOTAN_DLL int botan_mac_clear(botan_mac_t hash); - +BOTAN_DLL int botan_mac_output_length(botan_mac_t mac, size_t* output_length); BOTAN_DLL int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len); BOTAN_DLL int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len); BOTAN_DLL int botan_mac_final(botan_mac_t mac, uint8_t out[]); -BOTAN_DLL int botan_mac_output_length(botan_mac_t mac, size_t* output_length); +BOTAN_DLL int botan_mac_clear(botan_mac_t hash); +BOTAN_DLL int botan_mac_destroy(botan_mac_t mac); /* * Cipher modes @@ -94,8 +91,6 @@ BOTAN_DLL int botan_mac_output_length(botan_mac_t mac, size_t* output_length); typedef struct botan_cipher_struct* botan_cipher_t; BOTAN_DLL int botan_cipher_init(botan_cipher_t* cipher, const char* name, uint32_t flags); -BOTAN_DLL int botan_cipher_destroy(botan_cipher_t cipher); -BOTAN_DLL int botan_cipher_clear(botan_cipher_t hash); BOTAN_DLL int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl); BOTAN_DLL int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t* tag_size); @@ -121,6 +116,8 @@ BOTAN_DLL int botan_cipher_update(botan_cipher_t cipher, size_t input_size, size_t* input_consumed); +BOTAN_DLL int botan_cipher_clear(botan_cipher_t hash); +BOTAN_DLL int botan_cipher_destroy(botan_cipher_t cipher); /* * PBKDF @@ -159,8 +156,8 @@ BOTAN_DLL int botan_bcrypt_generate(uint8_t* out, size_t* out_len, /** * Returns 0 if if this password/hash combination is valid -* Returns 1 if the combination is not valid -* Returns -1 on error +* Returns 1 if the combination is not valid (but otherwise well formed) +* Returns negative on error */ BOTAN_DLL int botan_bcrypt_is_valid(const char* pass, const char* hash); @@ -305,20 +302,22 @@ BOTAN_DLL int botan_pk_op_key_agreement(botan_pk_op_ka_t op, const uint8_t salt[], size_t salt_len); /* -* TLS (not yet implemented) +* TLS (WIP) */ #if defined(BOTAN_HAS_TLS) && 0 typedef struct botan_tls_session_struct* botan_tls_session_t; -// TODO: getters on session_t +BOTAN_DLL int botan_tls_session_get_version(botan_tls_session_t* session, uint16_t* tls_version); +BOTAN_DLL int botan_tls_session_get_ciphersuite(botan_tls_session_t* session, uint16_t* ciphersuite); +// TODO: peer certs, validation, ... typedef struct botan_tls_channel_struct* botan_tls_channel_t; -typedef void (*botan_tls_channel_output_fn)(void, const uin8_t*, size_t); -typedef void (*botan_tls_channel_data_cb)(void, const uin8_t*, size_t); -typedef void (*botan_tls_channel_alert_cb)(void, u16bit, const char*); -typedef void (*botan_tls_channel_session_established)(void, botan_tls_session_t); +typedef void (*botan_tls_channel_output_fn)(void*, const uint8_t*, size_t); +typedef void (*botan_tls_channel_data_cb)(void*, const uint8_t*, size_t); +typedef void (*botan_tls_channel_alert_cb)(void*, uint16_t, const char*); +typedef void (*botan_tls_channel_session_established)(void*, botan_tls_session_t); BOTAN_DLL int botan_tls_channel_init_client(botan_tls_channel_t* channel, botan_tls_channel_output_fn output_fn, @@ -339,8 +338,9 @@ BOTAN_DLL int botan_tls_channel_received_data(botan_tls_channel_t chan, BOTAN_DLL int botan_tls_channel_send(botan_tls_channel_t chan, const uint8_t input[], size_t len); -BOTAN_DLL int botan_tls_channel_send_alert(botan_tls_channel_t chan, - uint16_t alert, bool fatal); +BOTAN_DLL int botan_tls_channel_close(botan_tls_channel_t chan); + +BOTAN_DLL int botan_tls_channel_destroy(botan_tls_channel_t chan); #endif |