Skip Menu |

This queue is for tickets about the Digest-SHA CPAN distribution.

Report information
The Basics
Id: 85781
Status: rejected
Priority: 0/
Queue: Digest-SHA

People
Owner: Nobody in particular
Requestors: dagolden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Concerns about constant-time HMAC comparison
I was recently pointed to String::Compare::ConstantTime and warned about the risks in using Perl's 'eq' operator to compare HMACs. I would suggest you consider adding an equivalent function -- which I admit is a bit of API bloat -- or at least mention in the documentation that HMACs shouldn't be compared with eq and suggest some options. String::Compare::ConstantTime uses XS and is quite fast. I believe a roughly-comparable pure-perl alternative would be C<< 0 == unpack("%32C*", $got ^ $expect) >>. Regards, David
Your suggestion might indeed be useful as part of a toolkit module for cryptographic application developers. I would encourage you to pursue that idea, or to collaborate with others who might already be working on such a module. But realize that timing attacks are just one small slice of the myriad threats that such developers need to be concerned about. Focusing solely on timing attacks is both insufficient and arbitrary. Timing attacks can be relevant to any process using secrets (keys), not just to HMAC algorithms. More importantly in this case, the timing attacks wouldn't actually be performed on the HMACs themselves: they are assumed to be public. Only the keys are hidden. Note that the HMAC algorithm uses the key exclusively during initialization of the digest context (ref. hmacopen), which is a very small part of the overall digest computation. It's difficult to see how an eavesdropper could obtain any reliable information about the key from timing data on the hmac functions.
Subject: Re: [rt.cpan.org #85781] Concerns about constant-time HMAC comparison
Date: Sat, 1 Jun 2013 23:15:30 -0400
To: bug-Digest-SHA [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
As it was explained to me, given an arbitrary (hostile) message, enough randomly-generated MACs get sent to allow statistical analysis of the timing. Because standard 'eq' shortcuts once there is a byte difference, timing analysis reveals the first byte of the correct MAC for that message -- without knowledge of the key. Etc. until the entire MAC for the message is discovered. A constant-time equality comparison ensures there's no way to determine how much of a MAC is correct and thus no way to use a timing attack to forge a MAC without the key. I would assume the usual real-world practicality of such an attack apply, but it was something that I never considered. So a little note along the lines of "hey, when you check the HMAC, don't use 'eq'" would be enough to help clue in the clueless. :-) David On Sat, Jun 1, 2013 at 11:52 AM, Mark Shelor via RT <bug-Digest-SHA@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=85781 > > > Your suggestion might indeed be useful as part of a toolkit module for cryptographic application developers. I would encourage you to pursue that idea, or to collaborate with others who might already be working on such a module. > > But realize that timing attacks are just one small slice of the myriad threats that such developers need to be concerned about. Focusing solely on timing attacks is both insufficient and arbitrary. > > Timing attacks can be relevant to any process using secrets (keys), not just to HMAC algorithms. More importantly in this case, the timing attacks wouldn't actually be performed on the HMACs themselves: they are assumed to be public. Only the keys are hidden. > > Note that the HMAC algorithm uses the key exclusively during initialization of the digest context (ref. hmacopen), which is a very small part of the overall digest computation. It's difficult to see how an eavesdropper could obtain any reliable information about the key from timing data on the hmac functions.
-- David Golden <dagolden@cpan.org> Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg
Indeed, that's how one particular variant of a timing attack works. But discovering a MAC by such a process is useless because--as stated previously--the MAC is already public to begin with. The goal of the attacker is to discover the *key*, not the MAC. Without the key, it's impossible to forge a correct MAC for a given arbitrary message. When an eavesdropper sees a particular message with corresponding MAC pass over the network, he now knows the correct MAC for that message. This means that the eavesdropper could now spoof the receiver by sending that same message (and MAC) again. This is known as a replay attack. However such attacks are usually foiled by insisting that the message contain a random nonce or sequence number such that all messages to the receiver are guaranteed to be distinct. Because each message is distinct, each MAC will be distinct as well and therefore can't be forged without knowledge of the key. Threat scenarios are varied and complex. Oftentimes, special protocols need to be employed to combat them. But this is in the province of the cryptographic application developer, not the digest algorithm implementer. The sole purpose of Digest::SHA is to implement the FIPS 180-4 algorithms in a complete, compact, efficient, and easy-to-use set of routines accessible to the Perl programmer. Documenting the myriad threat scenarios relevant to cryptographic application developers is clearly outside the scope of the Digest::SHA module. Even mentioning particular instances of such threats is irresponsible since it would give the mis-impression that the module also serves as a tutorial to cryptographic application developers, which it clearly is not. Such tutorials are best left to experts in that area. Mark On Sat Jun 01 23:16:16 2013, DAGOLDEN wrote: Show quoted text
> As it was explained to me, given an arbitrary (hostile) message, > enough randomly-generated MACs get sent to allow statistical analysis > of the timing. Because standard 'eq' shortcuts once there is a byte > difference, timing analysis reveals the first byte of the correct MAC > for that message -- without knowledge of the key. Etc. until the > entire MAC for the message is discovered. A constant-time equality > comparison ensures there's no way to determine how much of a MAC is > correct and thus no way to use a timing attack to forge a MAC without > the key. > > I would assume the usual real-world practicality of such an attack > apply, but it was something that I never considered. So a little note > along the lines of "hey, when you check the HMAC, don't use 'eq'" > would be enough to help clue in the clueless. :-) > > David > > > On Sat, Jun 1, 2013 at 11:52 AM, Mark Shelor via RT > <bug-Digest-SHA@rt.cpan.org> wrote:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=85781 > > > > > Your suggestion might indeed be useful as part of a toolkit module
> for cryptographic application developers. I would encourage you to > pursue that idea, or to collaborate with others who might already > be working on such a module.
> > > > But realize that timing attacks are just one small slice of the
> myriad threats that such developers need to be concerned about. > Focusing solely on timing attacks is both insufficient and > arbitrary.
> > > > Timing attacks can be relevant to any process using secrets (keys),
> not just to HMAC algorithms. More importantly in this case, the > timing attacks wouldn't actually be performed on the HMACs > themselves: they are assumed to be public. Only the keys are > hidden.
> > > > Note that the HMAC algorithm uses the key exclusively during
> initialization of the digest context (ref. hmacopen), which is a > very small part of the overall digest computation. It's difficult > to see how an eavesdropper could obtain any reliable information > about the key from timing data on the hmac functions. > > >
Subject: Re: [rt.cpan.org #85781] Concerns about constant-time HMAC comparison
Date: Sun, 2 Jun 2013 14:47:44 -0400
To: bug-Digest-SHA [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
On Sun, Jun 2, 2013 at 5:04 AM, Mark Shelor via RT <bug-Digest-SHA@rt.cpan.org> wrote: Show quoted text
> Indeed, that's how one particular variant of a timing attack works. But discovering a MAC by such a process is useless because--as stated previously--the MAC is already public to begin with. The goal of the attacker is to discover the *key*, not the MAC. Without the key, it's impossible to forge a correct MAC for a given arbitrary message.
You've misunderstood me. The timing attack doesn't reveal the key. It discovers a valid MAC for an arbitrary message *without* knowing the key. E.g. for a given message (including nonce value), create 256 MACs with different first bytes. Send thousands of those to the server and recording timing of failure. 1 of those 256 will take longer because the server checked two bytes of the string to find inequality instead of just one byte. Now the first byte of the MAC for that message is known. Create 256 MACs with the discovered first byte and different second bytes. Send thousands of those. Again, one of the 256 will take longer. Repeat until the correct MAC for the arbitrary message is discovered. See http://rdist.root.org/2009/05/28/timing-attack-in-google-keyczar-library/ for more. That said, I can respect your position that you don't want Digest::SHA to attempt to be a crypto tutorial. Please feel free to close the ticket. Regards, David -- David Golden <dagolden@cpan.org> Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg
I see. Thanks for the clarification. We nonetheless concur on the main point that such attacks are beyond the scope of Digest::SHA to either handle or document. However, that fact doesn't cause your original concern to disappear. So the question becomes: where and how do you intend to address it? You might have the basis there for a new and very useful CPAN module. A daunting task, though. Mark On Sun Jun 02 14:48:29 2013, DAGOLDEN wrote: Show quoted text
> On Sun, Jun 2, 2013 at 5:04 AM, Mark Shelor via RT > <bug-Digest-SHA@rt.cpan.org> wrote:
> > Indeed, that's how one particular variant of a timing attack works.
> But discovering a MAC by such a process is useless because--as > stated previously--the MAC is already public to begin with. The > goal of the attacker is to discover the *key*, not the MAC. > Without the key, it's impossible to forge a correct MAC for a given > arbitrary message. > > You've misunderstood me. The timing attack doesn't reveal the key. > It discovers a valid MAC for an arbitrary message *without* knowing > the key. E.g. for a given message (including nonce value), create 256 > MACs with different first bytes. Send thousands of those to the > server and recording timing of failure. 1 of those 256 will take > longer because the server checked two bytes of the string to find > inequality instead of just one byte. Now the first byte of the MAC > for that message is known. Create 256 MACs with the discovered first > byte and different second bytes. Send thousands of those. Again, one > of the 256 will take longer. Repeat until the correct MAC for the > arbitrary message is discovered. > > See http://rdist.root.org/2009/05/28/timing-attack-in-google-keyczar- > library/ > for more. > > That said, I can respect your position that you don't want Digest::SHA > to attempt to be a crypto tutorial. Please feel free to close the > ticket. > > Regards, > David > > -- > David Golden <dagolden@cpan.org> > Take back your inbox! → http://www.bunchmail.com/ > Twitter/IRC: @xdg
Subject: Re: [rt.cpan.org #85781] Concerns about constant-time HMAC comparison
Date: Sun, 2 Jun 2013 21:12:48 -0400
To: bug-Digest-SHA [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
I think that String::Compare::ConstantTime does a fair job at documenting the issues, but what really seems to be needed is a higher-level crypto library that helps people not shoot themselves in the foot. I'm pretty sure I'm not qualified to do an excellent job of it, but maybe I can start a project and rally participants. Sort of the crypto equivalent of the DateTime project. David On Sun, Jun 2, 2013 at 8:12 PM, Mark Shelor via RT <bug-Digest-SHA@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=85781 > > > I see. Thanks for the clarification. > > We nonetheless concur on the main point that such attacks are beyond the scope of Digest::SHA to either handle or document. However, that fact doesn't cause your original concern to disappear. So the question becomes: where and how do you intend to address it? You might have the basis there for a new and very useful CPAN module. A daunting task, though. > > Mark > > > On Sun Jun 02 14:48:29 2013, DAGOLDEN wrote:
>> On Sun, Jun 2, 2013 at 5:04 AM, Mark Shelor via RT >> <bug-Digest-SHA@rt.cpan.org> wrote:
>> > Indeed, that's how one particular variant of a timing attack works.
>> But discovering a MAC by such a process is useless because--as >> stated previously--the MAC is already public to begin with. The >> goal of the attacker is to discover the *key*, not the MAC. >> Without the key, it's impossible to forge a correct MAC for a given >> arbitrary message. >> >> You've misunderstood me. The timing attack doesn't reveal the key. >> It discovers a valid MAC for an arbitrary message *without* knowing >> the key. E.g. for a given message (including nonce value), create 256 >> MACs with different first bytes. Send thousands of those to the >> server and recording timing of failure. 1 of those 256 will take >> longer because the server checked two bytes of the string to find >> inequality instead of just one byte. Now the first byte of the MAC >> for that message is known. Create 256 MACs with the discovered first >> byte and different second bytes. Send thousands of those. Again, one >> of the 256 will take longer. Repeat until the correct MAC for the >> arbitrary message is discovered. >> >> See http://rdist.root.org/2009/05/28/timing-attack-in-google-keyczar- >> library/ >> for more. >> >> That said, I can respect your position that you don't want Digest::SHA >> to attempt to be a crypto tutorial. Please feel free to close the >> ticket. >> >> Regards, >> David >> >> -- >> David Golden <dagolden@cpan.org> >> Take back your inbox! → http://www.bunchmail.com/ >> Twitter/IRC: @xdg
> > >
-- David Golden <dagolden@cpan.org> Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg