aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssl/src/ssl_tls1.erl
diff options
context:
space:
mode:
authorAndreas Schultz <[email protected]>2012-06-15 17:35:58 +0200
committerIngela Anderton Andin <[email protected]>2012-08-22 14:00:43 +0200
commit571133751287d93598dc90fe90b58ab4580f4836 (patch)
treebd265955a8e32f871d94ff66afb09d3d85e24184 /lib/ssl/src/ssl_tls1.erl
parent0c692262d9be40ba1d2565ee5f663c70e9c630b1 (diff)
downloadotp-571133751287d93598dc90fe90b58ab4580f4836.tar.gz
otp-571133751287d93598dc90fe90b58ab4580f4836.tar.bz2
otp-571133751287d93598dc90fe90b58ab4580f4836.zip
ssl: Calculate handshake hash only when needed
TLS/SSL version before 1.2 always used a MD5/SHA combination for the handshake hashes. With TLS 1.2 the default hash is SHA256 and it is possible to negotiate a different hash. This change delays the calculation of the handshake hashes until they are really needed. At that point the hash to use should be known. For now MD5/SHA is still hard coded.
Diffstat (limited to 'lib/ssl/src/ssl_tls1.erl')
-rw-r--r--lib/ssl/src/ssl_tls1.erl25
1 files changed, 10 insertions, 15 deletions
diff --git a/lib/ssl/src/ssl_tls1.erl b/lib/ssl/src/ssl_tls1.erl
index c8aae34892..d64a8f815d 100644
--- a/lib/ssl/src/ssl_tls1.erl
+++ b/lib/ssl/src/ssl_tls1.erl
@@ -44,9 +44,9 @@ master_secret(PreMasterSecret, ClientRandom, ServerRandom) ->
prf(PreMasterSecret, <<"master secret">>,
[ClientRandom, ServerRandom], 48).
--spec finished(client | server, binary(), {binary(), binary()}) -> binary().
+-spec finished(client | server, binary(), [binary()]) -> binary().
-finished(Role, MasterSecret, {MD5Hash, SHAHash}) ->
+finished(Role, MasterSecret, Handshake) ->
%% RFC 2246 & 4346 - 7.4.9. Finished
%% struct {
%% opaque verify_data[12];
@@ -55,19 +55,19 @@ finished(Role, MasterSecret, {MD5Hash, SHAHash}) ->
%% verify_data
%% PRF(master_secret, finished_label, MD5(handshake_messages) +
%% SHA-1(handshake_messages)) [0..11];
- MD5 = hash_final(?MD5, MD5Hash),
- SHA = hash_final(?SHA, SHAHash),
+ MD5 = crypto:md5(Handshake),
+ SHA = crypto:sha(Handshake),
prf(MasterSecret, finished_label(Role), [MD5, SHA], 12).
--spec certificate_verify(OID::tuple(), {binary(), binary()}) -> binary().
+-spec certificate_verify(OID::tuple(), [binary()]) -> binary().
-certificate_verify(?'rsaEncryption', {MD5Hash, SHAHash}) ->
- MD5 = hash_final(?MD5, MD5Hash),
- SHA = hash_final(?SHA, SHAHash),
+certificate_verify(?'rsaEncryption', Handshake) ->
+ MD5 = crypto:md5(Handshake),
+ SHA = crypto:sha(Handshake),
<<MD5/binary, SHA/binary>>;
-certificate_verify(?'id-dsa', {_, SHAHash}) ->
- hash_final(?SHA, SHAHash).
+certificate_verify(?'id-dsa', Handshake) ->
+ crypto:sha(Handshake).
-spec setup_keys(binary(), binary(), binary(), integer(),
integer(), integer()) -> {binary(), binary(), binary(),
@@ -228,8 +228,3 @@ finished_label(client) ->
<<"client finished">>;
finished_label(server) ->
<<"server finished">>.
-
-hash_final(?MD5, Conntext) ->
- crypto:md5_final(Conntext);
-hash_final(?SHA, Conntext) ->
- crypto:sha_final(Conntext).