summaryrefslogtreecommitdiff
path: root/digest-openssl.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-07-02 15:28:02 +1000
committerDamien Miller <djm@mindrot.org>2014-07-02 15:28:02 +1000
commit8668706d0f52654fe64c0ca41a96113aeab8d2b8 (patch)
tree73e78e1ea3d39206e39870bbe0af17d6c430fb51 /digest-openssl.c
parent2cd7929250cf9e9f658d70dcd452f529ba08c942 (diff)
- djm@cvs.openbsd.org 2014/06/24 01:13:21
[Makefile.in auth-bsdauth.c auth-chall.c auth-options.c auth-rsa.c [auth2-none.c auth2-pubkey.c authfile.c authfile.h cipher-3des1.c [cipher-chachapoly.c cipher-chachapoly.h cipher.c cipher.h [digest-libc.c digest-openssl.c digest.h dns.c entropy.c hmac.h [hostfile.c key.c key.h krl.c monitor.c packet.c rsa.c rsa.h [ssh-add.c ssh-agent.c ssh-dss.c ssh-ecdsa.c ssh-ed25519.c [ssh-keygen.c ssh-pkcs11-client.c ssh-pkcs11-helper.c ssh-pkcs11.c [ssh-rsa.c sshbuf-misc.c sshbuf.h sshconnect.c sshconnect1.c [sshconnect2.c sshd.c sshkey.c sshkey.h [openbsd-compat/openssl-compat.c openbsd-compat/openssl-compat.h] New key API: refactor key-related functions to be more library-like, existing API is offered as a set of wrappers. with and ok markus@ Thanks also to Ben Hawkes, David Tomaschik, Ivan Fratric, Matthew Dempsky and Ron Bowes for a detailed review a few months ago. NB. This commit also removes portable OpenSSH support for OpenSSL <0.9.8e.
Diffstat (limited to 'digest-openssl.c')
-rw-r--r--digest-openssl.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/digest-openssl.c b/digest-openssl.c
index 863d37d03..de0380135 100644
--- a/digest-openssl.c
+++ b/digest-openssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: digest-openssl.c,v 1.2 2014/02/02 03:44:31 djm Exp $ */ 1/* $OpenBSD: digest-openssl.c,v 1.3 2014/06/24 01:13:21 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2013 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -26,8 +26,9 @@
26 26
27#include "openbsd-compat/openssl-compat.h" 27#include "openbsd-compat/openssl-compat.h"
28 28
29#include "buffer.h" 29#include "sshbuf.h"
30#include "digest.h" 30#include "digest.h"
31#include "ssherr.h"
31 32
32struct ssh_digest_ctx { 33struct ssh_digest_ctx {
33 int alg; 34 int alg;
@@ -98,9 +99,11 @@ ssh_digest_start(int alg)
98int 99int
99ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to) 100ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to)
100{ 101{
102 if (from->alg != to->alg)
103 return SSH_ERR_INVALID_ARGUMENT;
101 /* we have bcopy-style order while openssl has memcpy-style */ 104 /* we have bcopy-style order while openssl has memcpy-style */
102 if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx)) 105 if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
103 return -1; 106 return SSH_ERR_LIBCRYPTO_ERROR;
104 return 0; 107 return 0;
105} 108}
106 109
@@ -108,14 +111,14 @@ int
108ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen) 111ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
109{ 112{
110 if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1) 113 if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
111 return -1; 114 return SSH_ERR_LIBCRYPTO_ERROR;
112 return 0; 115 return 0;
113} 116}
114 117
115int 118int
116ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, const Buffer *b) 119ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, const struct sshbuf *b)
117{ 120{
118 return ssh_digest_update(ctx, buffer_ptr(b), buffer_len(b)); 121 return ssh_digest_update(ctx, sshbuf_ptr(b), sshbuf_len(b));
119} 122}
120 123
121int 124int
@@ -125,13 +128,13 @@ ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen)
125 u_int l = dlen; 128 u_int l = dlen;
126 129
127 if (dlen > UINT_MAX) 130 if (dlen > UINT_MAX)
128 return -1; 131 return SSH_ERR_INVALID_ARGUMENT;
129 if (dlen < digest->digest_len) /* No truncation allowed */ 132 if (dlen < digest->digest_len) /* No truncation allowed */
130 return -1; 133 return SSH_ERR_INVALID_ARGUMENT;
131 if (EVP_DigestFinal_ex(&ctx->mdctx, d, &l) != 1) 134 if (EVP_DigestFinal_ex(&ctx->mdctx, d, &l) != 1)
132 return -1; 135 return SSH_ERR_LIBCRYPTO_ERROR;
133 if (l != digest->digest_len) /* sanity */ 136 if (l != digest->digest_len) /* sanity */
134 return -1; 137 return SSH_ERR_INTERNAL_ERROR;
135 return 0; 138 return 0;
136} 139}
137 140
@@ -149,18 +152,19 @@ int
149ssh_digest_memory(int alg, const void *m, size_t mlen, u_char *d, size_t dlen) 152ssh_digest_memory(int alg, const void *m, size_t mlen, u_char *d, size_t dlen)
150{ 153{
151 struct ssh_digest_ctx *ctx = ssh_digest_start(alg); 154 struct ssh_digest_ctx *ctx = ssh_digest_start(alg);
155 int r;
152 156
153 if (ctx == NULL) 157 if (ctx == NULL)
154 return -1; 158 return SSH_ERR_INVALID_ARGUMENT;
155 if (ssh_digest_update(ctx, m, mlen) != 0 || 159 if ((r = ssh_digest_update(ctx, m, mlen) != 0) ||
156 ssh_digest_final(ctx, d, dlen) != 0) 160 (r = ssh_digest_final(ctx, d, dlen) != 0))
157 return -1; 161 return r;
158 ssh_digest_free(ctx); 162 ssh_digest_free(ctx);
159 return 0; 163 return 0;
160} 164}
161 165
162int 166int
163ssh_digest_buffer(int alg, const Buffer *b, u_char *d, size_t dlen) 167ssh_digest_buffer(int alg, const struct sshbuf *b, u_char *d, size_t dlen)
164{ 168{
165 return ssh_digest_memory(alg, buffer_ptr(b), buffer_len(b), d, dlen); 169 return ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen);
166} 170}