# HMAC vs RSA speed

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)?

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

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.