[BACK]Return to bufaux.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/Attic/bufaux.c between version 1.52 and 1.56.4.1

version 1.52, 2013/07/12 00:19:58 version 1.56.4.1, 2014/04/21 00:30:48
Line 43 
Line 43 
   
 #include <string.h>  #include <string.h>
 #include <stdarg.h>  #include <stdarg.h>
   #include <stdlib.h>
   
 #include "xmalloc.h"  #include "xmalloc.h"
 #include "buffer.h"  #include "buffer.h"
Line 213 
Line 214 
                 if (cp == ret + length - 1)                  if (cp == ret + length - 1)
                         error("buffer_get_cstring_ret: string contains \\0");                          error("buffer_get_cstring_ret: string contains \\0");
                 else {                  else {
                         bzero(ret, length);                          explicit_bzero(ret, length);
                         free(ret);                          free(ret);
                         return NULL;                          return NULL;
                 }                  }
Line 312 
Line 313 
   
         buffer_append(buffer, &ch, 1);          buffer_append(buffer, &ch, 1);
 }  }
   
   /* Pseudo bignum functions */
   
   void *
   buffer_get_bignum2_as_string_ret(Buffer *buffer, u_int *length_ptr)
   {
           u_int len;
           u_char *bin, *p, *ret;
   
           if ((p = bin = buffer_get_string_ret(buffer, &len)) == NULL) {
                   error("%s: invalid bignum", __func__);
                   return NULL;
           }
   
           if (len > 0 && (bin[0] & 0x80)) {
                   error("%s: negative numbers not supported", __func__);
                   free(bin);
                   return NULL;
           }
           if (len > 8 * 1024) {
                   error("%s: cannot handle BN of size %d", __func__, len);
                   free(bin);
                   return NULL;
           }
           /* Skip zero prefix on numbers with the MSB set */
           if (len > 1 && bin[0] == 0x00 && (bin[1] & 0x80) != 0) {
                   p++;
                   len--;
           }
           ret = xmalloc(len);
           memcpy(ret, p, len);
           explicit_bzero(p, len);
           free(bin);
           return ret;
   }
   
   void *
   buffer_get_bignum2_as_string(Buffer *buffer, u_int *l)
   {
           void *ret = buffer_get_bignum2_as_string_ret(buffer, l);
   
           if (ret == NULL)
                   fatal("%s: buffer error", __func__);
           return ret;
   }
   
   /*
    * Stores a string using the bignum encoding rules (\0 pad if MSB set).
    */
   void
   buffer_put_bignum2_from_string(Buffer *buffer, const u_char *s, u_int l)
   {
           u_char *buf, *p;
           int pad = 0;
   
           if (l > 8 * 1024)
                   fatal("%s: length %u too long", __func__, l);
           /* Skip leading zero bytes */
           for (; l > 0 && *s == 0; l--, s++)
                   ;
           p = buf = xmalloc(l + 1);
           /*
            * If most significant bit is set then prepend a zero byte to
            * avoid interpretation as a negative number.
            */
           if (l > 0 && (s[0] & 0x80) != 0) {
                   *p++ = '\0';
                   pad = 1;
           }
           memcpy(p, s, l);
           buffer_put_string(buffer, buf, l + pad);
           explicit_bzero(buf, l + pad);
           free(buf);
   }
   
   

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.56.4.1