2012/5/29 Dmitry S. Kravtsov <idkravitz / gmail.com>:
> Ok, now I get it,
> well I may only suggest to use high order functions, and write it like th=
is:
>
> if computed_mac.length =3D=3D presented_mac.length then
> =A0 computed_mac.chars.zip(presented_mac.chars).map {|x,y| x =3D=3D y}.al=
l?
> end
>

all? will be most likely short-circuiting, too, so this has the same
problem as using =3D=3D.

There's two ways I know that security folks have approved of:

1. As it is done in eql_time_cmp in [1].

2. sha =3D OpenSSL::Digest::SHA256.new
    if sha.digest(computed_mac) =3D=3D sha.digest(presented_mac)
      ..
    end

Although some say that there is even a problem with the first method:
An extremely
optimized (byte code) compiler could figure out what we're trying to
do there and "help"
us in short-circuiting again. This won't apply to the second method, though=
.


[1] http://www.ruby-doc.org/stdlib-2.0/libdoc/openssl/rdoc/OpenSSL/PKCS5.ht=
ml