diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-08-19 11:52:20 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-08-19 11:52:20 +0000 |
commit | 4128d9c2a1441223f149de8856d0461d96f04eb4 (patch) | |
tree | 76bd2d97ceb579b6dbc5fa99747174b814eab194 /lib/gnutls_cipher.c | |
parent | fbfd62394b0a7b8dc0307af1bf5caa489b6b6184 (diff) | |
download | gnutls-4128d9c2a1441223f149de8856d0461d96f04eb4.tar.gz |
gnutls now sends (again) record packets using one write.
Diffstat (limited to 'lib/gnutls_cipher.c')
-rw-r--r-- | lib/gnutls_cipher.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c index 5ebd2496e9..3e5e7c1af7 100644 --- a/lib/gnutls_cipher.c +++ b/lib/gnutls_cipher.c @@ -33,6 +33,8 @@ #include "gnutls_record.h" #include "gnutls_constate.h" +/* returns ciphertext which contains RECORD_HEADER_SIZE unused bytes + */ int _gnutls_encrypt(GNUTLS_STATE state, const char *data, size_t data_size, uint8 ** ciphertext, ContentType type) { @@ -101,7 +103,8 @@ int _gnutls_decrypt(GNUTLS_STATE state, char *ciphertext, /* This is the actual encryption - * (and also keeps some space for headers in the encrypted data) + * (and also keeps some space for headers (RECORD_HEADER_SIZE) in the + * encrypted data) */ int _gnutls_compressed2TLSCiphertext(GNUTLS_STATE state, gnutls_datum* @@ -174,18 +177,11 @@ int _gnutls_compressed2TLSCiphertext(GNUTLS_STATE state, length = compressed.size + hash_size; - data = gnutls_malloc(length); + data = gnutls_malloc(length+RECORD_HEADER_SIZE); if (data==NULL) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } - memcpy(data, compressed.data, compressed.size); - memcpy(&data[compressed.size], MAC, hash_size); - - gnutls_cipher_encrypt(state->connection_state. - write_cipher_state, data, length); - cipher->data = data; - cipher->size = length; break; case CIPHER_BLOCK: @@ -212,20 +208,12 @@ int _gnutls_compressed2TLSCiphertext(GNUTLS_STATE state, pad = (uint8) (blocksize - (length % blocksize)) + rand; length += pad; - data = gnutls_malloc(length); + data = gnutls_malloc(length+RECORD_HEADER_SIZE); if (data==NULL) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } - memset(&data[length - pad], pad - 1, pad); - memcpy(data, compressed.data, compressed.size); - memcpy(&data[compressed.size], MAC, hash_size); - - gnutls_cipher_encrypt(state->connection_state. - write_cipher_state, data, length); - - cipher->data = data; - cipher->size = length; + memset(&data[RECORD_HEADER_SIZE + length - pad], pad - 1, pad); break; default: @@ -233,6 +221,15 @@ int _gnutls_compressed2TLSCiphertext(GNUTLS_STATE state, return GNUTLS_E_UNKNOWN_CIPHER_TYPE; } + memcpy(&data[RECORD_HEADER_SIZE], compressed.data, compressed.size); + memcpy(&data[compressed.size+RECORD_HEADER_SIZE], MAC, hash_size); + + gnutls_cipher_encrypt(state->connection_state. + write_cipher_state, &data[RECORD_HEADER_SIZE], + length); + cipher->data = data; + cipher->size = length + RECORD_HEADER_SIZE; + return 0; } |