From: Nikos Mavrogiannopoulos Date: Mon, 7 Feb 2011 08:24:24 +0000 (+0100) Subject: inlined several small functions. X-Git-Tag: gnutls_2_99_0~317 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d499f4e58afb40b577b50eec81d83f3c0ba3af41;p=thirdparty%2Fgnutls.git inlined several small functions. --- diff --git a/lib/gnutls_cipher_int.c b/lib/gnutls_cipher_int.c index 98ee868d75..8689a683ec 100644 --- a/lib/gnutls_cipher_int.c +++ b/lib/gnutls_cipher_int.c @@ -108,67 +108,6 @@ cc_cleanup: return ret; } -void _gnutls_cipher_setiv (const cipher_hd_st * handle, - const void *iv, int ivlen) -{ - handle->setiv(handle->handle, iv, ivlen); -} - -int -_gnutls_cipher_encrypt2 (const cipher_hd_st * handle, const void *text, - int textlen, void *ciphertext, int ciphertextlen) -{ - if (handle != NULL && handle->handle != NULL) - { - return handle->encrypt (handle->handle, text, textlen, ciphertext, - ciphertextlen); - } - - return 0; -} - -int -_gnutls_cipher_decrypt2 (const cipher_hd_st * handle, const void *ciphertext, - int ciphertextlen, void *text, int textlen) -{ - if (handle != NULL && handle->handle != NULL) - { - return handle->decrypt (handle->handle, ciphertext, ciphertextlen, - text, textlen); - } - - return 0; -} - -void -_gnutls_cipher_deinit (cipher_hd_st * handle) -{ - if (handle != NULL && handle->handle != NULL) - { - handle->deinit (handle->handle); - handle->handle = NULL; - } -} - -/* returns the tag in AUTHENC ciphers */ -void _gnutls_cipher_tag( const cipher_hd_st * handle, void* tag, int tag_size) -{ - if (handle != NULL && handle->handle != NULL) - { - handle->tag (handle->handle, tag, tag_size); - } -} - -int _gnutls_cipher_auth (const cipher_hd_st * handle, const void *text, - int textlen) -{ - if (handle != NULL && handle->handle != NULL) - { - return handle->auth (handle->handle, text, textlen); - } - return GNUTLS_E_INTERNAL_ERROR; -} - /* Auth_cipher API */ int _gnutls_auth_cipher_init (auth_cipher_hd_st * handle, diff --git a/lib/gnutls_cipher_int.h b/lib/gnutls_cipher_int.h index e5423f3767..989076182d 100644 --- a/lib/gnutls_cipher_int.h +++ b/lib/gnutls_cipher_int.h @@ -57,29 +57,72 @@ int _gnutls_cipher_init (cipher_hd_st *, gnutls_cipher_algorithm_t cipher, const gnutls_datum_t * key, const gnutls_datum_t * iv); -/* Add auth data for AUTHENC ciphers - */ -int _gnutls_cipher_auth (const cipher_hd_st * handle, const void *text, - int textlen); +inline static void _gnutls_cipher_setiv (const cipher_hd_st * handle, + const void *iv, int ivlen) +{ + handle->setiv(handle->handle, iv, ivlen); +} -void _gnutls_cipher_setiv (const cipher_hd_st * handle, const void *iv, - int ivlen); +inline static int +_gnutls_cipher_encrypt2 (const cipher_hd_st * handle, const void *text, + int textlen, void *ciphertext, int ciphertextlen) +{ + if (handle != NULL && handle->handle != NULL) + { + return handle->encrypt (handle->handle, text, textlen, ciphertext, + ciphertextlen); + } -int _gnutls_cipher_encrypt2 (const cipher_hd_st * handle, const void *text, - int textlen, void *ciphertext, - int ciphertextlen); -int _gnutls_cipher_decrypt2 (const cipher_hd_st * handle, - const void *ciphertext, int ciphertextlen, - void *text, int textlen); + return 0; +} + +inline static int +_gnutls_cipher_decrypt2 (const cipher_hd_st * handle, const void *ciphertext, + int ciphertextlen, void *text, int textlen) +{ + if (handle != NULL && handle->handle != NULL) + { + return handle->decrypt (handle->handle, ciphertext, ciphertextlen, + text, textlen); + } + + return 0; +} + +inline static void +_gnutls_cipher_deinit (cipher_hd_st * handle) +{ + if (handle != NULL && handle->handle != NULL) + { + handle->deinit (handle->handle); + handle->handle = NULL; + } +} /* returns the tag in AUTHENC ciphers */ -void _gnutls_cipher_tag( const cipher_hd_st * handle, void* tag, int tag_size); +inline static void _gnutls_cipher_tag( const cipher_hd_st * handle, void* tag, int tag_size) +{ + if (handle != NULL && handle->handle != NULL) + { + handle->tag (handle->handle, tag, tag_size); + } +} + +/* Add auth data for AUTHENC ciphers + */ +inline static int _gnutls_cipher_auth (const cipher_hd_st * handle, const void *text, + int textlen) +{ + if (handle != NULL && handle->handle != NULL) + { + return handle->auth (handle->handle, text, textlen); + } + return GNUTLS_E_INTERNAL_ERROR; +} #define _gnutls_cipher_encrypt(x,y,z) _gnutls_cipher_encrypt2(x,y,z,y,z) #define _gnutls_cipher_decrypt(x,y,z) _gnutls_cipher_decrypt2(x,y,z,y,z) -void _gnutls_cipher_deinit (cipher_hd_st * handle); - /* auth_cipher API. Allows combining a cipher with a MAC. */ diff --git a/lib/gnutls_hash_int.c b/lib/gnutls_hash_int.c index 645f5f10e5..54f3a7aa7a 100644 --- a/lib/gnutls_hash_int.c +++ b/lib/gnutls_hash_int.c @@ -103,6 +103,21 @@ _gnutls_hash_init (digest_hd_st * dig, gnutls_digest_algorithm_t algorithm) return 0; } +void +_gnutls_hash_deinit (digest_hd_st * handle, void *digest) +{ + if (handle->handle == NULL) + { + return; + } + + if (digest != NULL) + _gnutls_hash_output (handle, digest); + + handle->deinit (handle->handle); + handle->handle = NULL; +} + /* returns the output size of the given hash/mac algorithm */ int @@ -111,16 +126,6 @@ _gnutls_hash_get_algo_len (gnutls_digest_algorithm_t algorithm) return digest_length (algorithm); } -int -_gnutls_hash (digest_hd_st * handle, const void *text, size_t textlen) -{ - if (textlen > 0) - { - handle->hash (handle->handle, text, textlen); - } - return 0; -} - int _gnutls_hash_copy (digest_hd_st * dst, digest_hd_st * src) { @@ -136,46 +141,7 @@ _gnutls_hash_copy (digest_hd_st * dst, digest_hd_st * src) return src->copy (&dst->handle, src->handle); } -/* when the current output is needed without calling deinit - */ -void -_gnutls_hash_output (digest_hd_st * handle, void *digest) -{ - size_t maclen; - maclen = _gnutls_hash_get_algo_len (handle->algorithm); - - if (digest != NULL) - { - handle->output (handle->handle, digest, maclen); - } -} - -void -_gnutls_hash_deinit (digest_hd_st * handle, void *digest) -{ - if (handle->handle == NULL) - { - return; - } - - if (digest != NULL) - _gnutls_hash_output (handle, digest); - - handle->deinit (handle->handle); - handle->handle = NULL; -} - -void -_gnutls_hash_reset (digest_hd_st * handle) -{ - if (handle->handle == NULL) - { - return; - } - - handle->reset (handle->handle); -} int _gnutls_hash_fast (gnutls_digest_algorithm_t algorithm, @@ -206,12 +172,6 @@ _gnutls_hash_fast (gnutls_digest_algorithm_t algorithm, /* HMAC interface */ -int -_gnutls_hmac_get_algo_len (gnutls_mac_algorithm_t algorithm) -{ - return digest_length (algorithm); -} - int _gnutls_hmac_fast (gnutls_mac_algorithm_t algorithm, const void *key, int keylen, const void *text, size_t textlen, void *digest) @@ -297,29 +257,6 @@ _gnutls_hmac_init (digest_hd_st * dig, gnutls_mac_algorithm_t algorithm, return 0; } -int -_gnutls_hmac (digest_hd_st * handle, const void *text, size_t textlen) -{ - if (textlen > 0) - { - return handle->hash (handle->handle, text, textlen); - } - return 0; -} - -void -_gnutls_hmac_output (digest_hd_st * handle, void *digest) -{ - int maclen; - - maclen = _gnutls_hmac_get_algo_len (handle->algorithm); - - if (digest != NULL) - { - handle->output (handle->handle, digest, maclen); - } -} - void _gnutls_hmac_deinit (digest_hd_st * handle, void *digest) { @@ -335,17 +272,6 @@ _gnutls_hmac_deinit (digest_hd_st * handle, void *digest) handle->handle = NULL; } -void -_gnutls_hmac_reset (digest_hd_st * handle) -{ - if (handle->handle == NULL) - { - return; - } - - handle->reset (handle->handle); -} - inline static int get_padsize (gnutls_mac_algorithm_t algorithm) { @@ -360,7 +286,6 @@ get_padsize (gnutls_mac_algorithm_t algorithm) } } - /* Special functions for SSL3 MAC */ diff --git a/lib/gnutls_hash_int.h b/lib/gnutls_hash_int.h index f191bb04cf..d0bcf145c6 100644 --- a/lib/gnutls_hash_int.h +++ b/lib/gnutls_hash_int.h @@ -62,23 +62,91 @@ typedef struct /* basic functions */ int _gnutls_hmac_init (digest_hd_st *, gnutls_mac_algorithm_t algorithm, const void *key, int keylen); -int _gnutls_hmac_get_algo_len (gnutls_mac_algorithm_t algorithm); -int _gnutls_hmac (digest_hd_st * handle, const void *text, size_t textlen); -void _gnutls_hmac_reset (digest_hd_st * handle); - +int _gnutls_hash_get_algo_len (gnutls_digest_algorithm_t algorithm); +#define _gnutls_hmac_get_algo_len _gnutls_hash_get_algo_len int _gnutls_hmac_fast (gnutls_mac_algorithm_t algorithm, const void *key, int keylen, const void *text, size_t textlen, void *digest); -void _gnutls_hmac_deinit (digest_hd_st * handle, void *digest); -void _gnutls_hmac_output (digest_hd_st * handle, void *digest); +inline static int +_gnutls_hmac (digest_hd_st * handle, const void *text, size_t textlen) +{ + if (textlen > 0) + { + return handle->hash (handle->handle, text, textlen); + } + return 0; +} + +inline static void +_gnutls_hmac_output (digest_hd_st * handle, void *digest) +{ + int maclen; + + maclen = _gnutls_hmac_get_algo_len (handle->algorithm); + + if (digest != NULL) + { + handle->output (handle->handle, digest, maclen); + } +} + +void +_gnutls_hmac_deinit (digest_hd_st * handle, void *digest); + +inline static void +_gnutls_hmac_reset (digest_hd_st * handle) +{ + if (handle->handle == NULL) + { + return; + } + + handle->reset (handle->handle); +} + +/* Hash interface */ int _gnutls_hash_init (digest_hd_st *, gnutls_digest_algorithm_t algorithm); -int _gnutls_hash_get_algo_len (gnutls_digest_algorithm_t algorithm); -int _gnutls_hash (digest_hd_st * handle, const void *text, size_t textlen); -void _gnutls_hash_deinit (digest_hd_st * handle, void *digest); -void _gnutls_hash_reset (digest_hd_st * handle); -void _gnutls_hash_output (digest_hd_st * handle, void *digest); + +inline static int +_gnutls_hash (digest_hd_st * handle, const void *text, size_t textlen) +{ + if (textlen > 0) + { + handle->hash (handle->handle, text, textlen); + } + return 0; +} + +/* when the current output is needed without calling deinit + */ +inline static void +_gnutls_hash_output (digest_hd_st * handle, void *digest) +{ + size_t maclen; + + maclen = _gnutls_hash_get_algo_len (handle->algorithm); + + if (digest != NULL) + { + handle->output (handle->handle, digest, maclen); + } +} + +inline static void +_gnutls_hash_reset (digest_hd_st * handle) +{ + if (handle->handle == NULL) + { + return; + } + + handle->reset (handle->handle); +} + +void +_gnutls_hash_deinit (digest_hd_st * handle, void *digest); int _gnutls_hash_fast (gnutls_digest_algorithm_t algorithm,