[key.c monitor_wrap.c ssh-dss.c ssh-rsa.c]
     don't allocate, copy, and discard if there is not interested in the data;
     ok deraadt@
This commit is contained in:
Ben Lindstrom 2002-07-07 22:13:31 +00:00
parent 8b2eecdf9f
commit 2bf759cba5
5 changed files with 38 additions and 46 deletions

View File

@ -12,6 +12,10 @@
- deraadt@cvs.openbsd.org 2002/07/04 08:12:15 - deraadt@cvs.openbsd.org 2002/07/04 08:12:15
[channels.c packet.c] [channels.c packet.c]
blah blah minor nothing as i read and re-read and re-read... blah blah minor nothing as i read and re-read and re-read...
- markus@cvs.openbsd.org 2002/07/04 10:41:47
[key.c monitor_wrap.c ssh-dss.c ssh-rsa.c]
don't allocate, copy, and discard if there is not interested in the data;
ok deraadt@
20020705 20020705
- (tim) [configure.ac] AIX 4.2.1 has authenticate() in libs. - (tim) [configure.ac] AIX 4.2.1 has authenticate() in libs.
@ -1295,4 +1299,4 @@
- (stevesk) entropy.c: typo in debug message - (stevesk) entropy.c: typo in debug message
- (djm) ssh-keygen -i needs seeded RNG; report from markus@ - (djm) ssh-keygen -i needs seeded RNG; report from markus@
$Id: ChangeLog,v 1.2343 2002/07/07 22:11:51 mouring Exp $ $Id: ChangeLog,v 1.2344 2002/07/07 22:13:31 mouring Exp $

17
key.c
View File

@ -32,7 +32,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: key.c,v 1.47 2002/07/04 04:15:33 deraadt Exp $"); RCSID("$OpenBSD: key.c,v 1.48 2002/07/04 10:41:47 markus Exp $");
#include <openssl/evp.h> #include <openssl/evp.h>
@ -729,7 +729,6 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
{ {
Buffer b; Buffer b;
int len; int len;
u_char *buf;
if (key == NULL) { if (key == NULL) {
error("key_to_blob: key == NULL"); error("key_to_blob: key == NULL");
@ -755,16 +754,14 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
return 0; return 0;
} }
len = buffer_len(&b); len = buffer_len(&b);
buf = xmalloc(len);
memcpy(buf, buffer_ptr(&b), len);
memset(buffer_ptr(&b), 0, len);
buffer_free(&b);
if (lenp != NULL) if (lenp != NULL)
*lenp = len; *lenp = len;
if (blobp != NULL) if (blobp != NULL) {
*blobp = buf; *blobp = xmalloc(len);
else memcpy(*blobp, buffer_ptr(&b), len);
xfree(buf); }
memset(buffer_ptr(&b), 0, len);
buffer_free(&b);
return len; return len;
} }

View File

@ -25,7 +25,7 @@
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: monitor_wrap.c,v 1.15 2002/07/04 04:15:33 deraadt Exp $"); RCSID("$OpenBSD: monitor_wrap.c,v 1.16 2002/07/04 10:41:47 markus Exp $");
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/dh.h> #include <openssl/dh.h>
@ -446,7 +446,6 @@ mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp)
{ {
Buffer b; Buffer b;
int len; int len;
u_char *buf;
Enc *enc; Enc *enc;
Mac *mac; Mac *mac;
Comp *comp; Comp *comp;
@ -484,16 +483,14 @@ mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp)
buffer_put_cstring(&b, comp->name); buffer_put_cstring(&b, comp->name);
len = buffer_len(&b); len = buffer_len(&b);
buf = xmalloc(len);
memcpy(buf, buffer_ptr(&b), len);
memset(buffer_ptr(&b), 0, len);
buffer_free(&b);
if (lenp != NULL) if (lenp != NULL)
*lenp = len; *lenp = len;
if (blobp != NULL) if (blobp != NULL) {
*blobp = buf; *blobp = xmalloc(len);
else memcpy(*blobp, buffer_ptr(&b), len);
xfree(blobp); }
memset(buffer_ptr(&b), 0, len);
buffer_free(&b);
return len; return len;
} }

View File

