test_md5.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_MD5_H_
  23. #define _TEST_MD5_H_
  24. struct md5_result {
  25. const char* msg;
  26. const char* xres;
  27. };
  28. struct md5_result msgs_md5[] = {
  29. { "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", "f3d129cf0d52088287dee3e6057fa18d" },
  30. { "", "d41d8cd98f00b204e9800998ecf8427e" },
  31. { "a", "0cc175b9c0f1b6a831c399e269772661" },
  32. { "abc", "900150983cd24fb0d6963f7d28e17f72" },
  33. { "message digest", "f96b697d7cb7938d525a2f31aaf161d0" },
  34. { "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" },
  35. { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f" },
  36. { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a" },
  37. { "The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6" },
  38. { "The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0" },
  39. };
  40. void test_md5()
  41. {
  42. size_t i;
  43. tsk_md5string_t md5result;
  44. for(i=0; i< sizeof(msgs_md5)/sizeof(struct md5_result); i++) {
  45. tsk_md5compute(msgs_md5[i].msg, strlen(msgs_md5[i].msg), &md5result);
  46. if(tsk_striequals(msgs_md5[i].xres, md5result)) {
  47. TSK_DEBUG_INFO("[MD5-%d] ==> OK", i);
  48. }
  49. else {
  50. TSK_DEBUG_INFO("[MD5-%d] ==> NOK", i);
  51. }
  52. }
  53. }
  54. struct hmac_md5_result {
  55. const char* msg;
  56. const char* key;
  57. const char* xres;
  58. };
  59. struct hmac_md5_result msgs_hmac_md5[] = {
  60. { "Hi There", "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "9294727a3638bb1c13f48ef8158bfc9d" },
  61. { "what do ya want for nothing?", "Jefe", "750c783e6ab0b503eaa86e310a5db738" },
  62. { "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "56be34521d144c88dbb8c733f0e8b3f6" },
  63. { "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", "697eaf0aca3a3aea3a75164746ffaa79" },
  64. { "Test With Truncation", "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", "56461ef2342edc00f9bab995690efd4c" },
  65. { "Test Using Larger Than Block-Size Key - Hash Key First", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd" },
  66. { "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", "6f630fad67cda0ee1fb1f562db3aa53e" },
  67. };
  68. void test_hmac_md5()
  69. {
  70. size_t i;
  71. tsk_md5string_t md5result;
  72. for(i=0; i< sizeof(msgs_hmac_md5)/sizeof(struct hmac_md5_result); i++) {
  73. hmac_md5_compute((const uint8_t*)msgs_hmac_md5[i].msg, strlen(msgs_hmac_md5[i].msg), msgs_hmac_md5[i].key, strlen(msgs_hmac_md5[i].key), &md5result);
  74. if(tsk_striequals(msgs_hmac_md5[i].xres, md5result)) {
  75. TSK_DEBUG_INFO("[HMAC-MD5-%d] ==> OK", i);
  76. }
  77. else {
  78. TSK_DEBUG_INFO("[HMAC-MD5-%d] ==> NOK", i);
  79. }
  80. }
  81. }
  82. #endif /* _TEST_MD5_H_ */