ssh-ed25519.c (294328) | ssh-ed25519.c (294332) |
---|---|
1/* $OpenBSD: ssh-ed25519.c,v 1.4 2014/06/24 01:13:21 djm Exp $ */ | 1/* $OpenBSD: ssh-ed25519.c,v 1.6 2015/01/15 21:38:50 markus Exp $ */ |
2/* 3 * Copyright (c) 2013 Markus Friedl <markus@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- 10 unchanged lines hidden (view full) --- 20#include <sys/types.h> 21#include <limits.h> 22 23#include "crypto_api.h" 24 25#include <string.h> 26#include <stdarg.h> 27 | 2/* 3 * Copyright (c) 2013 Markus Friedl <markus@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- 10 unchanged lines hidden (view full) --- 20#include <sys/types.h> 21#include <limits.h> 22 23#include "crypto_api.h" 24 25#include <string.h> 26#include <stdarg.h> 27 |
28#include "xmalloc.h" | |
29#include "log.h" | 28#include "log.h" |
30#include "buffer.h" | 29#include "sshbuf.h" |
31#define SSHKEY_INTERNAL 32#include "sshkey.h" 33#include "ssherr.h" 34#include "ssh.h" 35 36int 37ssh_ed25519_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, 38 const u_char *data, size_t datalen, u_int compat) --- 84 unchanged lines hidden (view full) --- 123 if (sshbuf_len(b) != 0) { 124 r = SSH_ERR_UNEXPECTED_TRAILING_DATA; 125 goto out; 126 } 127 if (len > crypto_sign_ed25519_BYTES) { 128 r = SSH_ERR_INVALID_FORMAT; 129 goto out; 130 } | 30#define SSHKEY_INTERNAL 31#include "sshkey.h" 32#include "ssherr.h" 33#include "ssh.h" 34 35int 36ssh_ed25519_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, 37 const u_char *data, size_t datalen, u_int compat) --- 84 unchanged lines hidden (view full) --- 122 if (sshbuf_len(b) != 0) { 123 r = SSH_ERR_UNEXPECTED_TRAILING_DATA; 124 goto out; 125 } 126 if (len > crypto_sign_ed25519_BYTES) { 127 r = SSH_ERR_INVALID_FORMAT; 128 goto out; 129 } |
131 if (datalen >= SIZE_MAX - len) 132 return SSH_ERR_INVALID_ARGUMENT; | 130 if (datalen >= SIZE_MAX - len) { 131 r = SSH_ERR_INVALID_ARGUMENT; 132 goto out; 133 } |
133 smlen = len + datalen; 134 mlen = smlen; | 134 smlen = len + datalen; 135 mlen = smlen; |
135 if ((sm = malloc(smlen)) == NULL || (m = xmalloc(mlen)) == NULL) { | 136 if ((sm = malloc(smlen)) == NULL || (m = malloc(mlen)) == NULL) { |
136 r = SSH_ERR_ALLOC_FAIL; 137 goto out; 138 } 139 memcpy(sm, sigblob, len); 140 memcpy(sm+len, data, datalen); 141 if ((ret = crypto_sign_ed25519_open(m, &mlen, sm, smlen, 142 key->ed25519_pk)) != 0) { 143 debug2("%s: crypto_sign_ed25519_open failed: %d", --- 14 unchanged lines hidden (view full) --- 158 if (m != NULL) { 159 explicit_bzero(m, smlen); /* NB mlen may be invalid if r != 0 */ 160 free(m); 161 } 162 sshbuf_free(b); 163 free(ktype); 164 return r; 165} | 137 r = SSH_ERR_ALLOC_FAIL; 138 goto out; 139 } 140 memcpy(sm, sigblob, len); 141 memcpy(sm+len, data, datalen); 142 if ((ret = crypto_sign_ed25519_open(m, &mlen, sm, smlen, 143 key->ed25519_pk)) != 0) { 144 debug2("%s: crypto_sign_ed25519_open failed: %d", --- 14 unchanged lines hidden (view full) --- 159 if (m != NULL) { 160 explicit_bzero(m, smlen); /* NB mlen may be invalid if r != 0 */ 161 free(m); 162 } 163 sshbuf_free(b); 164 free(ktype); 165 return r; 166} |
166 | |