@ -23,7 +23,7 @@
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: ssh-dss.c,v 1.16 2002/07/04 04:15:33 deraadt Exp $"); RCSID("$OpenBSD: ssh-dss.c,v 1.17 2002/07/04 10:41:47 markus Exp $");
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/evp.h> #include <openssl/evp.h>
@ -46,7 +46,7 @@ ssh_dss_sign(Key *key, u_char **sigp, u_int *lenp,
DSA_SIG *sig; DSA_SIG *sig;
const EVP_MD *evp_md = EVP_sha1(); const EVP_MD *evp_md = EVP_sha1();
EVP_MD_CTX md; EVP_MD_CTX md;
u_char *ret, digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN]; u_char digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN];
u_int rlen, slen, len, dlen; u_int rlen, slen, len, dlen;
Buffer b; Buffer b;
@ -79,29 +79,25 @@ ssh_dss_sign(Key *key, u_char **sigp, u_int *lenp,
DSA_SIG_free(sig); DSA_SIG_free(sig);
if (datafellows & SSH_BUG_SIGBLOB) { if (datafellows & SSH_BUG_SIGBLOB) {
ret = xmalloc(SIGBLOB_LEN);
memcpy(ret, sigblob, SIGBLOB_LEN);
if (lenp != NULL) if (lenp != NULL)
*lenp = SIGBLOB_LEN; *lenp = SIGBLOB_LEN;
if (sigp != NULL) if (sigp != NULL) {
*sigp = ret; *sigp = xmalloc(SIGBLOB_LEN);
else memcpy(*sigp, sigblob, SIGBLOB_LEN);
xfree(ret); }
} else { } else {
/* ietf-drafts */ /* ietf-drafts */
buffer_init(&b); buffer_init(&b);
buffer_put_cstring(&b, "ssh-dss"); buffer_put_cstring(&b, "ssh-dss");
buffer_put_string(&b, sigblob, SIGBLOB_LEN); buffer_put_string(&b, sigblob, SIGBLOB_LEN);
len = buffer_len(&b); len = buffer_len(&b);
ret = xmalloc(len);
memcpy(ret, buffer_ptr(&b), len);
buffer_free(&b);
if (lenp != NULL) if (lenp != NULL)
*lenp = len; *lenp = len;
if (sigp != NULL) if (sigp != NULL) {
*sigp = ret; *sigp = xmalloc(len);
else memcpy(*sigp, buffer_ptr(&b), len);
xfree(ret); }
buffer_free(&b);
} }
return 0; return 0;
} }

View File

@ -23,7 +23,7 @@
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: ssh-rsa.c,v 1.22 2002/07/04 04:15:33 deraadt Exp $"); RCSID("$OpenBSD: ssh-rsa.c,v 1.23 2002/07/04 10:41:47 markus Exp $");
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/err.h> #include <openssl/err.h>
@ -44,7 +44,7 @@ ssh_rsa_sign(Key *key, u_char **sigp, u_int *lenp,
{ {
const EVP_MD *evp_md; const EVP_MD *evp_md;
EVP_MD_CTX md; EVP_MD_CTX md;
u_char digest[EVP_MAX_MD_SIZE], *sig, *ret; u_char digest[EVP_MAX_MD_SIZE], *sig;
u_int slen, dlen, len; u_int slen, dlen, len;
int ok, nid; int ok, nid;
Buffer b; Buffer b;
@ -90,18 +90,16 @@ ssh_rsa_sign(Key *key, u_char **sigp, u_int *lenp,
buffer_put_cstring(&b, "ssh-rsa"); buffer_put_cstring(&b, "ssh-rsa");
buffer_put_string(&b, sig, slen); buffer_put_string(&b, sig, slen);
len = buffer_len(&b); len = buffer_len(&b);
ret = xmalloc(len); if (lenp != NULL)
memcpy(ret, buffer_ptr(&b), len); *lenp = len;
if (sigp != NULL) {
*sigp = xmalloc(len);
memcpy(*sigp, buffer_ptr(&b), len);
}
buffer_free(&b); buffer_free(&b);
memset(sig, 's', slen); memset(sig, 's', slen);
xfree(sig); xfree(sig);
if (lenp != NULL)
*lenp = len;
if (sigp != NULL)
*sigp = ret;
else
xfree(ret);
return 0; return 0;
} }