Question

In: Computer Science

1. Given h = Sha256(K ∥ M), where K is a secret and "∥" means concatenation...

1. Given h = Sha256(K ∥ M), where K is a secret and "∥" means concatenation (no padding is involved in calculating h). Describe a message X such that one can calculate Sha256(K ∥ X) without knowing K. Note that your described X should not the same as M, but could be a concatenated message

2. Given h = Sha256(M ∥ K), where K is a secret and "∥" means concatenation (no padding is involved in calculating h). Can you calculate Sha256(X ∥ K) for a different message X without knowing K?

Solutions

Expert Solution

In cryptography, an HMAC (sometimes expanded as either keyed-hash message authentication code or hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC. Any cryptographic hash function, such as SHA-256 or SHA-3, may be used in the calculation of an HMAC; the resulting MAC algorithm is termed HMAC-X, where X is the hash function used (e.g. HMAC-SHA256 or HMAC-SHA3); the cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function, the size of its hash output, and the size and quality of the key.

HMAC uses two passes of hash computation; the secret key is first used to derive two keys – inner and outer. The first pass of the algorithm produces an internal hash derived from the message and the inner key; the second pass produces the final HMAC code derived from the inner hash result and the outer key. Thus the algorithm provides better immunity against length extension attacks.

An iterative hash function breaks up a message into blocks of a fixed size and iterates over them with a compression function. For example, SHA-256 operates on 512-bit blocks; the size of the output of HMAC is the same as that of the underlying hash function (e.g., 256 and 1600 bits in the case of SHA-256 and SHA-3, respectively), although it can be truncated if desired.

HMAC does not encrypt the message. Instead, the message (encrypted or not) must be sent alongside the HMAC hash. Parties with the secret key will hash the message again themselves, and if it is authentic, the received and computed hashes will match.

The definition and analysis of the HMAC construction was first published in 1996 in a paper by Mihir Bellare, Ran Canetti, and Hugo Krawczyk,[1] and they also wrote RFC 2104 in 1997; the 1996 paper also defined a variant called NMAC. FIPS PUB 198 generalizes and standardizes the use of HMACs. HMAC is used within the IPsec and TLS protocols and for JSON Web Tokens.

Contents

  • 1 Definition
  • 2 Implementation
  • 3 Design principles
  • 4 Security
  • 5 Examples
  • 6 References
  • 7 External links

Definition

This definition is taken from RFC 2104:

where

H is a cryptographic hash function

m is the message to be authenticated

K is the secret key

K' is a block-sized key derived from the secret key, K; either by padding to the right with 0s up to the block size, or by hashing down to less than the block size first and then padding to the right with zeros

∥ denotes concatenation

⊕ denotes bitwise exclusive or (XOR)

opad is the block-sized outer padding, consisting of repeated bytes valued 0x5c

ipad is the block-sized inner padding, consisting of repeated bytes valued 0x36

Implementation

The following pseudocode demonstrates how HMAC may be implemented. Blocksize is 64 (bytes) when using one of the following hash functions: SHA-1, MD5, RIPEMD-128/160.[2]

Function hmac
   Inputs:
      key:        Bytes     //array of bytes
      message:    Bytes     //array of bytes to be hashed
      hash:       Function  //the hash function to use (e.g. SHA-1)
      blockSize:  Integer   //the block size of the underlying hash function (e.g. 64 bytes for SHA-1)
      outputSize: Integer   //the output size of the underlying hash function (e.g. 20 bytes for SHA-1)

   //Keys longer than blockSize are shortened by hashing them
   if (length(key) > blockSize) then
      key ← hash(key) //Key becomes outputSize bytes long
   //Keys shorter than blockSize are padded to blockSize by padding with zeros on the right
   if (length(key) < blockSize) then
      key ← Pad(key, blockSize) //pad key with zeros to make it blockSize bytes long
   o_key_pad ← key xor [0x5c * blockSize]   //Outer padded key
   i_key_pad ← key xor [0x36 * blockSize]   //Inner padded key
   return hash(o_key_pad ∥ hash(i_key_pad ∥ message)) //Where ∥ is concatenation

Design principles

The design of the HMAC specification was motivated by the existence of attacks on more trivial mechanisms for combining a key with a hash function. For example, one might assume the same security that HMAC provides could be achieved with MAC = H(key || message). However, this method suffers from a serious flaw: with most hash functions, it is easy to append data to the message without knowing the key and obtain another valid MAC ("length-extension attack"); the alternative, appending the key using MAC = H(message || key), suffers from the problem that an attacker who can find a collision in the (unkeyed) hash function has a collision in the MAC (as two messages m1 and m2 yielding the same hash will provide the same start condition to the hash function before the appended key is hashed, hence the final hash will be the same). Using MAC = H(key || message || key) is better, but various security papers have suggested vulnerabilities with this approach, even when two different keys are used.[1][3][4]

No known extension attacks have been found against the current HMAC specification which is defined as H(key || H(key || message)) because the outer application of the hash function masks the intermediate result of the internal hash. The values of ipad and opad are not critical to the security of the algorithm, but were defined in such a way to have a large Hamming distance from each other and so the inner and outer keys will have fewer bits in common; the security reduction of HMAC does require them to be different in at least one bit.[citation needed]

The Keccak hash function, that was selected by NIST as the SHA-3 competition winner, doesn't need this nested approach and can be used to generate a MAC by simply prepending the key to the message, as it is not susceptible to length-extension attacks.[5]

Security

The cryptographic strength of the HMAC depends upon the size of the secret key that is used; the most common attack against HMACs is brute force to uncover the secret key. HMACs are substantially less affected by collisions than their underlying hashing algorithms alone.[6][7] In particular, in 2006 Mihir Bellare proved that HMAC is a PRF under the sole assumption that the compression function is a PRF.[8] Therefore, HMAC-MD5 does not suffer from the same weaknesses that have been found in MD5.

RFC2104 requires that "keys longer than B bytes are first hashed using H" which leads to a confusing pseudo-collision: if the key is longer than the hash block size (e.g. 64 characters for SHA-1), then HMAC(k, m) is computed as HMAC(H(k), m).This property is sometimes raised as a possible weakness of HMAC in password-hashing scenarios: it has been demonstrated that it's possible to find a long ASCII string and a random value whose hash will be also an ASCII string, and both values will produce the same HMAC output.[9][10]

In 2006, Jongsung Kim, Alex Biryukov, Bart Preneel, and Seokhie Hong showed how to distinguish HMAC with reduced versions of MD5 and SHA-1 or full versions of HAVAL, MD4, and SHA-0 from a random function or HMAC with a random function. Differential distinguishers allow an attacker to devise a forgery attack on HMAC. Furthermore, differential and rectangle distinguishers can lead to second-preimage attacks. HMAC with the full version of MD4 can be forged with this knowledge; these attacks do not contradict the security proof of HMAC, but provide insight into HMAC based on existing cryptographic hash functions.[11]

In 2009, Xiaoyun Wang et al. presented a distinguishing attack on HMAC-MD5 without using related keys. It can distinguish an instantiation of HMAC with MD5 from an instantiation with a random function with 297 queries with probability 0.87.[12]

In 2011 an informational RFC 6151[13] was published to summarize security considerations in MD5 and HMAC-MD5. For HMAC-MD5 the RFC summarizes that – although the security of the MD5 hash function itself is severely compromised – the currently known "attacks on HMAC-MD5 do not seem to indicate a practical vulnerability when used as a message authentication code", but it also adds that "for a new protocol design, a ciphersuite with HMAC-MD5 should not be included".

In May 2011, RFC 6234 was published detailing the abstract theory and source code for SHA-based HMACS.

Examples

Here are some non-empty HMAC values, assuming 8-bit ASCII or UTF-8 encoding:

HMAC_MD5("key", "The quick brown fox jumps over the lazy dog")    = 80070713463e7749b90c2dc24911e275
HMAC_SHA1("key", "The quick brown fox jumps over the lazy dog")   = de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
HMAC_SHA256("key", "The quick brown fox jumps over the lazy dog") = f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8

Related Solutions

A patient is given 0.050 mg of technetium-99 m(where m means metastable - an unstable but...
A patient is given 0.050 mg of technetium-99 m(where m means metastable - an unstable but longlived state), a radioactive isotope with a half-life of about 6.0 hours. Part A How long until the radioactive isotope decays to 7.8×10−4 mg ? Express your answer using two significant figures. PLEASE FILL THE BLANK! 2. How does a Geiger-Muller counter detect radioactivity? Match the words in the left column to the appropriate blanks in the sentences on the right. Make certain each...
Given that h(x) = x.sinx . Find the root of the function h(x) = 1, where...
Given that h(x) = x.sinx . Find the root of the function h(x) = 1, where x is between [0, 2] using substitution method.
Consider a firm whose production is given by Q(K, L) = K^1/3L^1/3, where K and L...
Consider a firm whose production is given by Q(K, L) = K^1/3L^1/3, where K and L are, respectively, the quantities of capital and labour production inputs. Prices of capital and labour are both $1 per unit. (a) Derive and interpret the firm’s demand functions for capital and labour. (b) Derive and interpret the firm’s Long-Run Cost Function. (c) In the long-run, if the firm wished to produce 16 units of output, what quantities of capital and labour would it optimally...
A pump curve provided by a manufacturer is given by h= 20[1 − (Q/100)2] where h...
A pump curve provided by a manufacturer is given by h= 20[1 − (Q/100)2] where h is the head provided by the pump in meters and Q is the discharge in liters per minute. The system curve for a pumping application is h= 5+0.002Q2 (Q in liters per minute).Find the Operating point (Q) for one pump two pumps connected in series two pumps connected in parallel
Let G, H, K be groups. Prove that if G ≅ H and H ≅ K...
Let G, H, K be groups. Prove that if G ≅ H and H ≅ K then G ≅ K.
Given the following keys: 77, 109, 69, 99, 16, 100, 60 Also given h(k) = k...
Given the following keys: 77, 109, 69, 99, 16, 100, 60 Also given h(k) = k mod m Given size of the Hash Table (m) = 11 a) Find out hash values for each key (k) b) Find out the load factor. c) Construct Hash Table and use Linear Probing to resolve collision.
1. Consider production function of the form Q= f(H, K), where Q is the output measure...
1. Consider production function of the form Q= f(H, K), where Q is the output measure and H and K are hours worked and gross capital stock, respectively. Based on 33 observations we obtain the following results: ?og(?) = 0.129 + 0.448 ?og (?) + 0.559 ?og (?) (Standard Error) (0.546)      (0.704)           (0.816) R2= 0.886 a. Interpret the regression results. b. What is the output elasticity of hours worked? c. Verify that the coefficients of log(H) and log(K) are statistically...
Q5. A monopolist has the cost function C(Q) = m*Q +k*Q2 where m and k are...
Q5. A monopolist has the cost function C(Q) = m*Q +k*Q2 where m and k are parameters. It faces two types of consumers, A and B, with the following demand curves for its product: PA =60–3*QA PB =80–2*QB For (a)—(c) below, assume Assume m=30 and k=0. (a) [4] What price will the monopolist charge under uniform pricing? (b) [4] What prices will the monopolist charge if it can price discriminate? (c) [4] How much higher is the monopolist’s profit in...
K-means clustering: a. In the k-means lab, you examined different values for k using the "knee"...
K-means clustering: a. In the k-means lab, you examined different values for k using the "knee" heuristic to pick the best value of k. Explain what is so special about the k values on the “knee”? Hint: There are two properties that together make these values of k special. b. Give an example of a type of data (data type) that k-means should not be used for and explain why.
Consider a firm with production function given by q = f(E, K) = E^(1/4)K^(1/4), where E...
Consider a firm with production function given by q = f(E, K) = E^(1/4)K^(1/4), where E is number of workers and K is capital. The price of labor is w = 4 and price of capital is r = 8. The price of the output that firm produces is 20. The firm can adjust both its inputs. 1) Derive an expression for MRT S for this firm. 2) The firm wants to produce q0 units of output. What would be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT