PRF and handshake hash revision.

Change handshake hash array into a single digest context simplifying the
handhake hash code. Use EVP_md5_sha1() if needed for handshake hashes in
TLS 1.1 and earlier.

Simplify PRF code to also use a single digest and treat EVP_md5_sha1()
as a special case.

Modify algorithm2 field of ciphers to use a single index value for handshake
hash and PRF instead of a bitmap.

Reviewed-by: Matt Caswell <matt@openssl.org>
This commit is contained in:
Dr. Stephen Henson
2015-11-25 18:20:50 +00:00
parent 2a9b96548a
commit 28ba2541f9
6 changed files with 137 additions and 230 deletions

View File

@@ -3335,27 +3335,17 @@ void ssl_clear_hash_ctx(EVP_MD_CTX **hash)
/* Retrieve handshake hashes */
int ssl_handshake_hash(SSL *s, unsigned char *out, int outlen)
{
unsigned char *p = out;
int idx, ret = 0;
long mask;
EVP_MD_CTX ctx;
const EVP_MD *md;
EVP_MD_CTX *hdgst = s->s3->handshake_dgst;
int ret = EVP_MD_CTX_size(hdgst);
EVP_MD_CTX_init(&ctx);
for (idx = 0; ssl_get_handshake_digest(idx, &mask, &md); idx++) {
if (mask & ssl_get_algorithm2(s)) {
int hashsize = EVP_MD_size(md);
EVP_MD_CTX *hdgst = s->s3->handshake_dgst[idx];
if (!hdgst || hashsize < 0 || hashsize > outlen)
goto err;
if (!EVP_MD_CTX_copy_ex(&ctx, hdgst))
goto err;
if (!EVP_DigestFinal_ex(&ctx, p, NULL))
goto err;
p += hashsize;
outlen -= hashsize;
}
if (ret < 0 || ret > outlen) {
ret = 0;
goto err;
}
ret = p - out;
if (!EVP_MD_CTX_copy_ex(&ctx, hdgst)
|| EVP_DigestFinal_ex(&ctx, out, NULL) <= 0)
ret = 0;
err:
EVP_MD_CTX_cleanup(&ctx);
return ret;