[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 04/11] cleanup: use ssh_ prefix in the buffer (non-static) functions


Having "ssh_" prefix in the functions' name will avoid possible clashes
when compiling libssh statically.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 include/libssh/buffer.h          |  34 +++++-----
 src/agent.c                      |  30 ++++-----
 src/auth.c                       |   6 +-
 src/auth1.c                      |   8 +--
 src/buffer.c                     |  94 ++++++++++++++--------------
 src/channels.c                   |  60 +++++++++---------
 src/channels1.c                  |  42 ++++++-------
 src/dh.c                         |  36 +++++------
 src/gssapi.c                     |  14 ++---
 src/gzip.c                       |  14 ++---
 src/kex.c                        |  18 +++---
 src/kex1.c                       |  32 +++++-----
 src/known_hosts.c                |  16 ++---
 src/messages.c                   |  22 +++----
 src/packet.c                     |  42 ++++++-------
 src/packet1.c                    |  22 +++----
 src/packet_cb.c                  |   4 +-
 src/packet_crypt.c               |   2 +-
 src/pcap.c                       |  44 ++++++-------
 src/pki.c                        |  50 +++++++--------
 src/pki_container_openssh.c      |  10 +--
 src/pki_gcrypt.c                 |  28 ++++-----
 src/server.c                     |  10 +--
 src/sftp.c                       | 130 +++++++++++++++++++--------------------
 src/sftpserver.c                 |  48 +++++++--------
 src/socket.c                     |  18 +++---
 tests/unittests/torture_buffer.c |  70 ++++++++++-----------
 27 files changed, 452 insertions(+), 452 deletions(-)

diff --git a/include/libssh/buffer.h b/include/libssh/buffer.h
index 826d0b7..c56ac73 100644
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -46,11 +46,11 @@ LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
 LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
 LIBSSH_API ssh_buffer ssh_buffer_new(void);
 void ssh_buffer_set_secure(ssh_buffer buffer);
-int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
-int buffer_add_u8(ssh_buffer buffer, uint8_t data);
-int buffer_add_u16(ssh_buffer buffer, uint16_t data);
-int buffer_add_u32(ssh_buffer buffer, uint32_t data);
-int buffer_add_u64(ssh_buffer buffer, uint64_t data);
+int ssh_buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
+int ssh_buffer_add_u8(ssh_buffer buffer, uint8_t data);
+int ssh_buffer_add_u16(ssh_buffer buffer, uint16_t data);
+int ssh_buffer_add_u32(ssh_buffer buffer, uint32_t data);
+int ssh_buffer_add_u64(ssh_buffer buffer, uint64_t data);
 int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
 
 int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
@@ -74,27 +74,27 @@ int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
 #define ssh_buffer_unpack(buffer, format, ...) \
     _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
 
-int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
-int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
+int ssh_buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
+int ssh_buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
 int ssh_buffer_reinit(ssh_buffer buffer);
 
 /* buffer_get_rest returns a pointer to the current position into the buffer */
-void *buffer_get_rest(ssh_buffer buffer);
+void *ssh_buffer_get_rest(ssh_buffer buffer);
 /* buffer_get_rest_len returns the number of bytes which can be read */
-uint32_t buffer_get_rest_len(ssh_buffer buffer);
+uint32_t ssh_buffer_get_rest_len(ssh_buffer buffer);
 
 /* buffer_read_*() returns the number of bytes read, except for ssh strings */
-int buffer_get_u8(ssh_buffer buffer, uint8_t *data);
-int buffer_get_u32(ssh_buffer buffer, uint32_t *data);
-int buffer_get_u64(ssh_buffer buffer, uint64_t *data);
+int ssh_buffer_get_u8(ssh_buffer buffer, uint8_t *data);
+int ssh_buffer_get_u32(ssh_buffer buffer, uint32_t *data);
+int ssh_buffer_get_u64(ssh_buffer buffer, uint64_t *data);
 
-uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
+uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
 /* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
-ssh_string buffer_get_ssh_string(ssh_buffer buffer);
+ssh_string ssh_buffer_get_ssh_string(ssh_buffer buffer);
 /* gets a string out of a SSH-1 mpint */
-ssh_string buffer_get_mpint(ssh_buffer buffer);
+ssh_string ssh_buffer_get_mpint(ssh_buffer buffer);
 /* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
-uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
-uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
+uint32_t ssh_buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
+uint32_t ssh_buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
 
 #endif /* BUFFER_H_ */
