5
$\begingroup$

To my understanding one of the main advantages HMAC has over RSA is that HMAC is faster to compute.

My question is: How much faster? Say you are signing a SHA-1 hash function 1000 times a day. How much faster will HMAC be over RSA (2048 bit key)?

$\endgroup$
3
  • 3
    $\begingroup$ HMAC and digital signatures with RSA are very different primitives with different purposes. Why are you comparing the two? $\endgroup$
    – mikeazo
    Commented Jul 29, 2016 at 11:58
  • 1
    $\begingroup$ Take a look at this question $\endgroup$
    – mikeazo
    Commented Jul 29, 2016 at 11:59
  • $\begingroup$ Welcome to crypto, Almedin. $\endgroup$
    – Maarten Bodewes
    Commented Jul 30, 2016 at 12:12

1 Answer 1

7
$\begingroup$

Asymmetric signatures are one of the slowest operations (on relatively small sizes of data) around. RSA signature generation is particularly slow, as it requires modular exponentiation over the private exponent. It's possible to use Chinese Remainder Theorem and/or multi-prime RSA, but those kind of optimizations won't deliver the same performance as hashing.

The specification of the algorithm above is already an indication that the speed difference of HMAC and signatures depends on a lot of parameters:

  • the asymmetric primitive used;
  • the key size used for the asymmetric primitive;
  • the hash algorithm used for both HMAC and the signature algorithm, in case they differ;
  • the input data size;
  • the implementation of the algorithms.

For large amounts of data and an identical hash / hash implementation it is likely that RSA signature generation is only a constant value larger than HMAC, as both simply use a single pass of the hash algorithm over the data.


To view the difference for a specific implementation and signature / HMAC configurations, use openssl speed hmac rsa on the command line. Even then the results depend on the build configuration of OpenSSL.


Usually this question doesn't come up at all. Key pairs and symmetric keys are often used for different purposes in protocols. For instance, you cannot build a PKI (certificate / key infrastructure) with just HMAC; PKI requires asymmetric algorithms a key pairs.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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