[BACK]Return to sshbuf-misc.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / crypto / external / bsd / openssh / dist

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/crypto/external/bsd/openssh/dist/sshbuf-misc.c between version 1.8.8.2 and 1.9

version 1.8.8.2, 2017/08/15 04:53:01 version 1.9, 2019/10/12 18:32:22
Line 1 
Line 1 
 /*      $OpenBSD: sshbuf-misc.c,v 1.6 2016/05/02 08:49:03 djm Exp $     */  /*      $OpenBSD: sshbuf-misc.c,v 1.11 2019/07/30 05:04:49 djm Exp $    */
 /*  /*
  * Copyright (c) 2011 Damien Miller   * Copyright (c) 2011 Damien Miller
  *   *
Line 87  sshbuf_dtob16(struct sshbuf *buf)
Line 87  sshbuf_dtob16(struct sshbuf *buf)
         return ret;          return ret;
 }  }
   
   int
   sshbuf_dtob64(const struct sshbuf *d, struct sshbuf *b64, int wrap)
   {
           size_t i, slen = 0;
           char *s = NULL;
           int r;
   
           if (d == NULL || b64 == NULL || sshbuf_len(d) >= SIZE_MAX / 2)
                   return SSH_ERR_INVALID_ARGUMENT;
           if (sshbuf_len(d) == 0)
                   return 0;
           slen = ((sshbuf_len(d) + 2) / 3) * 4 + 1;
           if ((s = malloc(slen)) == NULL)
                   return SSH_ERR_ALLOC_FAIL;
           if (b64_ntop(sshbuf_ptr(d), sshbuf_len(d), s, slen) == -1) {
                   r = SSH_ERR_INTERNAL_ERROR;
                   goto fail;
           }
           if (wrap) {
                   for (i = 0; s[i] != '\0'; i++) {
                           if ((r = sshbuf_put_u8(b64, s[i])) != 0)
                                   goto fail;
                           if (i % 70 == 69 && (r = sshbuf_put_u8(b64, '\n')) != 0)
                                   goto fail;
                   }
                   if ((i - 1) % 70 != 69 && (r = sshbuf_put_u8(b64, '\n')) != 0)
                           goto fail;
           } else {
                   if ((r = sshbuf_put(b64, s, strlen(s))) != 0)
                           goto fail;
           }
           /* Success */
           r = 0;
    fail:
           freezero(s, slen);
           return r;
   }
   
 char *  char *
 sshbuf_dtob64(struct sshbuf *buf)  sshbuf_dtob64_string(const struct sshbuf *buf, int wrap)
 {  {
         size_t len = sshbuf_len(buf), plen;          struct sshbuf *tmp;
         const u_char *p = sshbuf_ptr(buf);  
         char *ret;          char *ret;
         int r;  
   
         if (len == 0)          if ((tmp = sshbuf_new()) == NULL)
                 return strdup("");  
         plen = ((len + 2) / 3) * 4 + 1;  
         if (SIZE_MAX / 2 <= len || (ret = malloc(plen)) == NULL)  
                 return NULL;                  return NULL;
         if ((r = b64_ntop(p, len, ret, plen)) == -1) {          if (sshbuf_dtob64(buf, tmp, wrap) != 0) {
                 explicit_bzero(ret, plen);                  sshbuf_free(tmp);
                 free(ret);  
                 return NULL;                  return NULL;
         }          }
           ret = sshbuf_dup_string(tmp);
           sshbuf_free(tmp);
         return ret;          return ret;
 }  }
   
Line 157  sshbuf_dup_string(struct sshbuf *buf)
Line 191  sshbuf_dup_string(struct sshbuf *buf)
         return r;          return r;
 }  }
   
   int
   sshbuf_cmp(const struct sshbuf *b, size_t offset,
       const void *s, size_t len)
   {
           if (sshbuf_ptr(b) == NULL)
                   return SSH_ERR_INTERNAL_ERROR;
           if (offset > SSHBUF_SIZE_MAX || len > SSHBUF_SIZE_MAX || len == 0)
                   return SSH_ERR_INVALID_ARGUMENT;
           if (offset + len > sshbuf_len(b))
                   return SSH_ERR_MESSAGE_INCOMPLETE;
           if (timingsafe_bcmp(sshbuf_ptr(b) + offset, s, len) != 0)
                   return SSH_ERR_INVALID_FORMAT;
           return 0;
   }
   
   int
   sshbuf_find(const struct sshbuf *b, size_t start_offset,
       const void *s, size_t len, size_t *offsetp)
   {
           void *p;
   
           if (offsetp != NULL)
                   *offsetp = 0;
           if (sshbuf_ptr(b) == NULL)
                   return SSH_ERR_INTERNAL_ERROR;
           if (start_offset > SSHBUF_SIZE_MAX || len > SSHBUF_SIZE_MAX || len == 0)
                   return SSH_ERR_INVALID_ARGUMENT;
           if (start_offset > sshbuf_len(b) || start_offset + len > sshbuf_len(b))
                   return SSH_ERR_MESSAGE_INCOMPLETE;
           if ((p = memmem(sshbuf_ptr(b) + start_offset,
               sshbuf_len(b) - start_offset, s, len)) == NULL)
                   return SSH_ERR_INVALID_FORMAT;
           if (offsetp != NULL)
                   *offsetp = (const u_char *)p - sshbuf_ptr(b);
           return 0;
   }

Legend:
Removed from v.1.8.8.2  
changed lines
  Added in v.1.9

CVSweb <webmaster@jp.NetBSD.org>