From: "Dmitry S. Kravtsov" Date: 2012-05-29T14:26:24+09:00 Subject: Re: does this leak more than the size of the string via timing side channels --e89a8ff24819478dbe04c126135e Content-Type: text/plain; charset=UTF-8 Whoops, my mistake -- your code behaves exactly like testing string for equality. So you can return computed_mac == presented_mac Anyway I didn't understand what you're trying to achieve 2012/5/29 Dmitry S. Kravtsov > In your example you simply testing two strings for equality, with > exception that when strings have different lengths you return true. > So your example can be written as this: > def message_authentic?(ciphertext, key, presented_mac) > computed_mac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, > OpenSSL::Digest::SHA256.new("mac" + key).to_s, ciphertext) > > computed_mac.length != presented_mac.length or computed_mac == > presented_mac > end > > 2012/5/29 rooby shoez > >> yuck the first example has issues I just realized, how about this way: >> >> >> def message_authentic?(ciphertext, key, presented_mac) >> computed_mac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, >> OpenSSL::Digest::SHA256.new("mac" + key).to_s, ciphertext) >> a = [true] >> if computed_mac.length == presented_mac.length then >> computer_mac.length.times do |i| >> a += [computed_mac[i] == presented_mac[i]] >> end >> mac_verifies = a.inject(:==) >> end >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > > > -- > Dmitry S. Kravtsov > -- Dmitry S. Kravtsov --e89a8ff24819478dbe04c126135e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Whoops, my mistake -- your code behaves exactly like testing string for equ= ality. So you
can return=C2=A0computed_mac =3D=3D presented= _mac

Anyway I didn't understand what you're trying to= achieve

2012/5/29 Dmitry S. Kravtsov <idkravitz@g= mail.com>
In your example you simply testing two strings for equali= ty, with exception that when strings have different lengths you return true= .
So your example can be written as this:
def message_authentic?(ciphertext, key, presented_mac) computed_mac =3D OpenSSL::HMAC.digest(OpenSSL::Digest::S= HA256.new,
OpenSSL::Digest::SHA256.new("m= ac" + key).to_s, ciphertext)

computed_mac.length !=3D presen= ted_mac.length or computed_mac =3D=3D presented_mac
end

2012= /5/29 rooby shoez <lists@ruby-forum.com>
yuck the first example has issues I just rea= lized, how about this way:


def message_authentic?(ciphertext, key, presented_mac)
computed_mac =3D OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new,
OpenSSL::Digest::SHA256.new("mac" + key).to_s, ciphertext)
a =3D [true]
if computed_mac.length =3D=3D presented_mac.length then
computer_mac.length.times do |i|
a +=3D [computed_mac[i] =3D=3D presented_mac[i]]
end
mac_verifies =3D a.inject(:=3D=3D)
end



<= /div>--
Dmitry S. Kravts= ov



--
Dmitry S. Kr= avtsov
--e89a8ff24819478dbe04c126135e--