write python code Example 3: key length > block size Input data:Message: “Hello” → x48656C6C 6FSecret Key: “Y0S5INaG35isu0FJNlEPQeC5V9VCb5jPQ6cVBVVTKRov0Un7Wv6kDsVzfTdx5djqg9bQakXf3vxf5IU1sOnjZoUzKu” → x59305335 494E6147 33356973 7530464A 4E6C4550 51654335 56395643 62356A50 51366356 42565654 4B526F76 30556E37 5776366B 4473567A 66546478 35646A71 67396251 616B5866 33767866 35495531 734F6E6A 5A6F557A 4B75 Constants for our case hash algorithm (SHA1) with block size 64 bytes:ipad (in HEX): x36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 (x36 repeated 64 time)opad (in HEX): x5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C (x5C repeated 64 time) Steps of creating HMAC (you could use the calculator to verify the result): If the key length > block size, we first hash the key, and then add 0s until its length becomes 64 bytes. In our case, with a key length of 90 bytes, we perform SHA1(Key). SHA1(Key) = 20e82c4d0379ee74fbe125e3b5be8b3f634a06e7.Currently, the length of SHA1(Key) is 20 bytes, so we add 0s until the length becomes 64 bytes.So K0 = 20E82C4D 0379EE74 FBE125E3 B5BE8B3F 634A06E7 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 We need to perform the operation K0 XOR ipad.How to make XOR operation you can see hereor use the calculator.K0 XOR ipad =16DE1A7B 354FD842 CDD713D5 8388BD09 557C30D1 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 Now, append the message (K0 XOR ipad || message) to K0 XOR ipad.(K0 XOR ipad) || message = 16DE1A7B 354FD842 CDD713D5 8388BD09 557C30D1 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 48656C6C 6F We put the result of the previous operation into the SHA-1 hash.Please note that you need to specify to the calculator that your data is in HEX (use this calculator). Also, you should remove all spaces (remember spaces are added here for readability but should not be included when hashing). In other words, you should input into the hash function:16de1a7b354fd842cdd713d58388bd09557c30d1363636363636363636363636363636363636363636363636363636363636363636363636363636363636363648656c6c6fsha1(K0 XOR ipad || message) = a79535b0b1fd1d5aff741fc0e1bbd2c627076c60 Perform the operation K0 XOR opad.K0 XOR opad = 7CB47011 5F25B228 A7BD79BF E9E2D763 3F165ABB 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C Append to the result of the previous operation the wich hash obtained in step 4.(K0 XOR opad) || (sha1(K0 XOR ipad || message)) =7CB47011 5F25B228 A7BD79BF E9E2D763 3F165ABB 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C A79535B0 B1FD1D5A FF741FC0 E1BBD2C6 27076C60 Put the result of step 6 into the SHA-1 hash.HMAC = 45fac385c1a6c3404593b8943c3d1da70da0594b

icon
Related questions
Question

write python code

Example 3: key length > block size

Input data:
Message: “Hello” → x48656C6C 6F
Secret Key: “Y0S5INaG35isu0FJNlEPQeC5V9VCb5jPQ6cVBVVTKRov0Un7Wv6kDsVzfTdx5djqg9bQakXf3vxf5IU1sOnjZoUzKu” → x59305335 494E6147 33356973 7530464A 4E6C4550 51654335 56395643 62356A50 51366356 42565654 4B526F76 30556E37 5776366B 4473567A 66546478 35646A71 67396251 616B5866 33767866 35495531 734F6E6A 5A6F557A 4B75

Constants for our case hash algorithm (SHA1) with block size 64 bytes:
ipad (in HEX): x36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 (x36 repeated 64 time)
opad (in HEX): x5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C (x5C repeated 64 time)

Steps of creating HMAC (you could use the calculator to verify the result):

  1. If the key length > block size, we first hash the key, and then add 0s until its length becomes 64 bytes. In our case, with a key length of 90 bytes, we perform SHA1(Key). SHA1(Key) = 20e82c4d0379ee74fbe125e3b5be8b3f634a06e7.
    Currently, the length of SHA1(Key) is 20 bytes, so we add 0s until the length becomes 64 bytes.
    So K0 = 20E82C4D 0379EE74 FBE125E3 B5BE8B3F 634A06E7 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  2. We need to perform the operation K0 XOR ipad.
    How to make XOR operation you can see hereor use the calculator.
    K0 XOR ipad =
    16DE1A7B 354FD842 CDD713D5 8388BD09 557C30D1 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636
  3. Now, append the message (K0 XOR ipad || message) to K0 XOR ipad.
    (K0 XOR ipad) || message = 16DE1A7B 354FD842 CDD713D5 8388BD09 557C30D1 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 36363636 48656C6C 6F
  4. We put the result of the previous operation into the SHA-1 hash.
    Please note that you need to specify to the calculator that your data is in HEX (use this calculator). Also, you should remove all spaces (remember spaces are added here for readability but should not be included when hashing). In other words, you should input into the hash function:
    16de1a7b354fd842cdd713d58388bd09557c30d1363636363636363636363636363636363636363636363636363636363636363636363636363636363636363648656c6c6f
    sha1(K0 XOR ipad || message) = a79535b0b1fd1d5aff741fc0e1bbd2c627076c60
  5. Perform the operation K0 XOR opad.
    K0 XOR opad = 7CB47011 5F25B228 A7BD79BF E9E2D763 3F165ABB 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C
  6. Append to the result of the previous operation the wich hash obtained in step 4.
    (K0 XOR opad) || (sha1(K0 XOR ipad || message)) =7CB47011 5F25B228 A7BD79BF E9E2D763 3F165ABB 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C 5C5C5C5C A79535B0 B1FD1D5A FF741FC0 E1BBD2C6 27076C60
  7. Put the result of step 6 into the SHA-1 hash.
    HMAC = 45fac385c1a6c3404593b8943c3d1da70da0594b
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer