From ba349b1a8751d6830fdeace466909d2cc6178cd1 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 3 Jul 2010 10:37:45 +0200 Subject: Allow encryption and decryption that are not in-place only. --- lib/crypto-api.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ lib/gnutls_cipher_int.c | 21 ++++++++++++++++++++ lib/gnutls_cipher_int.h | 4 ++++ lib/includes/gnutls/crypto.h | 5 +++++ lib/libgnutls.map | 2 ++ 5 files changed, 78 insertions(+) diff --git a/lib/crypto-api.c b/lib/crypto-api.c index cad9914132..1e61e4181b 100644 --- a/lib/crypto-api.c +++ b/lib/crypto-api.c @@ -101,6 +101,52 @@ gnutls_cipher_decrypt (gnutls_cipher_hd_t handle, void *ciphertext, ciphertextlen); } +/** + * gnutls_cipher_encrypt2: + * @handle: is a #gnutls_cipher_hd_t structure. + * @text: the data to encrypt + * @textlen: The length of data to encrypt + * @ciphertext: the encrypted data + * @ciphertextlen: The available length for encrypted data + * + * This function will encrypt the given data using the algorithm + * specified by the context. + * + * Returns: Zero or a negative value on error. + * + * Since: 2.10.0 + **/ +int +gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle, void *text, size_t textlen, + void* ciphertext, size_t ciphertextlen) +{ + return _gnutls_cipher_encrypt2 ((cipher_hd_st *) handle, text, textlen, + ciphertext, ciphertextlen); +} + +/** + * gnutls_cipher_decrypt2: + * @handle: is a #gnutls_cipher_hd_t structure. + * @ciphertext: the data to encrypt + * @ciphertextlen: The length of data to encrypt + * @text: the decrypted data + * @textlen: The available length for decrypted data + * + * This function will decrypt the given data using the algorithm + * specified by the context. + * + * Returns: Zero or a negative value on error. + * + * Since: 2.10.0 + **/ +int +gnutls_cipher_decrypt2 (gnutls_cipher_hd_t handle, const void *ciphertext, + size_t ciphertextlen, void* text, size_t textlen) +{ + return _gnutls_cipher_decrypt2 ((cipher_hd_st *) handle, ciphertext, + ciphertextlen, text, textlen); +} + /** * gnutls_cipher_deinit: * @handle: is a #gnutls_cipher_hd_t structure. diff --git a/lib/gnutls_cipher_int.c b/lib/gnutls_cipher_int.c index 4a830b8c19..023e459007 100644 --- a/lib/gnutls_cipher_int.c +++ b/lib/gnutls_cipher_int.c @@ -113,6 +113,27 @@ int _gnutls_cipher_decrypt (const cipher_hd_st * handle, void *ciphertext, return 0; } +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) diff --git a/lib/gnutls_cipher_int.h b/lib/gnutls_cipher_int.h index 81950f10fa..3131746a12 100644 --- a/lib/gnutls_cipher_int.h +++ b/lib/gnutls_cipher_int.h @@ -50,6 +50,10 @@ int _gnutls_cipher_encrypt (const cipher_hd_st * handle, void *text, int textlen); int _gnutls_cipher_decrypt (const cipher_hd_st * handle, void *ciphertext, int 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); void _gnutls_cipher_deinit (cipher_hd_st * handle); #endif /* GNUTLS_CIPHER_INT */ diff --git a/lib/includes/gnutls/crypto.h b/lib/includes/gnutls/crypto.h index 31352dd534..d121490f0d 100644 --- a/lib/includes/gnutls/crypto.h +++ b/lib/includes/gnutls/crypto.h @@ -35,6 +35,11 @@ int gnutls_cipher_encrypt (const gnutls_cipher_hd_t handle, void *text, size_t textlen); int gnutls_cipher_decrypt (const gnutls_cipher_hd_t handle, void *ciphertext, size_t ciphertextlen); +int gnutls_cipher_decrypt2 (gnutls_cipher_hd_t handle, const void *ciphertext, + size_t ciphertextlen, void* text, size_t textlen); +int gnutls_cipher_encrypt2 (gnutls_cipher_hd_t handle, void *text, size_t textlen, + void* ciphertext, size_t ciphertextlen); + void gnutls_cipher_deinit (gnutls_cipher_hd_t handle); int gnutls_cipher_get_block_size (gnutls_cipher_algorithm_t algorithm); diff --git a/lib/libgnutls.map b/lib/libgnutls.map index 47eed0cbcc..9b25b299e0 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -681,6 +681,8 @@ GNUTLS_2_11 gnutls_pk_bits_to_sec_param; gnutls_rnd; gnutls_x509_crq_get_preferred_hash_algorithm; + gnutls_cipher_encrypt2; + gnutls_cipher_decrypt2; } GNUTLS_2_10; GNUTLS_PRIVATE { -- cgit v1.2.1