Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

Im just wondering ... Lets say, I want to compute an MD5 hash from a given buffer which is an empty (memset(buffer, ' ', sizeof(buffer));) buffer with size of 512. I also want to compute MD5 hash on same-sized buffer but non-empty one: memset(buffer, 'a', sizeof(buffer));.

Am I right that the speed of computation should be the same for those 2 buffers? I mean, I want to ask if MD4/MD5 (cryptographic algorithms in general) speed depends only on data size, not also on data content?

share|improve this question
1  
I've always thought of it on the ones and zeros level. Cryptographic algorithms should blindly operate on 00000, 11111, and 01101 the same way, and they do. –  Adnan Jul 14 '13 at 17:45
    
@Adnan: so the speed depends on data content too? –  mazix Jul 14 '13 at 17:48
2  
That's the exact opposite of what I meant. –  Adnan Jul 14 '13 at 18:14
    
@Adnan: OK:) Im kind a new in all this, that's why it's so difficult to me to understand :) Thanks anyway, now I know;) –  mazix Jul 14 '13 at 18:15
add comment

1 Answer

up vote 5 down vote accepted

As far as performance is concerned, the time to compute an MD5 hash or any other cryptographic hash depends solely on the number of bytes. It doesn't matter what the bytes are.

Note that memset(buffer, ' ', sizeof(buffer)); doesn't create an “empty buffer” — there is no such thing as an empty byte in memory. It fills the buffer with space characters, which are bytes like 'a' or any other.

Security-wise, the time to compute a hash can vary very very slightly depending on the data. This may allow an attacker who doesn't know the data but can accurately measure the time it takes to hash it to obtain some information about the data. For a hash computation, timing attacks are highly unlikely to work in practice, because there is little in the timing that depends on the data. Timing attacks are mostly successful on operations on large integers involved in asymmetric cryptography, and mostly when the attacker can influence the data and the execution speed. For example, if the implementation uses a table that doesn't fit in a single cache line and the attacker can run code on the same processor, the attacker might try to use the cache in his own process, so that the hash computation keeps fetching parts of the table from RAM, allowing the attacker to observe when RAM lookups take place. The implementation can counter that by being cache-oblivious.

In practice, I wouldn't worry about timing attacks on hash computations. Hash comparisons, yes (when comparing two MD5 hashes, one of which is secret, you should compare all 16 bytes and not stop at the first difference). Number of hash computations or comparisons in an algorithm that involves many such, yes. But not for the hash computation itself.

share|improve this answer
    
The first sentence contradicts the rest of the answer, since some hashes will have data dependent timing in normal implementations, typically thanks to lookup tables. While not a hash, straight forward AES implementations suffer from this. –  CodesInChaos Jul 14 '13 at 18:02
    
Thank you so much for the explanation. I asked about MD4/MD5 hashes but Im interested in general in any other cryptographic algorithm. Lets say, I would like to measure speed for hmm, aes or des or any other crypto algorithm. Should I understand it like this, that speed of an crypto algorithms depends only on inputs size, not on inputs content too? –  mazix Jul 14 '13 at 18:04
1  
@CodesInChaos As far as performance is concerned, there is no difference — the differences are barely measurable in normal circumstances. –  Gilles Jul 14 '13 at 18:19
1  
@mazix Yes, any cryptographic algorithm can be subject to timing attack. There is some literature on timing attacks for AES. Usually the attacks only produce only useful results if the attacker can measure the speed of each round and not just of the encryption of the whole buffer. I'm no expert on cryptography, if you want to learn more about timing attacks on the implementation of MD5 or AES I suggest asking on Cryptography. –  Gilles Jul 14 '13 at 18:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.