]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tls packets are now send using one write(that way ssldump understands us)
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 25 Jan 2001 02:08:24 +0000 (02:08 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 25 Jan 2001 02:08:24 +0000 (02:08 +0000)
lib/gnutls.c
lib/gnutls_int.h

index 47ad4babad8dc11db035f34b48e996225bb1b15d..b01b9ddf09764dafd2b577bad9deb8b16293ae0d 100644 (file)
@@ -407,16 +407,14 @@ int gnutls_close_nowait(int cd, GNUTLS_STATE state)
  * send (if called by the user the Content is specific)
  * It is intended to transfer data, under the current state.    
  */
-#define MAX_ENC_LEN 16384
 ssize_t gnutls_send_int(int cd, GNUTLS_STATE state, ContentType type, void *_data, size_t sizeofdata, int flags)
 {
-       uint8 *cipher;
+       uint8 cipher[MAX_ENC_LEN];
        int i, cipher_size;
        int ret = 0;
        int iterations;
        uint16 length;
        int Size;
-       uint8 headers[5];
        uint8 *data=_data;
 
        if (sizeofdata == 0)
@@ -433,25 +431,20 @@ ssize_t gnutls_send_int(int cd, GNUTLS_STATE state, ContentType type, void *_dat
                Size = MAX_ENC_LEN;
        }
 
-       headers[0]=type;
-       headers[1]=state->connection_state.version.major;
-       headers[2]=state->connection_state.version.minor;
+       cipher[0]=type;
+       cipher[1]=state->connection_state.version.major;
+       cipher[2]=state->connection_state.version.minor;
        
        for (i = 0; i < iterations; i++) {
-               cipher_size = _gnutls_encrypt( state, &data[i*Size], Size, &cipher, type);
+               cipher_size = _gnutls_encrypt( state, &data[i*Size], Size, &cipher[5], type);
                if (cipher_size<=0) return cipher_size;
 #ifdef WORDS_BIGENDIAN
                length = cipher_size;
 #else
                length = byteswap16(cipher_size);
 #endif
-               memmove( &headers[3], &length, sizeof(uint16));
-               if (_gnutls_Write(cd, headers, sizeof(headers)) != sizeof(headers)) {
-                       state->gnutls_internals.valid_connection = VALID_FALSE;
-                       state->gnutls_internals.resumable = RESUME_FALSE;
-                       gnutls_assert();
-                       return GNUTLS_E_UNABLE_SEND_DATA;
-               }
+               memmove( &cipher[3], &length, sizeof(uint16));
+               cipher_size += HEADER_SIZE; /* add headers */
                if (_gnutls_Write(cd, cipher, cipher_size) != cipher_size) {
                        state->gnutls_internals.valid_connection = VALID_FALSE;
                        state->gnutls_internals.resumable = RESUME_FALSE;
@@ -463,20 +456,15 @@ ssize_t gnutls_send_int(int cd, GNUTLS_STATE state, ContentType type, void *_dat
                /* rest data */
        if (iterations > 1) {
                Size = sizeofdata % MAX_ENC_LEN;
-               cipher_size = _gnutls_encrypt( state, &data[i*Size], Size, &cipher, type);
+               cipher_size = _gnutls_encrypt( state, &data[i*Size], Size, &cipher[5], type);
                if (cipher_size<=0) return cipher_size;
 #ifdef WORDS_BIGENDIAN
                length = cipher_size;
 #else
                length = byteswap16(cipher_size);
 #endif
-               memmove( &headers[3], &length, sizeof(uint16));
-               if (_gnutls_Write(cd, headers, sizeof(headers)) != sizeof(headers)) {
-                       state->gnutls_internals.valid_connection = VALID_FALSE;
-                       state->gnutls_internals.resumable = RESUME_FALSE;
-                       gnutls_assert();
-                       return GNUTLS_E_UNABLE_SEND_DATA;
-               }
+               memmove( &cipher[3], &length, sizeof(uint16));
+               cipher_size+=HEADER_SIZE; /* add headers */
                if (_gnutls_Write(cd, cipher, cipher_size) != cipher_size) {
                        state->gnutls_internals.valid_connection = VALID_FALSE;
                        state->gnutls_internals.resumable = RESUME_FALSE;
@@ -488,8 +476,6 @@ ssize_t gnutls_send_int(int cd, GNUTLS_STATE state, ContentType type, void *_dat
 
        ret += sizeofdata;
 
-       gnutls_free(cipher);
-
        return ret;
 }
 
@@ -559,8 +545,6 @@ char peekdata;
  * flags is the sockets flags to use. Currently only MSG_DONTWAIT is
  * supported.
  */
-#define HEADER_SIZE 5
-#define MAX_RECV_SIZE 18432    /* 2^14+2048 */
 ssize_t gnutls_recv_int(int cd, GNUTLS_STATE state, ContentType type, char *data, size_t sizeofdata, int flags)
 {
        uint8 *tmpdata;
index 7c8c2a68ac197cfaeb9eb3b621a0f322f1d216b8..22e4b498ccb7692ea7a80b8a9f4bb101fba165fb 100644 (file)
 #define MAX24 16777215
 #define MAX16 65535
 
+/* the maximum size of encrypted packets */
+#define MAX_ENC_LEN 16384
+#define HEADER_SIZE 5
+#define MAX_RECV_SIZE 18432+HEADER_SIZE        /* 2^14+2048+HEADER_SIZE */
+
 /* for big numbers support */ /* FIXME */
 #include <gcrypt.h>