test_sha1.h 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_SHA1_H_
  23. #define _TEST_SHA1_H_
  24. struct sha1_result {
  25. const char* msg;
  26. const char* xres;
  27. };
  28. struct sha1_result msgs[] = {
  29. { "", "da39a3ee5e6b4b0d3255bfef95601890afd80709" },
  30. { "x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11", "1d29ab734b0c9585240069a6e4e3e91b61da1969" },
  31. { "The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" },
  32. { "The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" },
  33. };
  34. void test_sha1()
  35. {
  36. size_t i;
  37. tsk_sha1string_t sha1result;
  38. for(i=0; i< sizeof(msgs)/sizeof(struct sha1_result); i++) {
  39. tsk_sha1compute(msgs[i].msg, strlen(msgs[i].msg), &sha1result);
  40. if(tsk_striequals(msgs[i].xres, sha1result)) {
  41. TSK_DEBUG_INFO("[SHA1-%d] ==> OK", i);
  42. }
  43. else {
  44. TSK_DEBUG_INFO("[SHA1-%d] ==> NOK", i);
  45. }
  46. }
  47. }
  48. struct hmac_sha1_result {
  49. const char* msg;
  50. const char* key;
  51. const char* xres;
  52. };
  53. struct hmac_sha1_result hmac_sha1_msgs[] = {
  54. { "Hi There", "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", "b617318655057264e28bc0b6fb378c8ef146be00" },
  55. { "what do ya want for nothing?", "Jefe", "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79" },
  56. { "\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\xaa\xaa\xaa\xaa", "125d7342b9ac11cd91a39af48aa17b4f63f175d3" },
  57. { "\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", "4c9007f4026250c6bc8414f9bf50c86c2d7235da" },
  58. { "Test With Truncation", "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04" },
  59. { "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", "aa4ae5e15272d00e95705637ce8a3b55ed402112" },
  60. { "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", "e8e99d0f45237d786d6bbaa7965c7808bbff1a91" },
  61. };
  62. void test_hmac_sha1()
  63. {
  64. size_t i;
  65. tsk_sha1string_t sha1result;
  66. // const uint8_t* bytes = "\x00\x01\x00\x3c\x21\x12\xa4\x42\x33\x6f\x57\x50\x31\x4f\x4d\x65\x65\x58\x73\x7a\x00\x06\x00\x20\x33\x68\x50\x30\x6f\x53\x7a\x6b\x48\x75\x33\x52\x56\x2f\x4c\x35\x48\x49\x78\x49\x70\x34\x73\x55\x46\x47\x73\x38\x55\x6a\x4b\x57\x00\x08\x00\x14\x21\xee\x75\x15\xc0\x9c\x0a\x90\xf2\xf3\xa5\x3e\x22\x00\x0c\xd3\xd5\xc0\x2c\x82";
  67. //const uint8_t* bytes = "\x00\x01\x00\x24\x21\x12\xa4\x42\x33\x6f\x57\x50\x31\x4f\x4d\x65\x65\x58\x73\x7a\x00\x06\x00\x20\x33\x68\x50\x30\x6f\x53\x7a\x6b\x48\x75\x33\x52\x56\x2f\x4c\x35\x48\x49\x78\x49\x70\x34\x73\x55\x46\x47\x73\x38\x55\x6a\x4b\x57\x00\x08\x00\x14\x21\xee\x75\x15\xc0\x9c\x0a\x90\xf2\xf3\xa5\x3e\x22\x00\x0c\xd3\xd5\xc0\x2c\x82";
  68. //hmac_sha1_compute(bytes, 56, "tLzlCDl+o9yiWkp3", tsk_strlen("tLzlCDl+o9yiWkp3"), &sha1result);
  69. for(i=0; i< sizeof(hmac_sha1_msgs)/sizeof(struct hmac_sha1_result); i++) {
  70. hmac_sha1_compute((const uint8_t*)hmac_sha1_msgs[i].msg, strlen(hmac_sha1_msgs[i].msg), hmac_sha1_msgs[i].key, strlen(hmac_sha1_msgs[i].key), &sha1result);
  71. if(tsk_striequals(hmac_sha1_msgs[i].xres, sha1result)) {
  72. TSK_DEBUG_INFO("[SHA1-%d] ==> OK", i);
  73. }
  74. else {
  75. TSK_DEBUG_INFO("[SHA1-%d] ==> NOK", i);
  76. }
  77. }
  78. }
  79. #endif /* _TEST_SHA1_H_ */