home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / rfc / 3 / rfc2286.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  11.6 KB  |  396 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                            J. Kapp
  8. Request for Comments: 2286                           Reaper Technologies
  9. Category: Informational                                    February 1998
  10.  
  11.  
  12.             Test Cases for HMAC-RIPEMD160 and HMAC-RIPEMD128
  13.  
  14. Status of this Memo
  15.  
  16.    This memo provides information for the Internet community.  It does
  17.    not specify an Internet standard of any kind.  Distribution of this
  18.    memo is unlimited.
  19.  
  20. Copyright Notice
  21.  
  22.    Copyright (C) The Internet Society (1998).  All Rights Reserved.
  23.  
  24. Abstract
  25.  
  26.    This document provides two sets of test cases for HMAC-RIPEMD160 and
  27.    HMAC-RIPEMD128, respectively. HMAC-RIPEMD160 and HMAC-RIPEMD128 are
  28.    two constructs of the HMAC [HMAC] message authentication function
  29.    using the RIPEMD-160 and RIPEMD-128 [RIPE] hash functions. The test
  30.    cases and results provided in this document are meant to be used as a
  31.    conformance test for HMAC-RIPEMD160 and HMAC-RIPEMD128
  32.    implementations.
  33.  
  34. 1. Introduction
  35.  
  36.    The general method for constructing a HMAC message authentication
  37.    function using a particular hash function is described in section 2
  38.    of [HMAC].
  39.  
  40.    In sections 2 and 3 test cases for HMAC-RIPEMD160 and HMAC-RIPEMD128,
  41.    respectively are provided. Each case includes the key, the data, and
  42.    the result.  The values of keys and data are either hexadecimal
  43.    numbers (prefixed by "0x") or ASCII character strings in double
  44.    quotes. If a value is an ASCII character string, then the HMAC
  45.    computation for the corresponding test case DOES NOT include the
  46.    trailing null character ('\0') in the string.
  47.  
  48.    The C source code of the functions used to generate HMAC-RIPEMD160
  49.    and HMAC-RIPEMD128 results is listed in the Appendix. Please Note
  50.    that the functions provided are implemented in such a way as to be
  51.    simple and easy to understand as a result they are not optimized in
  52.    any way. The C source code for computing HMAC-MD5 can be found in
  53.    [MD5].
  54.  
  55.  
  56.  
  57.  
  58. Kapp                         Informational                      [Page 1]
  59.  
  60. RFC 2286       Test Cases: HMAC-RIPEMD160, HMAC-RIPEMD128  February 1998
  61.  
  62.  
  63. 2. Test Cases for HMAC-RIPEMD160
  64.  
  65. test_case =         1
  66. key =               0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
  67. key_len =           20
  68. data =              "Hi There"
  69. data_len =          8
  70. digest =            0x24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668
  71.  
  72. test_case =         2
  73. key =               "Jefe"
  74. key_len =           4
  75. data =              "what do ya want for nothing?"
  76. data_len =          28
  77. digest =            0xdda6c0213a485a9e24f4742064a7f033b43c4069
  78.  
  79. test_case =         3
  80. key =               0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  81. key_len =           20
  82. data =              0xdd repeated 50 times
  83. data_len =          50
  84. digest =            0xb0b105360de759960ab4f35298e116e295d8e7c1
  85.  
  86. test_case =         4
  87. key =               0x0102030405060708090a0b0c0d0e0f10111213141516171819
  88. key_len =           25
  89. data =              0xcd repeated 50 times
  90. data_len =          50
  91. digest =            0xd5ca862f4d21d5e610e18b4cf1beb97a4365ecf4
  92.  
  93. test_case =         5
  94. key =               0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
  95. key_len =           20
  96. data =              "Test With Truncation"
  97. data_len =          20
  98. digest =            0x7619693978f91d90539ae786500ff3d8e0518e39
  99. digest-96 =         0x7619693978f91d90539ae786
  100.  
  101. test_case =         6
  102. key =               0xaa repeated 80 times
  103. key_len =           80
  104. data =              "Test Using Larger Than Block-Size Key - Hash Key
  105.                     First"
  106. data_len =          54
  107. digest =            0x6466ca07ac5eac29e1bd523e5ada7605b791fd8b
  108.  
  109. test_case =         7
  110. key =               0xaa repeated 80 times
  111.  
  112.  
  113.  
  114. Kapp                         Informational                      [Page 2]
  115.  
  116. RFC 2286       Test Cases: HMAC-RIPEMD160, HMAC-RIPEMD128  February 1998
  117.  
  118.  
  119. key_len =           80
  120. data =              "Test Using Larger Than Block-Size Key and Larger
  121.                     Than One Block-Size Data"
  122. data_len =          73
  123. digest =            0x69ea60798d71616cce5fd0871e23754cd75d5a0a
  124.  
  125. 3. Test Cases for HMAC-RIPEMD128
  126.  
  127. test_case =         1
  128. key =               0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
  129. key_len =           16
  130. data =              "Hi There"
  131. data_len =          8
  132. digest =            0xfbf61f9492aa4bbf81c172e84e0734db
  133.  
  134. test_case =         2
  135. key =               "Jefe"
  136. key_len =           4
  137. data =              "what do ya want for nothing?"
  138. data_len =          28
  139. digest =            0x875f828862b6b334b427c55f9f7ff09b
  140.  
  141. test_case =         3
  142. key =               0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  143. key_len =           16
  144. data =              0xdd repeated 50 times
  145. data_len =          50
  146. digest =            0x09f0b2846d2f543da363cbec8d62a38d
  147.  
  148. test_case =         4
  149. key =               0x0102030405060708090a0b0c0d0e0f10111213141516171819
  150. key_len =           25
  151. data =              0xcd repeated 50 times
  152. data_len =          50
  153. digest =            0xbdbbd7cf03e44b5aa60af815be4d2294
  154.  
  155. test_case =         5
  156. key =               0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
  157. key_len =           16
  158. data =              "Test With Truncation"
  159. data_len =          20
  160. digest =            0xe79808f24b25fd031c155f0d551d9a3a
  161. digest-96 =         0xe79808f24b25fd031c155f0d
  162.  
  163. test_case =         6
  164. key =               0xaa repeated 80 times
  165. key_len =           80
  166. data =              "Test Using Larger Than Block-Size Key - Hash Key
  167.  
  168.  
  169.  
  170. Kapp                         Informational                      [Page 3]
  171.  
  172. RFC 2286       Test Cases: HMAC-RIPEMD160, HMAC-RIPEMD128  February 1998
  173.  
  174.  
  175.                     First"
  176. data_len =          54
  177. digest =            0xdc732928de98104a1f59d373c150acbb
  178.  
  179. test_case =         7
  180. key =               0xaa repeated 80 times
  181. key_len =           80
  182. data =              "Test Using Larger Than Block-Size Key and Larger
  183.                     Than One Block-Size Data"
  184. data_len =          73
  185. digest =            0x5c6bec96793e16d40690c237635f30c5
  186.  
  187. 4. Security Considerations
  188.  
  189.    This document raises no security issues.  Discussion on the strength
  190.    of the HMAC construction can be found in [HMAC].
  191.  
  192. References
  193.  
  194.    [HMAC]    Krawczyk, H., Bellare, M., and R. Canetti,
  195.              "HMAC: Keyed-Hashing for Message Authentication", RFC 2104,
  196.              February 1997.
  197.  
  198.    [MD5]     Rivest, R., "The MD5 Message-Digest Algorithm",
  199.              RFC 1321, April 1992.
  200.  
  201.    [OG]      Oehler, M., and R. Glenn,
  202.              "HMAC-MD5 IP Authentication with Replay Prevention", RFC
  203.              2085, February 1997
  204.  
  205.    [CG]      Chang, S., and R. Glenn,
  206.              "Test Cases for HMAC-MD5 and HMAC-SHA-1", RFC 2202,
  207.              September 1997.
  208.  
  209.    [RIPE]    Dobbertin, H., Bosselaers A., and Preneel, B.
  210.              "RIPEMD-160: A Strengthened Version of RIPEMD" April 1996
  211.  
  212. Author's Address
  213.  
  214.    Justin S. Kapp
  215.    Reaper Technologies
  216.    The Post Office, Dunsop Bridge
  217.    Clitheroe, Lancashire.
  218.    BB7 3BB.  United Kingdom
  219.  
  220.    EMail: skapp@reapertech.com
  221.  
  222.  
  223.  
  224.  
  225.  
  226. Kapp                         Informational                      [Page 4]
  227.  
  228. RFC 2286       Test Cases: HMAC-RIPEMD160, HMAC-RIPEMD128  February 1998
  229.  
  230.  
  231. Appendix
  232.  
  233.    This code which implements HMAC-RIPEMD160 using an existing RIPEMD-
  234.    160 library.  It assumes that the RIPEMD-160 library has similar
  235.    API's as those of the MD5 code described in RFC 1321.  The code for
  236.    HMAC-MD5, is similar, this HMAC-MD5 code is also listed in RFC 2104.
  237.    To adapt this example to produce the HMAC-RIPEMD128 then replace each
  238.    occurance of 'RMD160' with 'RMD128'.
  239.  
  240. #ifndef RMD160_DIGESTSIZE
  241. #define RMD160_DIGESTSIZE  20
  242. #endif
  243.  
  244. #ifndef RMD128_DIGESTSIZE
  245. #define RMD128_DIGESTSIZE  16
  246. #endif
  247.  
  248.  
  249. /*  HMAC_RMD160 implements HMAC-RIPEMD160 */
  250.  
  251. void HMAC_RMD160(input, len, key, keylen, digest)
  252. unsigned char *input;                       /* pointer to data stream */
  253. int len;                                     /* length of data stream */
  254. unsigned char *key;                  /* pointer to authentication key */
  255. int keylen;                           /* length of authentication key */
  256. unsigned char *digest;                        /* resulting MAC digest */
  257. {
  258.     RMD160_CTX context;
  259.     unsigned char k_ipad[65];  /* inner padding - key XORd with ipad */
  260.     unsigned char k_opad[65];  /* outer padding - key XORd with opad */
  261.     unsigned char tk[RMD160_DIGESTSIZE];
  262.     int i;
  263.  
  264.     /* if key is longer than 64 bytes reset it to key=SHA1(key) */
  265.     if (keylen > 64) {
  266.         RMD160_CTX      tctx;
  267.  
  268.         RMD160Init(&tctx);
  269.         RMD160Update(&tctx, key, keylen);
  270.         RMD160Final(tk, &tctx);
  271.  
  272.         key = tk;
  273.         keylen = RMD160_DIGESTSIZE;
  274.     }
  275.  
  276.         /* The HMAC_SHA1 transform looks like:
  277.  
  278.            RMD160(K XOR opad, RMD160(K XOR ipad, text))
  279.  
  280.  
  281.  
  282. Kapp                         Informational                      [Page 5]
  283.  
  284. RFC 2286       Test Cases: HMAC-RIPEMD160, HMAC-RIPEMD128  February 1998
  285.  
  286.  
  287.  
  288.            where K is an n byte key
  289.            ipad is the byte 0x36 repeated 64 times
  290.            opad is the byte 0x5c repeated 64 times
  291.            and text is the data being protected */
  292.  
  293.         /* start out by storing key in pads */
  294.     memset(k_ipad, 0x36, sizeof(k_ipad));
  295.     memset(k_opad, 0x5c, sizeof(k_opad));
  296.  
  297.         /* XOR key with ipad and opad values */
  298.     for (i=0; i<keylen; i++) {
  299.         k_ipad[i] ^= key[i];
  300.         k_opad[i] ^= key[i];
  301.     }
  302.  
  303.         /* perform inner RIPEMD-160 */
  304.  
  305.     RMD160Init(&context);           /* init context for 1st pass */
  306.     RMD160Update(&context, k_ipad, 64);  /* start with inner pad */
  307.     RMD160Update(&context, input, len); /* then text of datagram */
  308.     RMD160Final(digest, &context);         /* finish up 1st pass */
  309.  
  310.         /* perform outer RIPEMD-160 */
  311.     RMD160Init(&context);           /* init context for 2nd pass */
  312.     RMD160Update(&context, k_opad, 64);  /* start with outer pad */
  313.     /* then results of 1st hash */
  314.     RMD160Update(&context, digest, RMD160_DIGESTSIZE);
  315.     RMD160Final(digest, &context);         /* finish up 2nd pass */
  316.  
  317.     memset(k_ipad, 0x00, sizeof(k_ipad));
  318.     memset(k_opad, 0x00, sizeof(k_opad));
  319. }
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Kapp                         Informational                      [Page 6]
  339.  
  340. RFC 2286       Test Cases: HMAC-RIPEMD160, HMAC-RIPEMD128  February 1998
  341.  
  342.  
  343. Full Copyright Statement
  344.  
  345.    Copyright (C) The Internet Society (1998).  All Rights Reserved.
  346.  
  347.    This document and translations of it may be copied and furnished to
  348.    others, and derivative works that comment on or otherwise explain it
  349.    or assist in its implementation may be prepared, copied, published
  350.    and distributed, in whole or in part, without restriction of any
  351.    kind, provided that the above copyright notice and this paragraph are
  352.    included on all such copies and derivative works.  However, this
  353.    document itself may not be modified in any way, such as by removing
  354.    the copyright notice or references to the Internet Society or other
  355.    Internet organizations, except as needed for the purpose of
  356.    developing Internet standards in which case the procedures for
  357.    copyrights defined in the Internet Standards process must be
  358.    followed, or as required to translate it into languages other than
  359.    English.
  360.  
  361.    The limited permissions granted above are perpetual and will not be
  362.    revoked by the Internet Society or its successors or assigns.
  363.  
  364.    This document and the information contained herein is provided on an
  365.    "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
  366.    TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
  367.    BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
  368.    HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
  369.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Kapp                         Informational                      [Page 7]
  395.  
  396.