diff --git a/src/agent.c b/src/agent.c
index 1cbb9cd..804ee50 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -273,13 +273,13 @@ static int agent_talk(struct ssh_session_struct *session,
   uint32_t len = 0;
   uint8_t payload[1024] = {0};
 
-  len = buffer_get_rest_len(request);
+  len = ssh_buffer_get_rest_len(request);
   SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
   agent_put_u32(payload, len);
 
   /* send length and then the request packet */
   if (atomicio(session->agent, payload, 4, 0) == 4) {
-    if (atomicio(session->agent, buffer_get_rest(request), len, 0)
+    if (atomicio(session->agent, ssh_buffer_get_rest(request), len, 0)
         != len) {
       SSH_LOG(SSH_LOG_WARN, "atomicio sending request failed: %s",
           strerror(errno));
@@ -354,7 +354,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
       ssh_set_error_oom(session);
       return -1;
   }
-  if (buffer_add_u8(request, c1) < 0) {
+  if (ssh_buffer_add_u8(request, c1) < 0) {
       ssh_set_error_oom(session);
       ssh_buffer_free(request);
       return -1;
@@ -375,7 +375,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
   ssh_buffer_free(request);
 
   /* get message type and verify the answer */
-  rc = buffer_get_u8(reply, (uint8_t *) &type);
+  rc = ssh_buffer_get_u8(reply, (uint8_t *) &type);
   if (rc != sizeof(uint8_t)) {
     ssh_set_error(session, SSH_FATAL,
         "Bad authentication reply size: %d", rc);
@@ -397,7 +397,7 @@ int ssh_agent_get_ident_count(struct ssh_session_struct *session) {
       return -1;
   }
 
-  buffer_get_u32(reply, (uint32_t *) buf);
+  ssh_buffer_get_u32(reply, (uint32_t *) buf);
   session->agent->count = agent_get_u32(buf);
   SSH_LOG(SSH_LOG_DEBUG, "Agent count: %d",
       session->agent->count);
@@ -444,13 +444,13 @@ ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session,
             return NULL;
         case 2:
             /* get the blob */
-            blob = buffer_get_ssh_string(session->agent->ident);
+            blob = ssh_buffer_get_ssh_string(session->agent->ident);
             if (blob == NULL) {
                 return NULL;
             }
 
             /* get the comment */
-            tmp = buffer_get_ssh_string(session->agent->ident);
+            tmp = ssh_buffer_get_ssh_string(session->agent->ident);
             if (tmp == NULL) {
                 ssh_string_free(blob);
 
@@ -518,7 +518,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
     }
 
     /* create request */
-    if (buffer_add_u8(request, SSH2_AGENTC_SIGN_REQUEST) < 0) {
+    if (ssh_buffer_add_u8(request, SSH2_AGENTC_SIGN_REQUEST) < 0) {
         ssh_buffer_free(request);
         return NULL;
     }
@@ -530,7 +530,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
     }
 
     /* adds len + blob */
-    rc = buffer_add_ssh_string(request, key_blob);
+    rc = ssh_buffer_add_ssh_string(request, key_blob);
     ssh_string_free(key_blob);
     if (rc < 0) {
         ssh_buffer_free(request);
@@ -538,17 +538,17 @@ ssh_string ssh_agent_sign_data(ssh_session session,
     }
 
     /* Add data */
-    dlen = buffer_get_rest_len(data);
-    if (buffer_add_u32(request, htonl(dlen)) < 0) {
+    dlen = ssh_buffer_get_rest_len(data);
+    if (ssh_buffer_add_u32(request, htonl(dlen)) < 0) {
         ssh_buffer_free(request);
         return NULL;
     }
-    if (ssh_buffer_add_data(request, buffer_get_rest(data), dlen) < 0) {
+    if (ssh_buffer_add_data(request, ssh_buffer_get_rest(data), dlen) < 0) {
         ssh_buffer_free(request);
         return NULL;
     }
 
-    if (buffer_add_u32(request, htonl(flags)) < 0) {
+    if (ssh_buffer_add_u32(request, htonl(flags)) < 0) {
         ssh_buffer_free(request);
         return NULL;
     }
@@ -568,7 +568,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
     ssh_buffer_free(request);
 
     /* check if reply is valid */
-    if (buffer_get_u8(reply, (uint8_t *) &type) != sizeof(uint8_t)) {
+    if (ssh_buffer_get_u8(reply, (uint8_t *) &type) != sizeof(uint8_t)) {
         ssh_buffer_free(reply);
         return NULL;
     }
@@ -583,7 +583,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
         return NULL;
     }
 
-    sig_blob = buffer_get_ssh_string(reply);
+    sig_blob = ssh_buffer_get_ssh_string(reply);
     ssh_buffer_free(reply);
 
     return sig_blob;
diff --git a/src/auth.c b/src/auth.c
index eeed8c3..c2cf52f 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -158,7 +158,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_banner){
   (void)type;
   (void)user;
 
-  banner = buffer_get_ssh_string(packet);
+  banner = ssh_buffer_get_ssh_string(packet);
   if (banner == NULL) {
     SSH_LOG(SSH_LOG_WARN,
         "Invalid SSH_USERAUTH_BANNER packet");
@@ -615,7 +615,7 @@ int ssh_userauth_publickey(ssh_session session,
         goto fail;
     }
 
-    rc = buffer_add_ssh_string(session->out_buffer, str);
+    rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
     ssh_string_free(str);
     str = NULL;
     if (rc < 0) {
@@ -700,7 +700,7 @@ static int ssh_userauth_agent_publickey(ssh_session session,
         goto fail;
     }
 
-    rc = buffer_add_ssh_string(session->out_buffer, str);
+    rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
     ssh_string_free(str);
     if (rc < 0) {
         goto fail;
diff --git a/src/auth1.c b/src/auth1.c
index a65c447..e808763 100644
--- a/src/auth1.c
+++ b/src/auth1.c
@@ -103,11 +103,11 @@ static int send_username(ssh_session session, const char *username) {
     return SSH_AUTH_ERROR;
   }
 
-  if (buffer_add_u8(session->out_buffer, SSH_CMSG_USER) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_USER) < 0) {
     ssh_string_free(user);
     return SSH_AUTH_ERROR;
   }
-  if (buffer_add_ssh_string(session->out_buffer, user) < 0) {
+  if (ssh_buffer_add_ssh_string(session->out_buffer, user) < 0) {
     ssh_string_free(user);
     return SSH_AUTH_ERROR;
   }
@@ -197,13 +197,13 @@ int ssh_userauth1_password(ssh_session session, const char *username,
     ssh_string_fill(pwd, buf, sizeof(buf));
   }
 
-  if (buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_AUTH_PASSWORD) < 0) {
     ssh_string_burn(pwd);
     ssh_string_free(pwd);
 
     return SSH_AUTH_ERROR;
   }
-  if (buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
+  if (ssh_buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
     ssh_string_burn(pwd);
     ssh_string_free(pwd);
 
diff --git a/src/buffer.c b/src/buffer.c
index 0a33ae3..a327aa6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -257,7 +257,7 @@ int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint
  *
  * @return              0 on success, < 0 on error.
  */
-int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
+int ssh_buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
     struct ssh_string_struct *string) {
   uint32_t len = 0;
 
@@ -284,7 +284,7 @@ int buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
  *
  * @return              0 on success, -1 on error.
  */
-int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
+int ssh_buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
 {
     int rc;
 
@@ -307,7 +307,7 @@ int buffer_add_u32(struct ssh_buffer_struct *buffer,uint32_t data)
  *
  * @return              0 on success, -1 on error.
  */
-int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
+int ssh_buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
 {
     int rc;
 
@@ -330,7 +330,7 @@ int buffer_add_u16(struct ssh_buffer_struct *buffer,uint16_t data)
  *
  * @return              0 on success, -1 on error.
  */
-int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
+int ssh_buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
 {
     int rc;
 
@@ -353,7 +353,7 @@ int buffer_add_u64(struct ssh_buffer_struct *buffer, uint64_t data)
  *
  * @return              0 on success, -1 on error.
  */
-int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
+int ssh_buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
 {
     int rc;
 
@@ -378,7 +378,7 @@ int buffer_add_u8(struct ssh_buffer_struct *buffer,uint8_t data)
  *
  * @return              0 on success, -1 on error.
  */
-int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
+int ssh_buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
     uint32_t len) {
   buffer_verify(buffer);
 
@@ -419,14 +419,14 @@ int buffer_prepend_data(struct ssh_buffer_struct *buffer, const void *data,
  *
  * @return              0 on success, -1 on error.
  */
-int buffer_add_buffer(struct ssh_buffer_struct *buffer,
+int ssh_buffer_add_buffer(struct ssh_buffer_struct *buffer,
     struct ssh_buffer_struct *source)
 {
     int rc;
 
     rc = ssh_buffer_add_data(buffer,
-                             buffer_get_rest(source),
-                             buffer_get_rest_len(source));
+                             ssh_buffer_get_rest(source),
+                             ssh_buffer_get_rest_len(source));
     if (rc < 0) {
         return -1;
     }
@@ -444,8 +444,8 @@ int buffer_add_buffer(struct ssh_buffer_struct *buffer,
  *
  * @warning Don't expect data to be nul-terminated.
  *
- * @see buffer_get_rest()
- * @see buffer_get_len()
+ * @see ssh_buffer_get_rest()
+ * @see ssh_buffer_get_len()
  */
 void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
   return buffer->data;
@@ -460,10 +460,10 @@ void *ssh_buffer_get_begin(struct ssh_buffer_struct *buffer){
  *
  * @return              A pointer to the data from current position.
  *
- * @see buffer_get_rest_len()
- * @see buffer_get()
+ * @see ssh_buffer_get_rest_len()
+ * @see ssh_buffer_get()
  */
-void *buffer_get_rest(struct ssh_buffer_struct *buffer){
+void *ssh_buffer_get_rest(struct ssh_buffer_struct *buffer){
     return buffer->data + buffer->pos;
 }
 
@@ -474,7 +474,7 @@ void *buffer_get_rest(struct ssh_buffer_struct *buffer){
  *
  * @return              The length of the buffer.
  *
- * @see buffer_get()
+ * @see ssh_buffer_get()
  */
 uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
     return buffer->used;
@@ -489,9 +489,9 @@ uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  *
  * @return              The length of the buffer.
  *
- * @see buffer_get_rest()
+ * @see ssh_buffer_get_rest()
  */
-uint32_t buffer_get_rest_len(struct ssh_buffer_struct *buffer){
+uint32_t ssh_buffer_get_rest_len(struct ssh_buffer_struct *buffer){
   buffer_verify(buffer);
   return buffer->used - buffer->pos;
 }
@@ -509,7 +509,7 @@ uint32_t buffer_get_rest_len(struct ssh_buffer_struct *buffer){
  *
  * @return              The new size of the buffer.
  */
-uint32_t buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
+uint32_t ssh_buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
     buffer_verify(buffer);
 
     if (buffer->pos + len < len || buffer->used < buffer->pos + len) {
@@ -537,7 +537,7 @@ uint32_t buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
  *
  * @return              The new size of the buffer.
  */
-uint32_t buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
+uint32_t ssh_buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
   buffer_verify(buffer);
 
   if (buffer->used < len) {
@@ -562,7 +562,7 @@ uint32_t buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
  *
  * @returns             0 if there is not enough data in buffer, len otherwise.
  */
-uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
+uint32_t ssh_buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len){
     /*
      * Check for a integer overflow first, then check if not enough data is in
      * the buffer.
@@ -587,8 +587,8 @@ uint32_t buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t
  *
  * @returns             0 if there is not enough data in buffer, 1 otherwise.
  */
-int buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
-    return buffer_get_data(buffer,data,sizeof(uint8_t));
+int ssh_buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
+    return ssh_buffer_get_data(buffer,data,sizeof(uint8_t));
 }
 
 /** \internal
@@ -598,8 +598,8 @@ int buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
  * \returns 0 if there is not enough data in buffer
  * \returns 4 otherwise.
  */
-int buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
-    return buffer_get_data(buffer,data,sizeof(uint32_t));
+int ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
+    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
 }
 /**
  * @internal
@@ -613,8 +613,8 @@ int buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  *
  * @returns             0 if there is not enough data in buffer, 8 otherwise.
  */
-int buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
-    return buffer_get_data(buffer,data,sizeof(uint64_t));
+int ssh_buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
+    return ssh_buffer_get_data(buffer,data,sizeof(uint64_t));
 }
 
 /**
@@ -626,12 +626,12 @@ int buffer_get_u64(struct ssh_buffer_struct *buffer, uint64_t *data){
  *
  * @returns             The SSH String, NULL on error.
  */
-struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer) {
+struct ssh_string_struct *ssh_buffer_get_ssh_string(struct ssh_buffer_struct *buffer) {
   uint32_t stringlen;
   uint32_t hostlen;
   struct ssh_string_struct *str = NULL;
 
-  if (buffer_get_u32(buffer, &stringlen) == 0) {
+  if (ssh_buffer_get_u32(buffer, &stringlen) == 0) {
     return NULL;
   }
   hostlen = ntohl(stringlen);
@@ -643,7 +643,7 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
   if (str == NULL) {
     return NULL;
   }
-  if (buffer_get_data(buffer, ssh_string_data(str), hostlen) != hostlen) {
+  if (ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen) != hostlen) {
     /* should never happen */
     SAFE_FREE(str);
     return NULL;
@@ -663,12 +663,12 @@ struct ssh_string_struct *buffer_get_ssh_string(struct ssh_buffer_struct *buffer
  *
  * @returns             The SSH String containing the mpint, NULL on error.
  */
-struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
+struct ssh_string_struct *ssh_buffer_get_mpint(struct ssh_buffer_struct *buffer) {
   uint16_t bits;
   uint32_t len;
   struct ssh_string_struct *str = NULL;
 
-  if (buffer_get_data(buffer, &bits, sizeof(uint16_t)) != sizeof(uint16_t)) {
+  if (ssh_buffer_get_data(buffer, &bits, sizeof(uint16_t)) != sizeof(uint16_t)) {
     return NULL;
   }
   bits = ntohs(bits);
@@ -680,7 +680,7 @@ struct ssh_string_struct *buffer_get_mpint(struct ssh_buffer_struct *buffer) {
   if (str == NULL) {
     return NULL;
   }
-  if (buffer_get_data(buffer, ssh_string_data(str), len) != len) {
+  if (ssh_buffer_get_data(buffer, ssh_string_data(str), len) != len) {
     SAFE_FREE(str);
     return NULL;
   }
@@ -725,32 +725,32 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
         switch(*p) {
         case 'b':
             o.byte = (uint8_t)va_arg(ap, unsigned int);
-            rc = buffer_add_u8(buffer, o.byte);
+            rc = ssh_buffer_add_u8(buffer, o.byte);
             break;
         case 'w':
             o.word = (uint16_t)va_arg(ap, unsigned int);
             o.word = htons(o.word);
-            rc = buffer_add_u16(buffer, o.word);
+            rc = ssh_buffer_add_u16(buffer, o.word);
             break;
         case 'd':
             o.dword = va_arg(ap, uint32_t);
             o.dword = htonl(o.dword);
-            rc = buffer_add_u32(buffer, o.dword);
+            rc = ssh_buffer_add_u32(buffer, o.dword);
             break;
         case 'q':
             o.qword = va_arg(ap, uint64_t);
             o.qword = htonll(o.qword);
-            rc = buffer_add_u64(buffer, o.qword);
+            rc = ssh_buffer_add_u64(buffer, o.qword);
             break;
         case 'S':
             o.string = va_arg(ap, ssh_string);
-            rc = buffer_add_ssh_string(buffer, o.string);
+            rc = ssh_buffer_add_ssh_string(buffer, o.string);
             o.string = NULL;
             break;
         case 's':
             cstring = va_arg(ap, char *);
             len = strlen(cstring);
-            rc = buffer_add_u32(buffer, htonl(len));
+            rc = ssh_buffer_add_u32(buffer, htonl(len));
             if (rc == SSH_OK){
                 rc = ssh_buffer_add_data(buffer, cstring, len);
             }
@@ -772,7 +772,7 @@ int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
                 rc = SSH_ERROR;
                 break;
             }
-            rc = buffer_add_ssh_string(buffer, o.string);
+            rc = ssh_buffer_add_ssh_string(buffer, o.string);
             SAFE_FREE(o.string);
             break;
         case 't':
@@ -885,37 +885,37 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
         switch (*p) {
         case 'b':
             o.byte = va_arg(ap, uint8_t *);
-            rlen = buffer_get_u8(buffer, o.byte);
+            rlen = ssh_buffer_get_u8(buffer, o.byte);
             rc = rlen==1 ? SSH_OK : SSH_ERROR;
             break;
         case 'w':
             o.word = va_arg(ap,  uint16_t *);
-            rlen = buffer_get_data(buffer, o.word, sizeof(uint16_t));
+            rlen = ssh_buffer_get_data(buffer, o.word, sizeof(uint16_t));
             *o.word = ntohs(*o.word);
             rc = rlen==2 ? SSH_OK : SSH_ERROR;
             break;
         case 'd':
             o.dword = va_arg(ap, uint32_t *);
-            rlen = buffer_get_u32(buffer, o.dword);
+            rlen = ssh_buffer_get_u32(buffer, o.dword);
             *o.dword = ntohl(*o.dword);
             rc = rlen==4 ? SSH_OK : SSH_ERROR;
             break;
         case 'q':
             o.qword = va_arg(ap, uint64_t*);
-            rlen = buffer_get_u64(buffer, o.qword);
+            rlen = ssh_buffer_get_u64(buffer, o.qword);
             *o.qword = ntohll(*o.qword);
             rc = rlen==8 ? SSH_OK : SSH_ERROR;
             break;
         case 'S':
             o.string = va_arg(ap, ssh_string *);
-            *o.string = buffer_get_ssh_string(buffer);
+            *o.string = ssh_buffer_get_ssh_string(buffer);
             rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
             o.string = NULL;
             break;
         case 's':
             o.cstring = va_arg(ap, char **);
             *o.cstring = NULL;
-            rc = buffer_get_u32(buffer, &u32len);
+            rc = ssh_buffer_get_u32(buffer, &u32len);
             if (rc != 4){
                 rc = SSH_ERROR;
                 break;
@@ -930,7 +930,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
                 rc = SSH_ERROR;
                 break;
             }
-            rlen = buffer_get_data(buffer, *o.cstring, len);
+            rlen = ssh_buffer_get_data(buffer, *o.cstring, len);
             if (rlen != len){
                 SAFE_FREE(*o.cstring);
                 rc = SSH_ERROR;
@@ -951,7 +951,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
                 rc = SSH_ERROR;
                 break;
             }
-            rlen = buffer_get_data(buffer, *o.data, len);
+            rlen = ssh_buffer_get_data(buffer, *o.data, len);
             if (rlen != len){
                 SAFE_FREE(*o.data);
                 rc = SSH_ERROR;
diff --git a/src/channels.c b/src/channels.c
index d8cd190..84e9608 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -286,7 +286,7 @@ static int channel_open(ssh_channel channel, const char *type, int window,
   }
 
   if (payload != NULL) {
-    if (buffer_add_buffer(session->out_buffer, payload) < 0) {
+    if (ssh_buffer_add_buffer(session->out_buffer, payload) < 0) {
       ssh_set_error_oom(session);
 
       return err;
@@ -492,10 +492,10 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
   if (is_stderr) {
     uint32_t ignore;
     /* uint32 data type code. we can ignore it */
-    buffer_get_u32(packet, &ignore);
+    ssh_buffer_get_u32(packet, &ignore);
   }
 
-  str = buffer_get_ssh_string(packet);
+  str = ssh_buffer_get_ssh_string(packet);
   if (str == NULL) {
     SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
 
@@ -546,17 +546,17 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
       }
       rest = channel->callbacks->channel_data_function(channel->session,
                                                 channel,
-                                                buffer_get_rest(buf),
-                                                buffer_get_rest_len(buf),
+                                                ssh_buffer_get_rest(buf),
+                                                ssh_buffer_get_rest_len(buf),
                                                 is_stderr,
                                                 channel->callbacks->userdata);
       if(rest > 0) {
         if (channel->counter != NULL) {
             channel->counter->in_bytes += rest;
         }
-        buffer_pass_bytes(buf, rest);
+        ssh_buffer_pass_bytes(buf, rest);
       }
-      if (channel->local_window + buffer_get_rest_len(buf) < WINDOWLIMIT) {
+      if (channel->local_window + ssh_buffer_get_rest_len(buf) < WINDOWLIMIT) {
         if (grow_window(session, channel, 0) < 0) {
           return -1;
         }
@@ -612,9 +612,9 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
 			channel->remote_channel);
 
 	if ((channel->stdout_buffer &&
-			buffer_get_rest_len(channel->stdout_buffer) > 0) ||
+			ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
 			(channel->stderr_buffer &&
-					buffer_get_rest_len(channel->stderr_buffer) > 0)) {
+					ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
 		channel->delayed_close = 1;
 	} else {
 		channel->state = SSH_CHANNEL_STATE_CLOSED;
@@ -1414,9 +1414,9 @@ int ssh_channel_is_eof(ssh_channel channel) {
       return SSH_ERROR;
   }
   if ((channel->stdout_buffer &&
-        buffer_get_rest_len(channel->stdout_buffer) > 0) ||
+        ssh_buffer_get_rest_len(channel->stdout_buffer) > 0) ||
       (channel->stderr_buffer &&
-       buffer_get_rest_len(channel->stderr_buffer) > 0)) {
+       ssh_buffer_get_rest_len(channel->stderr_buffer) > 0)) {
     return 0;
   }
 
@@ -1540,8 +1540,8 @@ static int channel_request(ssh_channel channel, const char *request,
   }
 
   if (buffer != NULL) {
-    if (ssh_buffer_add_data(session->out_buffer, buffer_get_rest(buffer),
-        buffer_get_rest_len(buffer)) < 0) {
+    if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get_rest(buffer),
+        ssh_buffer_get_rest_len(buffer)) < 0) {
       ssh_set_error_oom(session);
       goto error;
     }
@@ -2099,8 +2099,8 @@ static int global_request(ssh_session session, const char *request,
 
   if (buffer != NULL) {
       rc = ssh_buffer_add_data(session->out_buffer,
-                           buffer_get_rest(buffer),
-                           buffer_get_rest_len(buffer));
+                           ssh_buffer_get_rest(buffer),
+                           ssh_buffer_get_rest_len(buffer));
       if (rc < 0) {
           ssh_set_error_oom(session);
           rc = SSH_ERROR;
@@ -2584,7 +2584,7 @@ struct ssh_channel_read_termination_struct {
 
 static int ssh_channel_read_termination(void *s){
   struct ssh_channel_read_termination_struct *ctx = s;
-  if (buffer_get_rest_len(ctx->buffer) >= ctx->count ||
+  if (ssh_buffer_get_rest_len(ctx->buffer) >= ctx->count ||
       ctx->channel->remote_eof ||
       ctx->channel->session->session_state == SSH_SESSION_STATE_ERROR)
     return 1;
@@ -2681,11 +2681,11 @@ int ssh_channel_read_timeout(ssh_channel channel,
   SSH_LOG(SSH_LOG_PACKET,
       "Read (%d) buffered : %d bytes. Window: %d",
       count,
-      buffer_get_rest_len(stdbuf),
+      ssh_buffer_get_rest_len(stdbuf),
       channel->local_window);
 
-  if (count > buffer_get_rest_len(stdbuf) + channel->local_window) {
-    if (grow_window(session, channel, count - buffer_get_rest_len(stdbuf)) < 0) {
+  if (count > ssh_buffer_get_rest_len(stdbuf) + channel->local_window) {
+    if (grow_window(session, channel, count - ssh_buffer_get_rest_len(stdbuf)) < 0) {
       return -1;
     }
   }
@@ -2711,14 +2711,14 @@ int ssh_channel_read_timeout(ssh_channel channel,
   if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
       return SSH_ERROR;
   }
-  if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) {
+  if (channel->remote_eof && ssh_buffer_get_rest_len(stdbuf) == 0) {
     return 0;
   }
-  len = buffer_get_rest_len(stdbuf);
+  len = ssh_buffer_get_rest_len(stdbuf);
   /* Read count bytes if len is greater, everything otherwise */
   len = (len > count ? count : len);
-  memcpy(dest, buffer_get_rest(stdbuf), len);
-  buffer_pass_bytes(stdbuf,len);
+  memcpy(dest, ssh_buffer_get_rest(stdbuf), len);
+  ssh_buffer_pass_bytes(stdbuf,len);
   if (channel->counter != NULL) {
       channel->counter->in_bytes += len;
   }
@@ -2818,7 +2818,7 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
     stdbuf = channel->stderr_buffer;
   }
 
-  if (buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
+  if (ssh_buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
     if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
       return SSH_ERROR;
     }
@@ -2827,15 +2827,15 @@ int ssh_channel_poll(ssh_channel channel, int is_stderr){
     }
   }
 
-  if (buffer_get_rest_len(stdbuf) > 0){
-  	return buffer_get_rest_len(stdbuf);
+  if (ssh_buffer_get_rest_len(stdbuf) > 0){
+  	return ssh_buffer_get_rest_len(stdbuf);
   }
 
   if (channel->remote_eof) {
     return SSH_EOF;
   }
 
-  return buffer_get_rest_len(stdbuf);
+  return ssh_buffer_get_rest_len(stdbuf);
 }
 
 /**
@@ -2882,7 +2882,7 @@ int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr){
     rc = SSH_ERROR;
     goto end;
   }
-  rc = buffer_get_rest_len(stdbuf);
+  rc = ssh_buffer_get_rest_len(stdbuf);
   if(rc > 0)
     goto end;
   if (channel->remote_eof)
@@ -2971,8 +2971,8 @@ static int channel_protocol_select(ssh_channel *rchans, ssh_channel *wchans,
       ssh_handle_packets(chan->session, SSH_TIMEOUT_NONBLOCKING);
     }
 
-    if ((chan->stdout_buffer && buffer_get_rest_len(chan->stdout_buffer) > 0) ||
-        (chan->stderr_buffer && buffer_get_rest_len(chan->stderr_buffer) > 0) ||
+    if ((chan->stdout_buffer && ssh_buffer_get_rest_len(chan->stdout_buffer) > 0) ||
+        (chan->stderr_buffer && ssh_buffer_get_rest_len(chan->stderr_buffer) > 0) ||
         chan->remote_eof) {
       rout[j] = chan;
       j++;
diff --git a/src/channels1.c b/src/channels1.c
index 4b7d268..c3e7b92 100644
--- a/src/channels1.c
+++ b/src/channels1.c
@@ -112,18 +112,18 @@ int channel_request_pty_size1(ssh_channel channel, const char *terminal, int col
     return -1;
   }
 
-  if (buffer_add_u8(session->out_buffer, SSH_CMSG_REQUEST_PTY) < 0 ||
-      buffer_add_ssh_string(session->out_buffer, str) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_REQUEST_PTY) < 0 ||
+      ssh_buffer_add_ssh_string(session->out_buffer, str) < 0) {
     ssh_string_free(str);
     return -1;
   }
   ssh_string_free(str);
 
-  if (buffer_add_u32(session->out_buffer, ntohl(row)) < 0 ||
-      buffer_add_u32(session->out_buffer, ntohl(col)) < 0 ||
-      buffer_add_u32(session->out_buffer, 0) < 0 || /* x */
-      buffer_add_u32(session->out_buffer, 0) < 0 || /* y */
-      buffer_add_u8(session->out_buffer, 0) < 0) { /* tty things */
+  if (ssh_buffer_add_u32(session->out_buffer, ntohl(row)) < 0 ||
+      ssh_buffer_add_u32(session->out_buffer, ntohl(col)) < 0 ||
+      ssh_buffer_add_u32(session->out_buffer, 0) < 0 || /* x */
+      ssh_buffer_add_u32(session->out_buffer, 0) < 0 || /* y */
+      ssh_buffer_add_u8(session->out_buffer, 0) < 0) { /* tty things */
     return -1;
   }
 
@@ -170,11 +170,11 @@ int channel_change_pty_size1(ssh_channel channel, int cols, int rows) {
     ssh_set_error(session,SSH_REQUEST_DENIED,"Wrong request state");
     return SSH_ERROR;
   }
-  if (buffer_add_u8(session->out_buffer, SSH_CMSG_WINDOW_SIZE) < 0 ||
-      buffer_add_u32(session->out_buffer, ntohl(rows)) < 0 ||
-      buffer_add_u32(session->out_buffer, ntohl(cols)) < 0 ||
-      buffer_add_u32(session->out_buffer, 0) < 0 ||
-      buffer_add_u32(session->out_buffer, 0) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_WINDOW_SIZE) < 0 ||
+      ssh_buffer_add_u32(session->out_buffer, ntohl(rows)) < 0 ||
+      ssh_buffer_add_u32(session->out_buffer, ntohl(cols)) < 0 ||
+      ssh_buffer_add_u32(session->out_buffer, 0) < 0 ||
+      ssh_buffer_add_u32(session->out_buffer, 0) < 0) {
     return SSH_ERROR;
   }
   channel->request_state=SSH_CHANNEL_REQ_STATE_PENDING;
@@ -215,7 +215,7 @@ int channel_request_shell1(ssh_channel channel) {
   }
   session = channel->session;
 
-  if (buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer,SSH_CMSG_EXEC_SHELL) < 0) {
     return -1;
   }
 
@@ -242,8 +242,8 @@ int channel_request_exec1(ssh_channel channel, const char *cmd) {
     return -1;
   }
 
-  if (buffer_add_u8(session->out_buffer, SSH_CMSG_EXEC_CMD) < 0 ||
-      buffer_add_ssh_string(session->out_buffer, command) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_EXEC_CMD) < 0 ||
+      ssh_buffer_add_ssh_string(session->out_buffer, command) < 0) {
     ssh_string_free(command);
     return -1;
   }
@@ -268,7 +268,7 @@ SSH_PACKET_CALLBACK(ssh_packet_data1){
       return SSH_PACKET_NOT_USED;
     }
 
-    str = buffer_get_ssh_string(packet);
+    str = ssh_buffer_get_ssh_string(packet);
     if (str == NULL) {
       SSH_LOG(SSH_LOG_FUNCTIONS, "Invalid data packet !\n");
       return SSH_PACKET_USED;
@@ -300,7 +300,7 @@ SSH_PACKET_CALLBACK(ssh_packet_close1){
     return SSH_PACKET_NOT_USED;
   }
 
-  buffer_get_u32(packet, &status);
+  ssh_buffer_get_u32(packet, &status);
   /*
    * It's much more than a channel closing. spec says it's the last
    * message sent by server (strange)
@@ -310,7 +310,7 @@ SSH_PACKET_CALLBACK(ssh_packet_close1){
   channel->state = SSH_CHANNEL_STATE_CLOSED;
   channel->remote_eof = 1;
 
-  rc = buffer_add_u8(session->out_buffer, SSH_CMSG_EXIT_CONFIRMATION);
+  rc = ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_EXIT_CONFIRMATION);
   if (rc < 0) {
     return SSH_PACKET_NOT_USED;
   }
@@ -329,7 +329,7 @@ SSH_PACKET_CALLBACK(ssh_packet_exist_status1){
     return SSH_PACKET_NOT_USED;
   }
 
-  buffer_get_u32(packet, &status);
+  ssh_buffer_get_u32(packet, &status);
   channel->state = SSH_CHANNEL_STATE_CLOSED;
   channel->remote_eof = 1;
   channel->exit_status = ntohl(status);
@@ -350,13 +350,13 @@ int channel_write1(ssh_channel channel, const void *data, int len) {
   session = channel->session;
 
   while (len > 0) {
-    if (buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) {
+    if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_STDIN_DATA) < 0) {
       return -1;
     }
 
     effectivelen = len > 32000 ? 32000 : len;
 
-    if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
+    if (ssh_buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
         ssh_buffer_add_data(session->out_buffer, ptr, effectivelen) < 0) {
       return -1;
     }
diff --git a/src/dh.c b/src/dh.c
index b372b2c..1d2367b 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -472,14 +472,14 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
   ssh_string pubkey = NULL;
   ssh_string signature = NULL;
   int rc;
-  pubkey = buffer_get_ssh_string(packet);
+  pubkey = ssh_buffer_get_ssh_string(packet);
   if (pubkey == NULL){
     ssh_set_error(session,SSH_FATAL, "No public key in packet");
     goto error;
   }
   dh_import_pubkey(session, pubkey);
 
-  f = buffer_get_ssh_string(packet);
+  f = ssh_buffer_get_ssh_string(packet);
   if (f == NULL) {
     ssh_set_error(session,SSH_FATAL, "No F number in packet");
     goto error;
@@ -492,7 +492,7 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
     goto error;
   }
 
-  signature = buffer_get_ssh_string(packet);
+  signature = ssh_buffer_get_ssh_string(packet);
   if (signature == NULL) {
     ssh_set_error(session, SSH_FATAL, "No signature in packet");
     goto error;
@@ -505,7 +505,7 @@ int ssh_client_dh_reply(ssh_session session, ssh_buffer packet){
   }
 
   /* Send the MSG_NEWKEYS */
-  if (buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
     goto error;
   }
 
@@ -550,22 +550,22 @@ int make_sessionid(ssh_session session) {
      *      boolean      first_kex_packet_follows
      *      uint32       0 (reserved for future extension)
      */
-    rc = buffer_add_u8(server_hash, 0);
+    rc = ssh_buffer_add_u8(server_hash, 0);
     if (rc < 0) {
         goto error;
     }
-    rc = buffer_add_u32(server_hash, 0);
+    rc = ssh_buffer_add_u32(server_hash, 0);
     if (rc < 0) {
         goto error;
     }
 
     /* These fields are handled for the server case in ssh_packet_kexinit. */
     if (session->client) {
-        rc = buffer_add_u8(client_hash, 0);
+        rc = ssh_buffer_add_u8(client_hash, 0);
         if (rc < 0) {
             goto error;
         }
-        rc = buffer_add_u32(client_hash, 0);
+        rc = ssh_buffer_add_u32(client_hash, 0);
         if (rc < 0) {
             goto error;
         }
@@ -573,12 +573,12 @@ int make_sessionid(ssh_session session) {
 
     rc = ssh_buffer_pack(buf,
                          "dPdPS",
-                         buffer_get_rest_len(client_hash),
-                         buffer_get_rest_len(client_hash),
-                         buffer_get_rest(client_hash),
-                         buffer_get_rest_len(server_hash),
-                         buffer_get_rest_len(server_hash),
-                         buffer_get_rest(server_hash),
+                         ssh_buffer_get_rest_len(client_hash),
+                         ssh_buffer_get_rest_len(client_hash),
+                         ssh_buffer_get_rest(client_hash),
+                         ssh_buffer_get_rest_len(server_hash),
+                         ssh_buffer_get_rest_len(server_hash),
+                         ssh_buffer_get_rest(server_hash),
                          session->next_crypto->server_pubkey);
 
     if(rc != SSH_OK){
@@ -643,7 +643,7 @@ int make_sessionid(ssh_session session) {
             ssh_set_error_oom(session);
             goto error;
         }
-        sha1(buffer_get_rest(buf), buffer_get_rest_len(buf),
+        sha1(ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf),
                                    session->next_crypto->secret_hash);
         break;
     case SSH_KEX_ECDH_SHA2_NISTP256:
@@ -655,7 +655,7 @@ int make_sessionid(ssh_session session) {
             ssh_set_error_oom(session);
             goto error;
         }
-        sha256(buffer_get_rest(buf), buffer_get_rest_len(buf),
+        sha256(ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf),
                                      session->next_crypto->secret_hash);
         break;
     }
@@ -698,7 +698,7 @@ int hashbufout_add_cookie(ssh_session session) {
     return -1;
   }
 
-  if (buffer_add_u8(session->out_hashbuf, 20) < 0) {
+  if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
     ssh_buffer_reinit(session->out_hashbuf);
     return -1;
   }
@@ -726,7 +726,7 @@ int hashbufin_add_cookie(ssh_session session, unsigned char *cookie) {
     return -1;
   }
 
-  if (buffer_add_u8(session->in_hashbuf, 20) < 0) {
+  if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
     ssh_buffer_reinit(session->in_hashbuf);
     return -1;
   }
diff --git a/src/gssapi.c b/src/gssapi.c
index 099294e..09f0d93 100644
--- a/src/gssapi.c
+++ b/src/gssapi.c
@@ -115,8 +115,8 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token){
  * @param[in] oid the OID that was selected for authentication
  */
 static int ssh_gssapi_send_response(ssh_session session, ssh_string oid){
-    if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE) < 0 ||
-            buffer_add_ssh_string(session->out_buffer,oid) < 0) {
+    if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE) < 0 ||
+            ssh_buffer_add_ssh_string(session->out_buffer,oid) < 0) {
         ssh_set_error_oom(session);
         return SSH_ERROR;
     }
@@ -293,7 +293,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server){
         ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_USERAUTH_GSSAPI_TOKEN in invalid state");
         return SSH_PACKET_USED;
     }
-    token = buffer_get_ssh_string(packet);
+    token = ssh_buffer_get_ssh_string(packet);
 
     if (token == NULL){
         ssh_set_error(session, SSH_REQUEST_DENIED, "ssh_packet_userauth_gssapi_token: invalid packet");
@@ -409,7 +409,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_mic)
     (void)type;
 
     SSH_LOG(SSH_LOG_PACKET,"Received SSH_MSG_USERAUTH_GSSAPI_MIC");
-    mic_token = buffer_get_ssh_string(packet);
+    mic_token = ssh_buffer_get_ssh_string(packet);
     if (mic_token == NULL) {
         ssh_set_error(session, SSH_FATAL, "Missing MIC in packet");
         goto error;
@@ -533,7 +533,7 @@ static int ssh_gssapi_send_auth_mic(ssh_session session, ssh_string *oid_set, in
     }
 
     for (i=0; i<n_oid; ++i){
-        rc = buffer_add_ssh_string(session->out_buffer, oid_set[i]);
+        rc = ssh_buffer_add_ssh_string(session->out_buffer, oid_set[i]);
         if (rc < 0) {
             goto fail;
         }
@@ -732,7 +732,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_response){
         ssh_set_error(session, SSH_FATAL, "Invalid state in ssh_packet_userauth_gssapi_response");
         return SSH_PACKET_USED;
     }
-    oid_s = buffer_get_ssh_string(packet);
+    oid_s = ssh_buffer_get_ssh_string(packet);
     if (!oid_s){
         ssh_set_error(session, SSH_FATAL, "Missing OID");
         return SSH_PACKET_USED;
@@ -828,7 +828,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client){
         ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_USERAUTH_GSSAPI_TOKEN in invalid state");
         return SSH_PACKET_USED;
     }
-    token = buffer_get_ssh_string(packet);
+    token = ssh_buffer_get_ssh_string(packet);
 
     if (token == NULL){
         ssh_set_error(session, SSH_REQUEST_DENIED, "ssh_packet_userauth_gssapi_token: invalid packet");
diff --git a/src/gzip.c b/src/gzip.c
index ca190bc..0a14084 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -58,8 +58,8 @@ static z_stream *initcompress(ssh_session session, int level) {
 
 static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level){
   z_stream *zout = session->current_crypto->compress_out_ctx;
-  void *in_ptr = buffer_get_rest(source);
-  unsigned long in_size = buffer_get_rest_len(source);
+  void *in_ptr = ssh_buffer_get_rest(source);
+  unsigned long in_size = ssh_buffer_get_rest_len(source);
   ssh_buffer dest = NULL;
   unsigned char out_buf[BLOCKSIZE] = {0};
   unsigned long len;
@@ -113,7 +113,7 @@ int compress_buffer(ssh_session session, ssh_buffer buf) {
     return -1;
   }
 
-  if (ssh_buffer_add_data(buf, buffer_get_rest(dest), buffer_get_rest_len(dest)) < 0) {
+  if (ssh_buffer_add_data(buf, ssh_buffer_get_rest(dest), ssh_buffer_get_rest_len(dest)) < 0) {
     ssh_buffer_free(dest);
     return -1;
   }
@@ -147,8 +147,8 @@ static z_stream *initdecompress(ssh_session session) {
 
 static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t maxlen) {
   z_stream *zin = session->current_crypto->compress_in_ctx;
-  void *in_ptr = buffer_get_rest(source);
-  unsigned long in_size = buffer_get_rest_len(source);
+  void *in_ptr = ssh_buffer_get_rest(source);
+  unsigned long in_size = ssh_buffer_get_rest_len(source);
   unsigned char out_buf[BLOCKSIZE] = {0};
   ssh_buffer dest = NULL;
   unsigned long len;
@@ -185,7 +185,7 @@ static ssh_buffer gzip_decompress(ssh_session session, ssh_buffer source, size_t
       ssh_buffer_free(dest);
       return NULL;
     }
-    if (buffer_get_rest_len(dest) > maxlen){
+    if (ssh_buffer_get_rest_len(dest) > maxlen){
       /* Size of packet exceeded, avoid a denial of service attack */
       ssh_buffer_free(dest);
       return NULL;
@@ -209,7 +209,7 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen){
     return -1;
   }
 
-  if (ssh_buffer_add_data(buf, buffer_get_rest(dest), buffer_get_rest_len(dest)) < 0) {
+  if (ssh_buffer_add_data(buf, ssh_buffer_get_rest(dest), ssh_buffer_get_rest_len(dest)) < 0) {
     ssh_buffer_free(dest);
     return -1;
   }
diff --git a/src/kex.c b/src/kex.c
index 519d79c..02965bd 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -346,7 +346,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
     }
 
     if (server_kex) {
-        rc = buffer_get_data(packet,session->next_crypto->client_kex.cookie, 16);
+        rc = ssh_buffer_get_data(packet,session->next_crypto->client_kex.cookie, 16);
         if (rc != 16) {
             ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet");
             goto error;
@@ -358,7 +358,7 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
             goto error;
         }
     } else {
-        rc = buffer_get_data(packet,session->next_crypto->server_kex.cookie, 16);
+        rc = ssh_buffer_get_data(packet,session->next_crypto->server_kex.cookie, 16);
         if (rc != 16) {
             ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet");
             goto error;
@@ -372,12 +372,12 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
     }
 
     for (i = 0; i < KEX_METHODS_SIZE; i++) {
-        str = buffer_get_ssh_string(packet);
+        str = ssh_buffer_get_ssh_string(packet);
         if (str == NULL) {
           goto error;
         }
 
-        rc = buffer_add_ssh_string(session->in_hashbuf, str);
+        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
         if (rc < 0) {
             ssh_set_error(session, SSH_FATAL, "Error adding string in hash buffer");
             goto error;
@@ -414,17 +414,17 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){
      * 'make_sessionid').
      */
     if (server_kex) {
-        rc = buffer_get_u8(packet, &first_kex_packet_follows);
+        rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
         if (rc != 1) {
             goto error;
         }
 
-        rc = buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
+        rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
         if (rc < 0) {
             goto error;
         }
 
-        rc = buffer_add_u32(session->in_hashbuf, kexinit_reserved);
+        rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
         if (rc < 0) {
             goto error;
         }
@@ -624,10 +624,10 @@ int ssh_send_kex(ssh_session session, int server_kex) {
       goto error;
     }
 
-    if (buffer_add_ssh_string(session->out_hashbuf, str) < 0) {
+    if (ssh_buffer_add_ssh_string(session->out_hashbuf, str) < 0) {
       goto error;
     }
-    if (buffer_add_ssh_string(session->out_buffer, str) < 0) {
+    if (ssh_buffer_add_ssh_string(session->out_buffer, str) < 0) {
       goto error;
     }
     ssh_string_free(str);
diff --git a/src/kex1.c b/src/kex1.c
index 758054f..9e0794d 100644
--- a/src/kex1.c
+++ b/src/kex1.c
@@ -51,13 +51,13 @@ static ssh_string make_rsa1_string(ssh_string e, ssh_string n){
       goto error;
   }
 
-  if (buffer_add_ssh_string(buffer, rsa) < 0) {
+  if (ssh_buffer_add_ssh_string(buffer, rsa) < 0) {
     goto error;
   }
-  if (buffer_add_ssh_string(buffer, e) < 0) {
+  if (ssh_buffer_add_ssh_string(buffer, e) < 0) {
     goto error;
   }
-  if (buffer_add_ssh_string(buffer, n) < 0) {
+  if (ssh_buffer_add_ssh_string(buffer, n) < 0) {
     goto error;
   }
 
@@ -325,32 +325,32 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
     ssh_set_error(session,SSH_FATAL,"SSH_KEXINIT received in wrong state");
     goto error;
   }
-  if (buffer_get_data(packet, session->next_crypto->server_kex.cookie, 8) != 8) {
+  if (ssh_buffer_get_data(packet, session->next_crypto->server_kex.cookie, 8) != 8) {
     ssh_set_error(session, SSH_FATAL, "Can't get cookie in buffer");
     goto error;
   }
 
-  buffer_get_u32(packet, &server_bits);
-  server_exp = buffer_get_mpint(packet);
+  ssh_buffer_get_u32(packet, &server_bits);
+  server_exp = ssh_buffer_get_mpint(packet);
   if (server_exp == NULL) {
     goto error;
   }
-  server_mod = buffer_get_mpint(packet);
+  server_mod = ssh_buffer_get_mpint(packet);
   if (server_mod == NULL) {
     goto error;
   }
-  buffer_get_u32(packet, &host_bits);
-  host_exp = buffer_get_mpint(packet);
+  ssh_buffer_get_u32(packet, &host_bits);
+  host_exp = ssh_buffer_get_mpint(packet);
   if (host_exp == NULL) {
     goto error;
   }
-  host_mod = buffer_get_mpint(packet);
+  host_mod = ssh_buffer_get_mpint(packet);
   if (host_mod == NULL) {
     goto error;
   }
-  buffer_get_u32(packet, &protocol_flags);
-  buffer_get_u32(packet, &supported_ciphers_mask);
-  ko = buffer_get_u32(packet, &supported_authentications_mask);
+  ssh_buffer_get_u32(packet, &protocol_flags);
+  ssh_buffer_get_u32(packet, &supported_ciphers_mask);
+  ko = ssh_buffer_get_u32(packet, &supported_authentications_mask);
 
   if ((ko != sizeof(uint32_t)) || !host_mod || !host_exp
       || !server_mod || !server_exp) {
@@ -411,10 +411,10 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
   }
   SSH_LOG(SSH_LOG_PROTOCOL, "Sending SSH_CMSG_SESSION_KEY");
 
-   if (buffer_add_u8(session->out_buffer, SSH_CMSG_SESSION_KEY) < 0) {
+   if (ssh_buffer_add_u8(session->out_buffer, SSH_CMSG_SESSION_KEY) < 0) {
      goto error;
    }
-   if (buffer_add_u8(session->out_buffer, support_3DES ? SSH_CIPHER_3DES : SSH_CIPHER_DES) < 0) {
+   if (ssh_buffer_add_u8(session->out_buffer, support_3DES ? SSH_CIPHER_3DES : SSH_CIPHER_DES) < 0) {
      goto error;
    }
    if (ssh_buffer_add_data(session->out_buffer, session->next_crypto->server_kex.cookie, 8) < 0) {
@@ -439,7 +439,7 @@ SSH_PACKET_CALLBACK(ssh_packet_publickey1){
      goto error;
    }
    /* the protocol flags */
-   if (buffer_add_u32(session->out_buffer, 0) < 0) {
+   if (ssh_buffer_add_u32(session->out_buffer, 0) < 0) {
      goto error;
    }
    session->session_state=SSH_SESSION_STATE_KEXINIT_RECEIVED;
diff --git a/src/known_hosts.c b/src/known_hosts.c
index d87af43..263289f 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -211,7 +211,7 @@ static int check_public_key(ssh_session session, char **tokens) {
       return -1;
     }
 
-    if (buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
+    if (ssh_buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
       ssh_buffer_free(pubkey_buffer);
       ssh_string_free(tmpstring);
       return -1;
@@ -244,7 +244,7 @@ static int check_public_key(ssh_session session, char **tokens) {
       bignum_bn2bin(tmpbn, ssh_string_data(tmpstring));
 #endif
       bignum_free(tmpbn);
-      if (buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
+      if (ssh_buffer_add_ssh_string(pubkey_buffer, tmpstring) < 0) {
         ssh_buffer_free(pubkey_buffer);
         ssh_string_free(tmpstring);
         bignum_free(tmpbn);
@@ -264,14 +264,14 @@ static int check_public_key(ssh_session session, char **tokens) {
     return -1;
   }
 
-  if (buffer_get_rest_len(pubkey_buffer) != ssh_string_len(pubkey)) {
+  if (ssh_buffer_get_rest_len(pubkey_buffer) != ssh_string_len(pubkey)) {
     ssh_buffer_free(pubkey_buffer);
     return 0;
   }
 
   /* now test that they are identical */
-  if (memcmp(buffer_get_rest(pubkey_buffer), ssh_string_data(pubkey),
-        buffer_get_rest_len(pubkey_buffer)) != 0) {
+  if (memcmp(ssh_buffer_get_rest(pubkey_buffer), ssh_string_data(pubkey),
+        ssh_buffer_get_rest_len(pubkey_buffer)) != 0) {
     ssh_buffer_free(pubkey_buffer);
     return 0;
   }
@@ -340,7 +340,7 @@ static int match_hashed_host(const char *host, const char *sourcehash)
     return 0;
   }
 
-  mac = hmac_init(buffer_get_rest(salt), buffer_get_rest_len(salt), SSH_HMAC_SHA1);
+  mac = hmac_init(ssh_buffer_get_rest(salt), ssh_buffer_get_rest_len(salt), SSH_HMAC_SHA1);
   if (mac == NULL) {
     ssh_buffer_free(salt);
     ssh_buffer_free(hash);
@@ -351,8 +351,8 @@ static int match_hashed_host(const char *host, const char *sourcehash)
   hmac_update(mac, host, strlen(host));
   hmac_final(mac, buffer, &size);
 
-  if (size == buffer_get_rest_len(hash) &&
-      memcmp(buffer, buffer_get_rest(hash), size) == 0) {
+  if (size == ssh_buffer_get_rest_len(hash) &&
+      memcmp(buffer, ssh_buffer_get_rest(hash), size) == 0) {
     match = 1;
   } else {
     match = 0;
diff --git a/src/messages.c b/src/messages.c
index ec53877..bd93b58 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -81,9 +81,9 @@ static ssh_message ssh_message_new(ssh_session session){
 static int ssh_message_reply_default(ssh_message msg) {
   SSH_LOG(SSH_LOG_FUNCTIONS, "Reporting unknown packet");
 
-  if (buffer_add_u8(msg->session->out_buffer, SSH2_MSG_UNIMPLEMENTED) < 0)
+  if (ssh_buffer_add_u8(msg->session->out_buffer, SSH2_MSG_UNIMPLEMENTED) < 0)
     goto error;
-  if (buffer_add_u32(msg->session->out_buffer,
+  if (ssh_buffer_add_u32(msg->session->out_buffer,
       htonl(msg->session->recv_seq-1)) < 0)
     goto error;
   return packet_send(msg->session);
@@ -579,7 +579,7 @@ SSH_PACKET_CALLBACK(ssh_packet_service_request){
 
   (void)type;
   (void)user;
-  service = buffer_get_ssh_string(packet);
+  service = ssh_buffer_get_ssh_string(packet);
   if (service == NULL) {
     ssh_set_error(session, SSH_FATAL, "Invalid SSH_MSG_SERVICE_REQUEST packet");
     goto error;
@@ -712,7 +712,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
     ssh_string submethods = NULL;
 
     msg->auth_request.method = SSH_AUTH_METHOD_INTERACTIVE;
-    lang = buffer_get_ssh_string(packet);
+    lang = ssh_buffer_get_ssh_string(packet);
     if (lang == NULL) {
       goto error;
     }
@@ -722,7 +722,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
      */
     ssh_string_free(lang);
 
-    submethods = buffer_get_ssh_string(packet);
+    submethods = ssh_buffer_get_ssh_string(packet);
     if (submethods == NULL) {
       goto error;
     }
@@ -768,7 +768,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
         ssh_string sig_blob = NULL;
         ssh_buffer digest = NULL;
 
-        sig_blob = buffer_get_ssh_string(packet);
+        sig_blob = ssh_buffer_get_ssh_string(packet);
         if(sig_blob == NULL) {
             SSH_LOG(SSH_LOG_PACKET, "Invalid signature packet from peer");
             msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_ERROR;
@@ -786,8 +786,8 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
         rc = ssh_pki_signature_verify_blob(session,
                                            sig_blob,
                                            msg->auth_request.pubkey,
-                                           buffer_get_rest(digest),
-                                           buffer_get_rest_len(digest));
+                                           ssh_buffer_get_rest(digest),
+                                           ssh_buffer_get_rest_len(digest));
         ssh_string_free(sig_blob);
         ssh_buffer_free(digest);
         if (rc < 0) {
@@ -811,7 +811,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
      ssh_string oid;
      char *hexa;
      int i;
-     buffer_get_u32(packet, &n_oid);
+     ssh_buffer_get_u32(packet, &n_oid);
      n_oid=ntohl(n_oid);
      if(n_oid > 100){
     	 ssh_set_error(session, SSH_FATAL, "USERAUTH_REQUEST: gssapi-with-mic OID count too big (%d)",n_oid);
@@ -824,7 +824,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_request){
     	 goto error;
      }
      for (i=0;i<(int) n_oid;++i){
-    	 oid=buffer_get_ssh_string(packet);
+    	 oid=ssh_buffer_get_ssh_string(packet);
     	 if(oid == NULL){
     		 for(i=i-1;i>=0;--i){
     			 SAFE_FREE(oids[i]);
@@ -969,7 +969,7 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response){
   memset(session->kbdint->answers, 0, nanswers * sizeof(char *));
 
   for (i = 0; i < nanswers; i++) {
-    tmp = buffer_get_ssh_string(packet);
+    tmp = ssh_buffer_get_ssh_string(packet);
     if (tmp == NULL) {
       ssh_set_error(session, SSH_FATAL, "Short INFO_RESPONSE packet");
       session->kbdint->nanswers = i;
diff --git a/src/packet.c b/src/packet.c
index d16cd16..4636f26 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -253,11 +253,11 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
                  * Decrypt the rest of the packet (blocksize bytes already
                  * have been decrypted)
                  */
-                uint32_t buffer_len = buffer_get_rest_len(session->in_buffer);
+                uint32_t buffer_len = ssh_buffer_get_rest_len(session->in_buffer);
 
                 /* The following check avoids decrypting zero bytes */
                 if (buffer_len > blocksize) {
-                    uint8_t *payload = ((uint8_t*)buffer_get_rest(session->in_buffer) + blocksize);
+                    uint8_t *payload = ((uint8_t*)ssh_buffer_get_rest(session->in_buffer) + blocksize);
                     uint32_t plen = buffer_len - blocksize;
 
                     rc = packet_decrypt(session, payload, plen);
@@ -280,9 +280,9 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
             }
 
             /* skip the size field which has been processed before */
-            buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
+            ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 
-            rc = buffer_get_u8(session->in_buffer, &padding);
+            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
             if (rc == 0) {
                 ssh_set_error(session,
                               SSH_FATAL,
@@ -290,28 +290,28 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
                 goto error;
             }
 
-            if (padding > buffer_get_rest_len(session->in_buffer)) {
+            if (padding > ssh_buffer_get_rest_len(session->in_buffer)) {
                 ssh_set_error(session,
                               SSH_FATAL,
                               "Invalid padding: %d (%d left)",
                               padding,
-                              buffer_get_rest_len(session->in_buffer));
+                              ssh_buffer_get_rest_len(session->in_buffer));
                 goto error;
             }
-            buffer_pass_bytes_end(session->in_buffer, padding);
-            compsize = buffer_get_rest_len(session->in_buffer);
+            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
+            compsize = ssh_buffer_get_rest_len(session->in_buffer);
 
 #ifdef WITH_ZLIB
             if (session->current_crypto
                 && session->current_crypto->do_compress_in
-                && buffer_get_rest_len(session->in_buffer) > 0) {
+                && ssh_buffer_get_rest_len(session->in_buffer) > 0) {
                 rc = decompress_buffer(session, session->in_buffer,MAX_PACKET_LEN);
                 if (rc < 0) {
                     goto error;
                 }
             }
 #endif /* WITH_ZLIB */
-            payloadsize = buffer_get_rest_len(session->in_buffer);
+            payloadsize = ssh_buffer_get_rest_len(session->in_buffer);
             session->recv_seq++;
             if (session->raw_counter != NULL) {
                 session->raw_counter->in_bytes += payloadsize;
@@ -489,7 +489,7 @@ int ssh_packet_parse_type(ssh_session session) {
     return SSH_ERROR;
   }
 
-  if(buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
+  if(ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
     ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
     return SSH_ERROR;
   }
@@ -507,8 +507,8 @@ static int ssh_packet_write(ssh_session session) {
   int rc = SSH_ERROR;
 
   rc=ssh_socket_write(session->socket,
-      buffer_get_rest(session->out_buffer),
-      buffer_get_rest_len(session->out_buffer));
+      ssh_buffer_get_rest(session->out_buffer),
+      ssh_buffer_get_rest_len(session->out_buffer));
 
   return rc;
 }
@@ -518,7 +518,7 @@ static int packet_send2(ssh_session session) {
       session->current_crypto->out_cipher->blocksize : 8);
   enum ssh_hmac_e hmac_type = (session->current_crypto ?
       session->current_crypto->out_hmac : session->next_crypto->out_hmac);
-  uint32_t currentlen = buffer_get_rest_len(session->out_buffer);
+  uint32_t currentlen = ssh_buffer_get_rest_len(session->out_buffer);
   unsigned char *hmac = NULL;
   char padstring[32] = { 0 };
   int rc = SSH_ERROR;
@@ -531,11 +531,11 @@ static int packet_send2(ssh_session session) {
 #ifdef WITH_ZLIB
   if (session->current_crypto
       && session->current_crypto->do_compress_out
-      && buffer_get_rest_len(session->out_buffer)) {
+      && ssh_buffer_get_rest_len(session->out_buffer)) {
     if (compress_buffer(session,session->out_buffer) < 0) {
       goto error;
     }
-    currentlen = buffer_get_rest_len(session->out_buffer);
+    currentlen = ssh_buffer_get_rest_len(session->out_buffer);
   }
 #endif /* WITH_ZLIB */
   compsize = currentlen;
@@ -552,7 +552,7 @@ static int packet_send2(ssh_session session) {
 
   memcpy(&header[0], &finallen, sizeof(finallen));
   header[sizeof(finallen)] = padding;
-  rc = buffer_prepend_data(session->out_buffer, &header, sizeof(header));
+  rc = ssh_buffer_prepend_data(session->out_buffer, &header, sizeof(header));
   if (rc < 0) {
     goto error;
   }
@@ -563,12 +563,12 @@ static int packet_send2(ssh_session session) {
 #ifdef WITH_PCAP
   if(session->pcap_ctx){
   	ssh_pcap_context_write(session->pcap_ctx,SSH_PCAP_DIR_OUT,
-  			buffer_get_rest(session->out_buffer),buffer_get_rest_len(session->out_buffer)
-  			,buffer_get_rest_len(session->out_buffer));
+  			ssh_buffer_get_rest(session->out_buffer),ssh_buffer_get_rest_len(session->out_buffer)
+  			,ssh_buffer_get_rest_len(session->out_buffer));
   }
 #endif
-  hmac = packet_encrypt(session, buffer_get_rest(session->out_buffer),
-      buffer_get_rest_len(session->out_buffer));
+  hmac = packet_encrypt(session, ssh_buffer_get_rest(session->out_buffer),
+      ssh_buffer_get_rest_len(session->out_buffer));
   if (hmac) {
     rc = ssh_buffer_add_data(session->out_buffer, hmac, hmac_digest_len(hmac_type));
     if (rc < 0) {
diff --git a/src/packet1.c b/src/packet1.c
index eac7008..543af1f 100644
--- a/src/packet1.c
+++ b/src/packet1.c
@@ -185,7 +185,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
           ssh_buffer_get_len(session->in_buffer));
 #endif
       SSH_LOG(SSH_LOG_PACKET, "%d bytes padding", padding);
-      if(((len + padding) != buffer_get_rest_len(session->in_buffer)) ||
+      if(((len + padding) != ssh_buffer_get_rest_len(session->in_buffer)) ||
           ((len + padding) < sizeof(uint32_t))) {
         SSH_LOG(SSH_LOG_RARE, "no crc32 in packet");
         ssh_set_error(session, SSH_FATAL, "no crc32 in packet");
@@ -193,26 +193,26 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
       }
 
       memcpy(&crc,
-          (unsigned char *)buffer_get_rest(session->in_buffer) + (len+padding) - sizeof(uint32_t),
+          (unsigned char *)ssh_buffer_get_rest(session->in_buffer) + (len+padding) - sizeof(uint32_t),
           sizeof(uint32_t));
-      buffer_pass_bytes_end(session->in_buffer, sizeof(uint32_t));
+      ssh_buffer_pass_bytes_end(session->in_buffer, sizeof(uint32_t));
       crc = ntohl(crc);
-      if (ssh_crc32(buffer_get_rest(session->in_buffer),
+      if (ssh_crc32(ssh_buffer_get_rest(session->in_buffer),
             (len + padding) - sizeof(uint32_t)) != crc) {
 #ifdef DEBUG_CRYPTO
-        ssh_print_hexa("crc32 on",buffer_get_rest(session->in_buffer),
+        ssh_print_hexa("crc32 on",ssh_buffer_get_rest(session->in_buffer),
             len + padding - sizeof(uint32_t));
 #endif
         SSH_LOG(SSH_LOG_RARE, "Invalid crc32");
         ssh_set_error(session, SSH_FATAL,
             "Invalid crc32: expected %.8x, got %.8x",
             crc,
-            ssh_crc32(buffer_get_rest(session->in_buffer),
+            ssh_crc32(ssh_buffer_get_rest(session->in_buffer),
               len + padding - sizeof(uint32_t)));
         goto error;
       }
       /* pass the padding */
-      buffer_pass_bytes(session->in_buffer, padding);
+      ssh_buffer_pass_bytes(session->in_buffer, padding);
       SSH_LOG(SSH_LOG_PACKET, "The packet is valid");
 
 /* TODO FIXME
@@ -270,7 +270,7 @@ int packet_send1(ssh_session session) {
     if (compress_buffer(session, session->out_buffer) < 0) {
       goto error;
     }
-    currentlen = buffer_get_len(session->out_buffer);
+    currentlen = ssh_buffer_get_len(session->out_buffer);
   }
 #endif
 */
@@ -286,17 +286,17 @@ int packet_send1(ssh_session session) {
       "%d bytes after comp + %d padding bytes = %d bytes packet",
       currentlen, padding, ntohl(finallen));
 
-  if (buffer_prepend_data(session->out_buffer, &padstring, padding) < 0) {
+  if (ssh_buffer_prepend_data(session->out_buffer, &padstring, padding) < 0) {
     goto error;
   }
-  if (buffer_prepend_data(session->out_buffer, &finallen, sizeof(uint32_t)) < 0) {
+  if (ssh_buffer_prepend_data(session->out_buffer, &finallen, sizeof(uint32_t)) < 0) {
     goto error;
   }
 
   crc = ssh_crc32((char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t),
       ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t));
 
-  if (buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) {
+  if (ssh_buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) {
     goto error;
   }
 
diff --git a/src/packet_cb.c b/src/packet_cb.c
index 4fe6402..8353b46 100644
--- a/src/packet_cb.c
+++ b/src/packet_cb.c
@@ -53,12 +53,12 @@ SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback){
   (void)user;
   (void)type;
 
-  rc = buffer_get_u32(packet, &code);
+  rc = ssh_buffer_get_u32(packet, &code);
   if (rc != 0) {
     code = ntohl(code);
   }
 
-  error_s = buffer_get_ssh_string(packet);
+  error_s = ssh_buffer_get_ssh_string(packet);
   if (error_s != NULL) {
     error = ssh_string_to_char(error_s);
     ssh_string_free(error_s);
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index 914727e..c24a3e9 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -175,7 +175,7 @@ int packet_hmac_verify(ssh_session session, ssh_buffer buffer,
   seq = htonl(session->recv_seq);
 
   hmac_update(ctx, (unsigned char *) &seq, sizeof(uint32_t));
-  hmac_update(ctx, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
+  hmac_update(ctx, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
   hmac_final(ctx, hmacbuf, &len);
 
 #ifdef DEBUG_CRYPTO
diff --git a/src/pcap.c b/src/pcap.c
index 134bdf1..4efb052 100644
--- a/src/pcap.c
+++ b/src/pcap.c
@@ -144,8 +144,8 @@ static int ssh_pcap_file_write(ssh_pcap_file pcap, ssh_buffer packet){
 	uint32_t len;
 	if(pcap == NULL || pcap->output==NULL)
 		return SSH_ERROR;
-	len=buffer_get_rest_len(packet);
-	err=fwrite(buffer_get_rest(packet),len,1,pcap->output);
+	len=ssh_buffer_get_rest_len(packet);
+	err=fwrite(ssh_buffer_get_rest(packet),len,1,pcap->output);
 	if(err<0)
 		return SSH_ERROR;
 	else
@@ -163,23 +163,23 @@ int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, uint32_t o
 	if(header == NULL)
 		return SSH_ERROR;
 	gettimeofday(&now,NULL);
-    err = buffer_add_u32(header,htonl(now.tv_sec));
+    err = ssh_buffer_add_u32(header,htonl(now.tv_sec));
     if (err < 0) {
         goto error;
     }
-    err = buffer_add_u32(header,htonl(now.tv_usec));
+    err = ssh_buffer_add_u32(header,htonl(now.tv_usec));
     if (err < 0) {
         goto error;
     }
-    err = buffer_add_u32(header,htonl(buffer_get_rest_len(packet)));
+    err = ssh_buffer_add_u32(header,htonl(ssh_buffer_get_rest_len(packet)));
     if (err < 0) {
         goto error;
     }
-    err = buffer_add_u32(header,htonl(original_len));
+    err = ssh_buffer_add_u32(header,htonl(original_len));
     if (err < 0) {
         goto error;
     }
-    err = buffer_add_buffer(header,packet);
+    err = ssh_buffer_add_buffer(header,packet);
     if (err < 0) {
         goto error;
     }
@@ -207,35 +207,35 @@ int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename){
 	header=ssh_buffer_new();
 	if(header==NULL)
 		return SSH_ERROR;
-    err = buffer_add_u32(header,htonl(PCAP_MAGIC));
+    err = ssh_buffer_add_u32(header,htonl(PCAP_MAGIC));
     if (err < 0) {
         goto error;
     }
-    err = buffer_add_u16(header,htons(PCAP_VERSION_MAJOR));
+    err = ssh_buffer_add_u16(header,htons(PCAP_VERSION_MAJOR));
     if (err < 0) {
         goto error;
     }
-    err = buffer_add_u16(header,htons(PCAP_VERSION_MINOR));
+    err = ssh_buffer_add_u16(header,htons(PCAP_VERSION_MINOR));
     if (err < 0) {
         goto error;
     }
 	/* currently hardcode GMT to 0 */
-    err = buffer_add_u32(header,htonl(0));
+    err = ssh_buffer_add_u32(header,htonl(0));
     if (err < 0) {
         goto error;
     }
 	/* accuracy */
-    err = buffer_add_u32(header,htonl(0));
+    err = ssh_buffer_add_u32(header,htonl(0));
     if (err < 0) {
         goto error;
     }
 	/* size of the biggest packet */
-    err = buffer_add_u32(header,htonl(MAX_PACKET_LEN));
+    err = ssh_buffer_add_u32(header,htonl(MAX_PACKET_LEN));
     if (err < 0) {
         goto error;
     }
 	/* we will write sort-of IP */
-    err = buffer_add_u32(header,htonl(DLT_RAW));
+    err = ssh_buffer_add_u32(header,htonl(DLT_RAW));
     if (err < 0) {
         goto error;
     }
@@ -371,40 +371,40 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
 	    goto error;
 	}
 	if(direction==SSH_PCAP_DIR_OUT){
-        rc = buffer_add_u32(ip,ctx->ipsource);
+        rc = ssh_buffer_add_u32(ip,ctx->ipsource);
         if (rc < 0) {
             goto error;
         }
-        rc = buffer_add_u32(ip,ctx->ipdest);
+        rc = ssh_buffer_add_u32(ip,ctx->ipdest);
         if (rc < 0) {
             goto error;
         }
 	} else {
-        rc = buffer_add_u32(ip,ctx->ipdest);
+        rc = ssh_buffer_add_u32(ip,ctx->ipdest);
         if (rc < 0) {
             goto error;
         }
-        rc = buffer_add_u32(ip,ctx->ipsource);
+        rc = ssh_buffer_add_u32(ip,ctx->ipsource);
         if (rc < 0) {
             goto error;
         }
 	}
 	/* TCP */
 	if(direction==SSH_PCAP_DIR_OUT){
-	    rc = buffer_add_u16(ip,ctx->portsource);
+	    rc = ssh_buffer_add_u16(ip,ctx->portsource);
         if (rc < 0) {
             goto error;
         }
-	    rc = buffer_add_u16(ip,ctx->portdest);
+	    rc = ssh_buffer_add_u16(ip,ctx->portdest);
         if (rc < 0) {
             goto error;
         }
 	} else {
-	    rc = buffer_add_u16(ip,ctx->portdest);
+	    rc = ssh_buffer_add_u16(ip,ctx->portdest);
         if (rc < 0) {
             goto error;
         }
-	    rc = buffer_add_u16(ip,ctx->portsource);
+	    rc = ssh_buffer_add_u16(ip,ctx->portsource);
         if (rc < 0) {
             goto error;
         }
diff --git a/src/pki.c b/src/pki.c
index 22143cb..12e84e2 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -671,18 +671,18 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
                 ssh_string g;
                 ssh_string pubkey;
 
-                p = buffer_get_ssh_string(buffer);
+                p = ssh_buffer_get_ssh_string(buffer);
                 if (p == NULL) {
                     goto fail;
                 }
-                q = buffer_get_ssh_string(buffer);
+                q = ssh_buffer_get_ssh_string(buffer);
                 if (q == NULL) {
                     ssh_string_burn(p);
                     ssh_string_free(p);
 
                     goto fail;
                 }
-                g = buffer_get_ssh_string(buffer);
+                g = ssh_buffer_get_ssh_string(buffer);
                 if (g == NULL) {
                     ssh_string_burn(p);
                     ssh_string_free(p);
@@ -691,7 +691,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
 
                     goto fail;
                 }
-                pubkey = buffer_get_ssh_string(buffer);
+                pubkey = ssh_buffer_get_ssh_string(buffer);
                 if (pubkey == NULL) {
                     ssh_string_burn(p);
                     ssh_string_free(p);
@@ -728,11 +728,11 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
                 ssh_string e;
                 ssh_string n;
 
-                e = buffer_get_ssh_string(buffer);
+                e = ssh_buffer_get_ssh_string(buffer);
                 if (e == NULL) {
                     goto fail;
                 }
-                n = buffer_get_ssh_string(buffer);
+                n = ssh_buffer_get_ssh_string(buffer);
                 if (n == NULL) {
                     ssh_string_burn(e);
                     ssh_string_free(e);
@@ -761,7 +761,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
                 ssh_string i;
                 int nid;
 
-                i = buffer_get_ssh_string(buffer);
+                i = ssh_buffer_get_ssh_string(buffer);
                 if (i == NULL) {
                     goto fail;
                 }
@@ -772,7 +772,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
                 }
 
 
-                e = buffer_get_ssh_string(buffer);
+                e = ssh_buffer_get_ssh_string(buffer);
                 if (e == NULL) {
                     goto fail;
                 }
@@ -791,7 +791,7 @@ static int pki_import_pubkey_buffer(ssh_buffer buffer,
 #endif
         case SSH_KEYTYPE_ED25519:
         {
-            ssh_string pubkey = buffer_get_ssh_string(buffer);
+            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
             if (ssh_string_len(pubkey) != ED25519_PK_LEN) {
                 SSH_LOG(SSH_LOG_WARN, "Invalid public key length");
                 ssh_string_burn(pubkey);
@@ -858,13 +858,13 @@ static int pki_import_cert_buffer(ssh_buffer buffer,
     if (type_s == NULL) {
         goto fail;
     }
-    rc = buffer_add_ssh_string(cert, type_s);
+    rc = ssh_buffer_add_ssh_string(cert, type_s);
     ssh_string_free(type_s);
     if (rc != 0) {
         goto fail;
     }
 
-    rc = buffer_add_buffer(cert, buffer);
+    rc = ssh_buffer_add_buffer(cert, buffer);
     if (rc != 0) {
         goto fail;
     }
@@ -909,7 +909,7 @@ int ssh_pki_import_pubkey_base64(const char *b64_key,
         return SSH_ERROR;
     }
 
-    type_s = buffer_get_ssh_string(buffer);
+    type_s = ssh_buffer_get_ssh_string(buffer);
     if (type_s == NULL) {
         ssh_buffer_free(buffer);
         return SSH_ERROR;
@@ -966,7 +966,7 @@ int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
         goto fail;
     }
 
-    type_s = buffer_get_ssh_string(buffer);
+    type_s = ssh_buffer_get_ssh_string(buffer);
     if (type_s == NULL) {
         SSH_LOG(SSH_LOG_WARN, "Out of memory!");
         goto fail;
@@ -1406,7 +1406,7 @@ int ssh_pki_copy_cert_to_privkey(const ssh_key certkey, ssh_key privkey) {
       return SSH_ERROR;
   }
 
-  rc = buffer_add_buffer(cert_buffer, certkey->cert);
+  rc = ssh_buffer_add_buffer(cert_buffer, certkey->cert);
   if (rc != 0) {
       ssh_buffer_free(cert_buffer);
       return SSH_ERROR;
@@ -1447,7 +1447,7 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
         return SSH_ERROR;
     }
 
-    rc = buffer_add_ssh_string(buf, str);
+    rc = ssh_buffer_add_ssh_string(buf, str);
     ssh_string_free(str);
     if (rc < 0) {
         ssh_buffer_free(buf);
@@ -1460,20 +1460,20 @@ int ssh_pki_export_signature_blob(const ssh_signature sig,
         return SSH_ERROR;
     }
 
-    rc = buffer_add_ssh_string(buf, str);
+    rc = ssh_buffer_add_ssh_string(buf, str);
     ssh_string_free(str);
     if (rc < 0) {
         ssh_buffer_free(buf);
         return SSH_ERROR;
     }
 
-    str = ssh_string_new(buffer_get_rest_len(buf));
+    str = ssh_string_new(ssh_buffer_get_rest_len(buf));
     if (str == NULL) {
         ssh_buffer_free(buf);
         return SSH_ERROR;
     }
 
-    ssh_string_fill(str, buffer_get_rest(buf), buffer_get_rest_len(buf));
+    ssh_string_fill(str, ssh_buffer_get_rest(buf), ssh_buffer_get_rest_len(buf));
     ssh_buffer_free(buf);
 
     *sig_blob = str;
@@ -1508,7 +1508,7 @@ int ssh_pki_import_signature_blob(const ssh_string sig_blob,
         return SSH_ERROR;
     }
 
-    str = buffer_get_ssh_string(buf);
+    str = ssh_buffer_get_ssh_string(buf);
     if (str == NULL) {
         ssh_buffer_free(buf);
         return SSH_ERROR;
@@ -1517,7 +1517,7 @@ int ssh_pki_import_signature_blob(const ssh_string sig_blob,
     type = ssh_key_type_from_name(ssh_string_get_char(str));
     ssh_string_free(str);
 
-    str = buffer_get_ssh_string(buf);
+    str = ssh_buffer_get_ssh_string(buf);
     ssh_buffer_free(buf);
     if (str == NULL) {
         return SSH_ERROR;
@@ -1629,7 +1629,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
         }
 
         evp_update(ctx, session_id, ssh_string_len(session_id) + 4);
-        evp_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
+        evp_update(ctx, ssh_buffer_get_rest(sigbuf), ssh_buffer_get_rest_len(sigbuf));
         evp_final(ctx, ehash, &elen);
 
 #ifdef DEBUG_CRYPTO
@@ -1651,7 +1651,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
         rc = ssh_buffer_pack(buf,
                              "SP",
                              session_id,
-                             buffer_get_rest_len(sigbuf), buffer_get_rest(sigbuf));
+                             ssh_buffer_get_rest_len(sigbuf), ssh_buffer_get_rest(sigbuf));
         if (rc != SSH_OK) {
             ssh_string_free(session_id);
             ssh_buffer_free(buf);
@@ -1673,7 +1673,7 @@ ssh_string ssh_pki_do_sign(ssh_session session,
         }
 
         sha1_update(ctx, session_id, ssh_string_len(session_id) + 4);
-        sha1_update(ctx, buffer_get_rest(sigbuf), buffer_get_rest_len(sigbuf));
+        sha1_update(ctx, ssh_buffer_get_rest(sigbuf), ssh_buffer_get_rest_len(sigbuf));
         sha1_final(hash, ctx);
 
 #ifdef DEBUG_CRYPTO
@@ -1725,7 +1725,7 @@ ssh_string ssh_pki_do_sign_agent(ssh_session session,
         return NULL;
     }
 
-    rc = buffer_add_ssh_string(sig_buf, session_id);
+    rc = ssh_buffer_add_ssh_string(sig_buf, session_id);
     if (rc < 0) {
         ssh_string_free(session_id);
         ssh_buffer_free(sig_buf);
@@ -1734,7 +1734,7 @@ ssh_string ssh_pki_do_sign_agent(ssh_session session,
     ssh_string_free(session_id);
 
     /* append out buffer */
-    if (buffer_add_buffer(sig_buf, buf) < 0) {
+    if (ssh_buffer_add_buffer(sig_buf, buf) < 0) {
         ssh_buffer_free(sig_buf);
         return NULL;
     }
diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c
index 40b1156..1f2ed97 100644
--- a/src/pki_container_openssh.c
+++ b/src/pki_container_openssh.c
@@ -384,11 +384,11 @@ ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
     if (rc == SSH_ERROR){
         goto error;
     }
-    comment = buffer_get_ssh_string(privkey_buffer);
+    comment = ssh_buffer_get_ssh_string(privkey_buffer);
     SAFE_FREE(comment);
     /* verify that the remaining data is correct padding */
-    for (i=1; buffer_get_rest_len(privkey_buffer) > 0; ++i){
-        buffer_get_u8(privkey_buffer, &padding);
+    for (i=1; ssh_buffer_get_rest_len(privkey_buffer) > 0; ++i){
+        ssh_buffer_get_u8(privkey_buffer, &padding);
         if (padding != i){
             ssh_key_free(key);
             key = NULL;
@@ -493,7 +493,7 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer,
         return SSH_ERROR;
     }
     while (ssh_buffer_get_len(privkey_buffer) % cipher.blocksize != 0) {
-        rc = buffer_add_u8(privkey_buffer, padding);
+        rc = ssh_buffer_add_u8(privkey_buffer, padding);
         if (rc < 0) {
             return SSH_ERROR;
         }
@@ -704,7 +704,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
     }
 
     str_len = ssh_buffer_get_len(buffer);
-    len = buffer_get_data(buffer, ssh_string_data(str), str_len);
+    len = ssh_buffer_get_data(buffer, ssh_string_data(str), str_len);
     if (str_len != len) {
         ssh_string_free(str);
         str = NULL;
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 0def32c..0b65ccd 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -92,7 +92,7 @@ static uint32_t asn1_get_len(ssh_buffer buffer) {
   uint32_t len;
   unsigned char tmp[4];
 
-  if (buffer_get_data(buffer,tmp,1) == 0) {
+  if (ssh_buffer_get_data(buffer,tmp,1) == 0) {
     return 0;
   }
 
@@ -101,7 +101,7 @@ static uint32_t asn1_get_len(ssh_buffer buffer) {
     if (len > 4) {
       return 0; /* Length doesn't fit in u32. Can this really happen? */
     }
-    if (buffer_get_data(buffer,tmp,len) == 0) {
+    if (ssh_buffer_get_data(buffer,tmp,len) == 0) {
       return 0;
     }
     len = char_to_u32(tmp, len);
@@ -117,7 +117,7 @@ static ssh_string asn1_get_int(ssh_buffer buffer) {
   unsigned char type;
   uint32_t size;
 
-  if (buffer_get_data(buffer, &type, 1) == 0 || type != ASN1_INTEGER) {
+  if (ssh_buffer_get_data(buffer, &type, 1) == 0 || type != ASN1_INTEGER) {
     return NULL;
   }
   size = asn1_get_len(buffer);
@@ -130,7 +130,7 @@ static ssh_string asn1_get_int(ssh_buffer buffer) {
     return NULL;
   }
 
-  if (buffer_get_data(buffer, ssh_string_data(str), size) == 0) {
+  if (ssh_buffer_get_data(buffer, ssh_string_data(str), size) == 0) {
     ssh_string_free(str);
     return NULL;
   }
@@ -145,7 +145,7 @@ static int asn1_check_sequence(ssh_buffer buffer) {
   uint32_t size;
   uint32_t padding;
 
-  if (buffer_get_data(buffer, &tmp, 1) == 0 || tmp != ASN1_SEQUENCE) {
+  if (ssh_buffer_get_data(buffer, &tmp, 1) == 0 || tmp != ASN1_SEQUENCE) {
     return 0;
   }
 
@@ -1168,7 +1168,7 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
         return NULL;
     }
 
-    rc = buffer_add_ssh_string(buffer, type_s);
+    rc = ssh_buffer_add_ssh_string(buffer, type_s);
     ssh_string_free(type_s);
     if (rc < 0) {
         ssh_buffer_free(buffer);
@@ -1224,16 +1224,16 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
             }
             ssh_string_fill(n, (char *) tmp, size);
 
-            if (buffer_add_ssh_string(buffer, p) < 0) {
+            if (ssh_buffer_add_ssh_string(buffer, p) < 0) {
                 goto fail;
             }
-            if (buffer_add_ssh_string(buffer, q) < 0) {
+            if (ssh_buffer_add_ssh_string(buffer, q) < 0) {
                 goto fail;
             }
-            if (buffer_add_ssh_string(buffer, g) < 0) {
+            if (ssh_buffer_add_ssh_string(buffer, g) < 0) {
                 goto fail;
             }
-            if (buffer_add_ssh_string(buffer, n) < 0) {
+            if (ssh_buffer_add_ssh_string(buffer, n) < 0) {
                 goto fail;
             }
 
@@ -1273,10 +1273,10 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
             ssh_string_fill(n, (char *) tmp, size);
             gcry_sexp_release(sexp);
 
-            if (buffer_add_ssh_string(buffer, e) < 0) {
+            if (ssh_buffer_add_ssh_string(buffer, e) < 0) {
                 goto fail;
             }
-            if (buffer_add_ssh_string(buffer, n) < 0) {
+            if (ssh_buffer_add_ssh_string(buffer, n) < 0) {
                 goto fail;
             }
 
@@ -1298,12 +1298,12 @@ ssh_string pki_publickey_to_blob(const ssh_key key)
             goto fail;
     }
 
-    str = ssh_string_new(buffer_get_rest_len(buffer));
+    str = ssh_string_new(ssh_buffer_get_rest_len(buffer));
     if (str == NULL) {
         goto fail;
     }
 
-    rc = ssh_string_fill(str, buffer_get_rest(buffer), buffer_get_rest_len(buffer));
+    rc = ssh_string_fill(str, ssh_buffer_get_rest(buffer), ssh_buffer_get_rest_len(buffer));
     if (rc < 0) {
         goto fail;
     }
diff --git a/src/server.c b/src/server.c
index a078e7a..6679245 100644
--- a/src/server.c
+++ b/src/server.c
@@ -155,7 +155,7 @@ static int server_set_kex(ssh_session session) {
  **/
 static int ssh_server_kexdh_init(ssh_session session, ssh_buffer packet){
     ssh_string e;
-    e = buffer_get_ssh_string(packet);
+    e = ssh_buffer_get_ssh_string(packet);
     if (e == NULL) {
       ssh_set_error(session, SSH_FATAL, "No e number in client request");
       return -1;
@@ -325,7 +325,7 @@ static int dh_handshake_server(ssh_session session) {
     return -1;
   }
 
-  if (buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
     ssh_buffer_reinit(session->out_buffer);
     return -1;
   }
@@ -738,7 +738,7 @@ int ssh_message_global_request_reply_success(ssh_message msg, uint16_t bound_por
     SSH_LOG(SSH_LOG_FUNCTIONS, "Accepting a global request");
 
     if (msg->global_request.want_reply) {
-        if (buffer_add_u8(msg->session->out_buffer
+        if (ssh_buffer_add_u8(msg->session->out_buffer
                     , SSH2_MSG_REQUEST_SUCCESS) < 0) {
             goto error;
         }
@@ -770,7 +770,7 @@ static int ssh_message_global_request_reply_default(ssh_message msg) {
     SSH_LOG(SSH_LOG_FUNCTIONS, "Refusing a global request");
 
     if (msg->global_request.want_reply) {
-        if (buffer_add_u8(msg->session->out_buffer
+        if (ssh_buffer_add_u8(msg->session->out_buffer
                     , SSH2_MSG_REQUEST_FAILURE) < 0) {
             goto error;
         }
@@ -994,7 +994,7 @@ int ssh_auth_reply_success(ssh_session session, int partial) {
   session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
   session->flags |= SSH_SESSION_FLAG_AUTHENTICATED;
 
-  if (buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS) < 0) {
+  if (ssh_buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS) < 0) {
     return SSH_ERROR;
   }
 
diff --git a/src/sftp.c b/src/sftp.c
index 39d0819..c1dbda1 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -210,7 +210,7 @@ int sftp_server_init(sftp_session sftp){
 
   SSH_LOG(SSH_LOG_PACKET, "Received SSH_FXP_INIT");
 
-  buffer_get_u32(packet->payload, &version);
+  ssh_buffer_get_u32(packet->payload, &version);
   version = ntohl(version);
   SSH_LOG(SSH_LOG_PACKET, "Client version: %d", version);
   sftp->client_version = version;
@@ -223,7 +223,7 @@ int sftp_server_init(sftp_session sftp){
     return -1;
   }
 
-  if (buffer_add_u32(reply, ntohl(LIBSFTP_VERSION)) < 0) {
+  if (ssh_buffer_add_u32(reply, ntohl(LIBSFTP_VERSION)) < 0) {
     ssh_set_error_oom(session);
     ssh_buffer_free(reply);
     return -1;
@@ -277,25 +277,25 @@ void sftp_free(sftp_session sftp){
 int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
   int size;
 
-  if (buffer_prepend_data(payload, &type, sizeof(uint8_t)) < 0) {
+  if (ssh_buffer_prepend_data(payload, &type, sizeof(uint8_t)) < 0) {
     ssh_set_error_oom(sftp->session);
     return -1;
   }
 
-  size = htonl(buffer_get_rest_len(payload));
-  if (buffer_prepend_data(payload, &size, sizeof(uint32_t)) < 0) {
+  size = htonl(ssh_buffer_get_rest_len(payload));
+  if (ssh_buffer_prepend_data(payload, &size, sizeof(uint32_t)) < 0) {
     ssh_set_error_oom(sftp->session);
     return -1;
   }
 
-  size = ssh_channel_write(sftp->channel, buffer_get_rest(payload),
-      buffer_get_rest_len(payload));
+  size = ssh_channel_write(sftp->channel, ssh_buffer_get_rest(payload),
+      ssh_buffer_get_rest_len(payload));
   if (size < 0) {
     return -1;
-  } else if((uint32_t) size != buffer_get_rest_len(payload)) {
+  } else if((uint32_t) size != ssh_buffer_get_rest_len(payload)) {
     SSH_LOG(SSH_LOG_PACKET,
         "Had to write %d bytes, wrote only %d",
-        buffer_get_rest_len(payload),
+        ssh_buffer_get_rest_len(payload),
         size);
   }
 
@@ -335,7 +335,7 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
     }
   } while (r<4);
   ssh_buffer_add_data(packet->payload, buffer, r);
-  if (buffer_get_u32(packet->payload, &tmp) != sizeof(uint32_t)) {
+  if (ssh_buffer_get_u32(packet->payload, &tmp) != sizeof(uint32_t)) {
     ssh_set_error(sftp->session, SSH_FATAL, "Short sftp packet!");
     ssh_buffer_free(packet->payload);
     SAFE_FREE(packet);
@@ -350,7 +350,7 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
     return NULL;
   }
   ssh_buffer_add_data(packet->payload, buffer, r);
-  buffer_get_u8(packet->payload, &packet->type);
+  ssh_buffer_get_u8(packet->payload, &packet->type);
 
   size = ntohl(tmp);
   if (size == 0) {
@@ -460,8 +460,8 @@ static sftp_message sftp_get_message(sftp_packet packet) {
       msg->id,
       msg->packet_type);
 
-  if (ssh_buffer_add_data(msg->payload, buffer_get_rest(packet->payload),
-        buffer_get_rest_len(packet->payload)) < 0) {
+  if (ssh_buffer_add_data(msg->payload, ssh_buffer_get_rest(packet->payload),
+        ssh_buffer_get_rest_len(packet->payload)) < 0) {
     ssh_set_error_oom(sftp->session);
     sftp_message_free(msg);
     return NULL;
@@ -832,7 +832,7 @@ static sftp_file parse_handle_msg(sftp_message msg){
   }
   ZERO_STRUCTP(file);
 
-  file->handle = buffer_get_ssh_string(msg->payload);
+  file->handle = ssh_buffer_get_ssh_string(msg->payload);
   if (file->handle == NULL) {
     ssh_set_error(msg->sftp->session, SSH_FATAL,
         "Invalid SSH_FXP_HANDLE message");
@@ -871,8 +871,8 @@ sftp_dir sftp_opendir(sftp_session sftp, const char *path){
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(payload, htonl(id)) < 0 ||
-      buffer_add_ssh_string(payload, path_s) < 0) {
+  if (ssh_buffer_add_u32(payload, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(payload, path_s) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(payload);
     ssh_string_free(path_s);
@@ -963,7 +963,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
 
   /* This isn't really a loop, but it is like a try..catch.. */
   do {
-    if (buffer_get_u32(buf, &flags) != 4) {
+    if (ssh_buffer_get_u32(buf, &flags) != 4) {
       break;
     }
 
@@ -971,14 +971,14 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
     attr->flags = flags;
 
     if (flags & SSH_FILEXFER_ATTR_SIZE) {
-      if (buffer_get_u64(buf, &attr->size) != 8) {
+      if (ssh_buffer_get_u64(buf, &attr->size) != 8) {
         break;
       }
       attr->size = ntohll(attr->size);
     }
 
     if (flags & SSH_FILEXFER_ATTR_OWNERGROUP) {
-      owner = buffer_get_ssh_string(buf);
+      owner = ssh_buffer_get_ssh_string(buf);
       if (owner == NULL) {
         break;
       }
@@ -988,7 +988,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
         break;
       }
 
-      group = buffer_get_ssh_string(buf);
+      group = ssh_buffer_get_ssh_string(buf);
       if (group == NULL) {
         break;
       }
@@ -1000,7 +1000,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
     }
 
     if (flags & SSH_FILEXFER_ATTR_PERMISSIONS) {
-      if (buffer_get_u32(buf, &attr->permissions) != 4) {
+      if (ssh_buffer_get_u32(buf, &attr->permissions) != 4) {
         break;
       }
       attr->permissions = ntohl(attr->permissions);
@@ -1029,62 +1029,62 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
     }
 
     if (flags & SSH_FILEXFER_ATTR_ACCESSTIME) {
-      if (buffer_get_u64(buf, &attr->atime64) != 8) {
+      if (ssh_buffer_get_u64(buf, &attr->atime64) != 8) {
         break;
       }
       attr->atime64 = ntohll(attr->atime64);
     }
 
     if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
-      if (buffer_get_u32(buf, &attr->atime_nseconds) != 4) {
+      if (ssh_buffer_get_u32(buf, &attr->atime_nseconds) != 4) {
         break;
       }
       attr->atime_nseconds = ntohl(attr->atime_nseconds);
     }
 
     if (flags & SSH_FILEXFER_ATTR_CREATETIME) {
-      if (buffer_get_u64(buf, &attr->createtime) != 8) {
+      if (ssh_buffer_get_u64(buf, &attr->createtime) != 8) {
         break;
       }
       attr->createtime = ntohll(attr->createtime);
     }
 
     if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
-      if (buffer_get_u32(buf, &attr->createtime_nseconds) != 4) {
+      if (ssh_buffer_get_u32(buf, &attr->createtime_nseconds) != 4) {
         break;
       }
       attr->createtime_nseconds = ntohl(attr->createtime_nseconds);
     }
 
     if (flags & SSH_FILEXFER_ATTR_MODIFYTIME) {
-      if (buffer_get_u64(buf, &attr->mtime64) != 8) {
+      if (ssh_buffer_get_u64(buf, &attr->mtime64) != 8) {
         break;
       }
       attr->mtime64 = ntohll(attr->mtime64);
     }
 
     if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) {
-      if (buffer_get_u32(buf, &attr->mtime_nseconds) != 4) {
+      if (ssh_buffer_get_u32(buf, &attr->mtime_nseconds) != 4) {
         break;
       }
       attr->mtime_nseconds = ntohl(attr->mtime_nseconds);
     }
 
     if (flags & SSH_FILEXFER_ATTR_ACL) {
-      if ((attr->acl = buffer_get_ssh_string(buf)) == NULL) {
+      if ((attr->acl = ssh_buffer_get_ssh_string(buf)) == NULL) {
         break;
       }
     }
 
     if (flags & SSH_FILEXFER_ATTR_EXTENDED) {
-      if (buffer_get_u32(buf,&attr->extended_count) != 4) {
+      if (ssh_buffer_get_u32(buf,&attr->extended_count) != 4) {
         break;
       }
       attr->extended_count = ntohl(attr->extended_count);
 
       while(attr->extended_count &&
-          (attr->extended_type = buffer_get_ssh_string(buf)) &&
-          (attr->extended_data = buffer_get_ssh_string(buf))){
+          (attr->extended_type = ssh_buffer_get_ssh_string(buf)) &&
+          (attr->extended_data = ssh_buffer_get_ssh_string(buf))){
         attr->extended_count--;
       }
 
@@ -1403,8 +1403,8 @@ sftp_attributes sftp_readdir(sftp_session sftp, sftp_dir dir) {
     }
 
     id = sftp_get_new_id(sftp);
-    if (buffer_add_u32(payload, htonl(id)) < 0 ||
-        buffer_add_ssh_string(payload, dir->handle) < 0) {
+    if (ssh_buffer_add_u32(payload, htonl(id)) < 0 ||
+        ssh_buffer_add_ssh_string(payload, dir->handle) < 0) {
       ssh_set_error_oom(sftp->session);
       ssh_buffer_free(payload);
       return NULL;
@@ -1450,7 +1450,7 @@ sftp_attributes sftp_readdir(sftp_session sftp, sftp_dir dir) {
 
         return NULL;
       case SSH_FXP_NAME:
-        buffer_get_u32(msg->payload, &dir->count);
+        ssh_buffer_get_u32(msg->payload, &dir->count);
         dir->count = ntohl(dir->count);
         dir->buffer = msg->payload;
         msg->payload = NULL;
@@ -1527,8 +1527,8 @@ static int sftp_handle_close(sftp_session sftp, ssh_string handle) {
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, handle) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, handle) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     return -1;
@@ -1650,8 +1650,8 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
     sftp_flags |= SSH_FXF_EXCL;
   SSH_LOG(SSH_LOG_PACKET,"Opening file %s with sftp flags %x",file,sftp_flags);
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, filename) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, filename) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     ssh_string_free(filename);
@@ -1659,7 +1659,7 @@ sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
   }
   ssh_string_free(filename);
 
-  if (buffer_add_u32(buffer, htonl(sftp_flags)) < 0 ||
+  if (ssh_buffer_add_u32(buffer, htonl(sftp_flags)) < 0 ||
       buffer_add_attributes(buffer, &attr) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
@@ -1787,7 +1787,7 @@ ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
       status_msg_free(status);
       return -1;
     case SSH_FXP_DATA:
-      datastring = buffer_get_ssh_string(msg->payload);
+      datastring = ssh_buffer_get_ssh_string(msg->payload);
       sftp_message_free(msg);
       if (datastring == NULL) {
         ssh_set_error(sftp->session, SSH_FATAL,
@@ -1908,7 +1908,7 @@ int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
       status_msg_free(status);
       return err;
     case SSH_FXP_DATA:
-      datastring = buffer_get_ssh_string(msg->payload);
+      datastring = ssh_buffer_get_ssh_string(msg->payload);
       sftp_message_free(msg);
       if (datastring == NULL) {
         ssh_set_error(sftp->session, SSH_FATAL,
@@ -1968,7 +1968,7 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
     ssh_buffer_free(buffer);
     return -1;
   }
-  packetlen=buffer_get_rest_len(buffer);
+  packetlen=ssh_buffer_get_rest_len(buffer);
   len = sftp_packet_write(file->sftp, SSH_FXP_WRITE, buffer);
   ssh_buffer_free(buffer);
   if (len < 0) {
@@ -2223,8 +2223,8 @@ int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode) {
   attr.flags = SSH_FILEXFER_ATTR_PERMISSIONS;
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, path) < 0 ||
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, path) < 0 ||
       buffer_add_attributes(buffer, &attr) < 0 ||
       sftp_packet_write(sftp, SSH_FXP_MKDIR, buffer) < 0) {
     ssh_buffer_free(buffer);
@@ -2317,7 +2317,7 @@ int sftp_rename(sftp_session sftp, const char *original, const char *newname) {
   if (sftp->version >= 4){
       /* POSIX rename atomically replaces newpath, we should do the same
        * only available on >=v4 */
-      buffer_add_u32(buffer, SSH_FXF_RENAME_OVERWRITE);
+      ssh_buffer_add_u32(buffer, SSH_FXF_RENAME_OVERWRITE);
   }
 
   if (sftp_packet_write(sftp, SSH_FXP_RENAME, buffer) < 0) {
@@ -2389,8 +2389,8 @@ int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr) {
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, path) < 0 ||
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, path) < 0 ||
       buffer_add_attributes(buffer, attr) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
@@ -2606,8 +2606,8 @@ char *sftp_readlink(sftp_session sftp, const char *path) {
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, path_s) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, path_s) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     ssh_string_free(path_s);
@@ -2630,9 +2630,9 @@ char *sftp_readlink(sftp_session sftp, const char *path) {
 
   if (msg->packet_type == SSH_FXP_NAME) {
     /* we don't care about "count" */
-    buffer_get_u32(msg->payload, &ignored);
+    ssh_buffer_get_u32(msg->payload, &ignored);
     /* we only care about the file name string */
-    link_s = buffer_get_ssh_string(msg->payload);
+    link_s = ssh_buffer_get_ssh_string(msg->payload);
     sftp_message_free(msg);
     if (link_s == NULL) {
       /* TODO: what error to set here? */
@@ -2734,9 +2734,9 @@ sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path) {
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, ext) < 0 ||
-      buffer_add_ssh_string(buffer, pathstr) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, ext) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     ssh_string_free(ext);
@@ -2813,9 +2813,9 @@ sftp_statvfs_t sftp_fstatvfs(sftp_file file) {
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, ext) < 0 ||
-      buffer_add_ssh_string(buffer, file->handle) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, ext) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, file->handle) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     ssh_string_free(ext);
@@ -2902,8 +2902,8 @@ char *sftp_canonicalize_path(sftp_session sftp, const char *path) {
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, pathstr) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     ssh_string_free(pathstr);
@@ -2926,9 +2926,9 @@ char *sftp_canonicalize_path(sftp_session sftp, const char *path) {
 
   if (msg->packet_type == SSH_FXP_NAME) {
     /* we don't care about "count" */
-    buffer_get_u32(msg->payload, &ignored);
+    ssh_buffer_get_u32(msg->payload, &ignored);
     /* we only care about the file name string */
-    name = buffer_get_ssh_string(msg->payload);
+    name = ssh_buffer_get_ssh_string(msg->payload);
     sftp_message_free(msg);
     if (name == NULL) {
       /* TODO: error message? */
@@ -2980,8 +2980,8 @@ static sftp_attributes sftp_xstat(sftp_session sftp, const char *path,
   }
 
   id = sftp_get_new_id(sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, pathstr) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
     ssh_set_error_oom(sftp->session);
     ssh_buffer_free(buffer);
     ssh_string_free(pathstr);
@@ -3047,8 +3047,8 @@ sftp_attributes sftp_fstat(sftp_file file) {
   }
 
   id = sftp_get_new_id(file->sftp);
-  if (buffer_add_u32(buffer, htonl(id)) < 0 ||
-      buffer_add_ssh_string(buffer, file->handle) < 0) {
+  if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
+      ssh_buffer_add_ssh_string(buffer, file->handle) < 0) {
     ssh_set_error_oom(file->sftp->session);
     ssh_buffer_free(buffer);
     return NULL;
diff --git a/src/sftpserver.c b/src/sftpserver.c
index 6049879..5939309 100644
--- a/src/sftpserver.c
+++ b/src/sftpserver.c
@@ -65,15 +65,15 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
   /* take a copy of the whole packet */
   msg->complete_message = ssh_buffer_new();
   ssh_buffer_add_data(msg->complete_message,
-                      buffer_get_rest(payload),
-                      buffer_get_rest_len(payload));
+                      ssh_buffer_get_rest(payload),
+                      ssh_buffer_get_rest_len(payload));
 
-  buffer_get_u32(payload, &msg->id);
+  ssh_buffer_get_u32(payload, &msg->id);
 
   switch(msg->type) {
     case SSH_FXP_CLOSE:
     case SSH_FXP_READDIR:
-      msg->handle = buffer_get_ssh_string(payload);
+      msg->handle = ssh_buffer_get_ssh_string(payload);
       if (msg->handle == NULL) {
         ssh_set_error_oom(session);
         sftp_client_message_free(msg);
@@ -148,7 +148,7 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
       }
       break;
     case SSH_FXP_FSETSTAT:
-      msg->handle = buffer_get_ssh_string(payload);
+      msg->handle = ssh_buffer_get_ssh_string(payload);
       if (msg->handle == NULL) {
         ssh_set_error_oom(session);
         sftp_client_message_free(msg);
@@ -274,10 +274,10 @@ int sftp_reply_name(sftp_client_message msg, const char *name,
     return -1;
   }
 
-  if (buffer_add_u32(out, msg->id) < 0 ||
-      buffer_add_u32(out, htonl(1)) < 0 ||
-      buffer_add_ssh_string(out, file) < 0 ||
-      buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
+  if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+      ssh_buffer_add_u32(out, htonl(1)) < 0 ||
+      ssh_buffer_add_ssh_string(out, file) < 0 ||
+      ssh_buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
       buffer_add_attributes(out, attr) < 0 ||
       sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
     ssh_buffer_free(out);
@@ -298,8 +298,8 @@ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
     return -1;
   }
 
-  if (buffer_add_u32(out, msg->id) < 0 ||
-      buffer_add_ssh_string(out, handle) < 0 ||
+  if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+      ssh_buffer_add_ssh_string(out, handle) < 0 ||
       sftp_packet_write(msg->sftp, SSH_FXP_HANDLE, out) < 0) {
     ssh_buffer_free(out);
     return -1;
@@ -317,7 +317,7 @@ int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
     return -1;
   }
 
-  if (buffer_add_u32(out, msg->id) < 0 ||
+  if (ssh_buffer_add_u32(out, msg->id) < 0 ||
       buffer_add_attributes(out, attr) < 0 ||
       sftp_packet_write(msg->sftp, SSH_FXP_ATTRS, out) < 0) {
     ssh_buffer_free(out);
@@ -345,7 +345,7 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
     }
   }
 
-  if (buffer_add_ssh_string(msg->attrbuf, name) < 0) {
+  if (ssh_buffer_add_ssh_string(msg->attrbuf, name) < 0) {
     ssh_string_free(name);
     return -1;
   }
@@ -355,7 +355,7 @@ int sftp_reply_names_add(sftp_client_message msg, const char *file,
   if (name == NULL) {
     return -1;
   }
-  if (buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
+  if (ssh_buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
       buffer_add_attributes(msg->attrbuf,attr) < 0) {
     ssh_string_free(name);
     return -1;
@@ -375,10 +375,10 @@ int sftp_reply_names(sftp_client_message msg) {
     return -1;
   }
 
-  if (buffer_add_u32(out, msg->id) < 0 ||
-      buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
-      ssh_buffer_add_data(out, buffer_get_rest(msg->attrbuf),
-        buffer_get_rest_len(msg->attrbuf)) < 0 ||
+  if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+      ssh_buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
+      ssh_buffer_add_data(out, ssh_buffer_get_rest(msg->attrbuf),
+        ssh_buffer_get_rest_len(msg->attrbuf)) < 0 ||
       sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
     ssh_buffer_free(out);
     ssh_buffer_free(msg->attrbuf);
@@ -410,10 +410,10 @@ int sftp_reply_status(sftp_client_message msg, uint32_t status,
     return -1;
   }
 
-  if (buffer_add_u32(out, msg->id) < 0 ||
-      buffer_add_u32(out, htonl(status)) < 0 ||
-      buffer_add_ssh_string(out, s) < 0 ||
-      buffer_add_u32(out, 0) < 0 || /* language string */
+  if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+      ssh_buffer_add_u32(out, htonl(status)) < 0 ||
+      ssh_buffer_add_ssh_string(out, s) < 0 ||
+      ssh_buffer_add_u32(out, 0) < 0 || /* language string */
       sftp_packet_write(msg->sftp, SSH_FXP_STATUS, out) < 0) {
     ssh_buffer_free(out);
     ssh_string_free(s);
@@ -434,8 +434,8 @@ int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
     return -1;
   }
 
-  if (buffer_add_u32(out, msg->id) < 0 ||
-      buffer_add_u32(out, ntohl(len)) < 0 ||
+  if (ssh_buffer_add_u32(out, msg->id) < 0 ||
+      ssh_buffer_add_u32(out, ntohl(len)) < 0 ||
       ssh_buffer_add_data(out, data, len) < 0 ||
       sftp_packet_write(msg->sftp, SSH_FXP_DATA, out) < 0) {
     ssh_buffer_free(out);
diff --git a/src/socket.c b/src/socket.c
index 022c9a7..ba5128a 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -290,10 +290,10 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
             }
             if (s->callbacks && s->callbacks->data) {
                 do {
-                    r = s->callbacks->data(buffer_get_rest(s->in_buffer),
-                                           buffer_get_rest_len(s->in_buffer),
+                    r = s->callbacks->data(ssh_buffer_get_rest(s->in_buffer),
+                                           ssh_buffer_get_rest_len(s->in_buffer),
                                            s->callbacks->userdata);
-                    buffer_pass_bytes(s->in_buffer, r);
+                    ssh_buffer_pass_bytes(s->in_buffer, r);
                 } while ((r > 0) && (s->state == SSH_SOCKET_CONNECTED));
                 /* p may have been freed, so don't use it
                  * anymore in this function */
@@ -330,7 +330,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd,
         }
 
         /* If buffered data is pending, write it */
-        if (buffer_get_rest_len(s->out_buffer) > 0) {
+        if (ssh_buffer_get_rest_len(s->out_buffer) > 0) {
             ssh_socket_nonblocking_flush(s);
         } else if (s->callbacks && s->callbacks->controlflow) {
             /* Otherwise advertise the upper level that write can be done */
@@ -650,7 +650,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
     return SSH_ERROR;
   }
 
-  len = buffer_get_rest_len(s->out_buffer);
+  len = ssh_buffer_get_rest_len(s->out_buffer);
   if (!s->write_wontblock && s->poll_out && len > 0) {
       /* force the poll system to catch pollout events */
       ssh_poll_add_events(s->poll_out, POLLOUT);
@@ -658,7 +658,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
       return SSH_AGAIN;
   }
   if (s->write_wontblock && len > 0) {
-    w = ssh_socket_unbuffered_write(s, buffer_get_rest(s->out_buffer), len);
+    w = ssh_socket_unbuffered_write(s, ssh_buffer_get_rest(s->out_buffer), len);
     if (w < 0) {
       session->alive = 0;
       ssh_socket_close(s);
@@ -674,14 +674,14 @@ int ssh_socket_nonblocking_flush(ssh_socket s) {
       }
       return SSH_ERROR;
     }
-    buffer_pass_bytes(s->out_buffer, w);
+    ssh_buffer_pass_bytes(s->out_buffer, w);
     if (s->session->socket_counter != NULL) {
         s->session->socket_counter->out_bytes += w;
     }
   }
 
   /* Is there some data pending? */
-  len = buffer_get_rest_len(s->out_buffer);
+  len = ssh_buffer_get_rest_len(s->out_buffer);
   if (s->poll_out && len > 0) {
       /* force the poll system to catch pollout events */
       ssh_poll_add_events(s->poll_out, POLLOUT);
@@ -721,7 +721,7 @@ int ssh_socket_data_writable(ssh_socket s) {
 int ssh_socket_buffered_write_bytes(ssh_socket s){
 	if(s==NULL || s->out_buffer == NULL)
 		return 0;
-	return buffer_get_rest_len(s->out_buffer);
+	return ssh_buffer_get_rest_len(s->out_buffer);
 }
 
 
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c
index 390572c..03dfcf9 100644
--- a/tests/unittests/torture_buffer.c
+++ b/tests/unittests/torture_buffer.c
@@ -36,8 +36,8 @@ static void torture_growing_buffer(void **state) {
   for(i=0;i<LIMIT;++i){
     ssh_buffer_add_data(buffer,"A",1);
     if(buffer->used >= 128){
-      if(buffer_get_rest_len(buffer) * 2 < buffer->allocated){
-        assert_true(buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
+      if(ssh_buffer_get_rest_len(buffer) * 2 < buffer->allocated){
+        assert_true(ssh_buffer_get_rest_len(buffer) * 2 >= buffer->allocated);
       }
     }
   }
@@ -55,11 +55,11 @@ static void torture_growing_buffer_shifting(void **state) {
     ssh_buffer_add_data(buffer,"S",1);
   }
   for(i=0;i<LIMIT;++i){
-    buffer_get_u8(buffer,&c);
+    ssh_buffer_get_u8(buffer,&c);
     ssh_buffer_add_data(buffer,"A",1);
     if(buffer->used >= 128){
-      if(buffer_get_rest_len(buffer) * 4 < buffer->allocated){
-        assert_true(buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
+      if(ssh_buffer_get_rest_len(buffer) * 4 < buffer->allocated){
+        assert_true(ssh_buffer_get_rest_len(buffer) * 4 >= buffer->allocated);
         return;
       }
     }
@@ -67,39 +67,39 @@ static void torture_growing_buffer_shifting(void **state) {
 }
 
 /*
- * Test the behavior of buffer_prepend_data
+ * Test the behavior of ssh_buffer_prepend_data
  */
 static void torture_buffer_prepend(void **state) {
   ssh_buffer buffer = *state;
   uint32_t v;
   ssh_buffer_add_data(buffer,"abcdef",6);
-  buffer_prepend_data(buffer,"xyz",3);
-  assert_int_equal(buffer_get_rest_len(buffer),9);
-  assert_memory_equal(buffer_get_rest(buffer),  "xyzabcdef", 9);
+  ssh_buffer_prepend_data(buffer,"xyz",3);
+  assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
+  assert_memory_equal(ssh_buffer_get_rest(buffer),  "xyzabcdef", 9);
 
   /* Now remove 4 bytes and see if we can replace them */
-  buffer_get_u32(buffer,&v);
-  assert_int_equal(buffer_get_rest_len(buffer),5);
-  assert_memory_equal(buffer_get_rest(buffer), "bcdef", 5);
+  ssh_buffer_get_u32(buffer,&v);
+  assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
+  assert_memory_equal(ssh_buffer_get_rest(buffer), "bcdef", 5);
 
-  buffer_prepend_data(buffer,"aris",4);
-  assert_int_equal(buffer_get_rest_len(buffer),9);
-  assert_memory_equal(buffer_get_rest(buffer), "arisbcdef", 9);
+  ssh_buffer_prepend_data(buffer,"aris",4);
+  assert_int_equal(ssh_buffer_get_rest_len(buffer),9);
+  assert_memory_equal(ssh_buffer_get_rest(buffer), "arisbcdef", 9);
 
   /* same thing but we add 5 bytes now */
-  buffer_get_u32(buffer,&v);
-  assert_int_equal(buffer_get_rest_len(buffer),5);
-  assert_memory_equal(buffer_get_rest(buffer), "bcdef", 5);
+  ssh_buffer_get_u32(buffer,&v);
+  assert_int_equal(ssh_buffer_get_rest_len(buffer),5);
+  assert_memory_equal(ssh_buffer_get_rest(buffer), "bcdef", 5);
 
-  buffer_prepend_data(buffer,"12345",5);
-  assert_int_equal(buffer_get_rest_len(buffer),10);
-  assert_memory_equal(buffer_get_rest(buffer), "12345bcdef", 10);
+  ssh_buffer_prepend_data(buffer,"12345",5);
+  assert_int_equal(ssh_buffer_get_rest_len(buffer),10);
+  assert_memory_equal(ssh_buffer_get_rest(buffer), "12345bcdef", 10);
 }
 
 /*
- * Test the behavior of buffer_get_ssh_string with invalid data
+ * Test the behavior of ssh_buffer_get_ssh_string with invalid data
  */
-static void torture_buffer_get_ssh_string(void **state) {
+static void torture_ssh_buffer_get_ssh_string(void **state) {
   ssh_buffer buffer;
   int i,j,k,l, rc;
   /* some values that can go wrong */
@@ -115,13 +115,13 @@ static void torture_buffer_get_ssh_string(void **state) {
         assert_non_null(buffer);
 
         for(l=0;l<k;++l){
-          rc = buffer_add_u32(buffer,htonl(values[i]));
+          rc = ssh_buffer_add_u32(buffer,htonl(values[i]));
           assert_int_equal(rc, 0);
         }
         rc = ssh_buffer_add_data(buffer,data,j);
         assert_int_equal(rc, 0);
         for(l=0;l<k;++l){
-          ssh_string str = buffer_get_ssh_string(buffer);
+          ssh_string str = ssh_buffer_get_ssh_string(buffer);
           assert_null(str);
           ssh_string_free(str);
         }
@@ -131,7 +131,7 @@ static void torture_buffer_get_ssh_string(void **state) {
   }
 }
 
-static void torture_buffer_add_format(void **state) {
+static void torture_ssh_buffer_add_format(void **state) {
     ssh_buffer buffer=*state;
     uint8_t b;
     uint16_t w;
@@ -155,14 +155,14 @@ static void torture_buffer_add_format(void **state) {
     rc=ssh_buffer_pack(buffer, "bwdqSsPt",b,w,d,q,s,"rocks",7,"So much","Fun!");
     assert_int_equal(rc, SSH_OK);
 
-    len = buffer_get_rest_len(buffer);
+    len = ssh_buffer_get_rest_len(buffer);
     assert_int_equal(len, sizeof(verif) - 1);
-    assert_memory_equal(buffer_get_rest(buffer), verif, sizeof(verif) -1);
+    assert_memory_equal(ssh_buffer_get_rest(buffer), verif, sizeof(verif) -1);
 
     ssh_string_free(s);
 }
 
-static void torture_buffer_get_format(void **state) {
+static void torture_ssh_buffer_get_format(void **state) {
     ssh_buffer buffer=*state;
     uint8_t b=0;
     uint16_t w=0;
@@ -199,14 +199,14 @@ static void torture_buffer_get_format(void **state) {
     assert_true(s2 != NULL);
     assert_memory_equal(s2, "So much", 7);
 
-    len = buffer_get_rest_len(buffer);
+    len = ssh_buffer_get_rest_len(buffer);
     assert_int_equal(len, 0);
     SAFE_FREE(s);
     SAFE_FREE(s1);
     SAFE_FREE(s2);
 }
 
-static void torture_buffer_get_format_error(void **state) {
+static void torture_ssh_buffer_get_format_error(void **state) {
     ssh_buffer buffer=*state;
     uint8_t b=0;
     uint16_t w=0;
@@ -262,10 +262,10 @@ int torture_run_tests(void) {
         cmocka_unit_test_setup_teardown(torture_growing_buffer, setup, teardown),
         cmocka_unit_test_setup_teardown(torture_growing_buffer_shifting, setup, teardown),
         cmocka_unit_test_setup_teardown(torture_buffer_prepend, setup, teardown),
-        cmocka_unit_test(torture_buffer_get_ssh_string),
-        cmocka_unit_test_setup_teardown(torture_buffer_add_format, setup, teardown),
-        cmocka_unit_test_setup_teardown(torture_buffer_get_format, setup, teardown),
-        cmocka_unit_test_setup_teardown(torture_buffer_get_format_error, setup, teardown),
+        cmocka_unit_test(torture_ssh_buffer_get_ssh_string),
+        cmocka_unit_test_setup_teardown(torture_ssh_buffer_add_format, setup, teardown),
+        cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format, setup, teardown),
+        cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format_error, setup, teardown),
         cmocka_unit_test_setup_teardown(torture_buffer_pack_badformat, setup, teardown)
     };
 
-- 
2.4.3


Follow-Ups:
Re: [PATCH 04/11] cleanup: use ssh_ prefix in the buffer (non-static) functionsFabiano Fidêncio <fidencio@xxxxxxxxxx>
References:
[PATCH 00/11] cleanup and removing some warningsFabiano Fidêncio <fidencio@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org