2
0

sha512t.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* crypto/sha/sha512t.c */
  2. /* ====================================================================
  3. * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
  4. * ====================================================================
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <openssl/sha.h>
  10. #include <openssl/evp.h>
  11. #include <openssl/crypto.h>
  12. #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512)
  13. int main(int argc, char *argv[])
  14. {
  15. printf("No SHA512 support\n");
  16. return(0);
  17. }
  18. #else
  19. unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
  20. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  21. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  22. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  23. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  24. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  25. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  26. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  27. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f };
  28. unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
  29. 0x8e,0x95,0x9b,0x75,0xda,0xe3,0x13,0xda,
  30. 0x8c,0xf4,0xf7,0x28,0x14,0xfc,0x14,0x3f,
  31. 0x8f,0x77,0x79,0xc6,0xeb,0x9f,0x7f,0xa1,
  32. 0x72,0x99,0xae,0xad,0xb6,0x88,0x90,0x18,
  33. 0x50,0x1d,0x28,0x9e,0x49,0x00,0xf7,0xe4,
  34. 0x33,0x1b,0x99,0xde,0xc4,0xb5,0x43,0x3a,
  35. 0xc7,0xd3,0x29,0xee,0xb6,0xdd,0x26,0x54,
  36. 0x5e,0x96,0xe5,0x5b,0x87,0x4b,0xe9,0x09 };
  37. unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
  38. 0xe7,0x18,0x48,0x3d,0x0c,0xe7,0x69,0x64,
  39. 0x4e,0x2e,0x42,0xc7,0xbc,0x15,0xb4,0x63,
  40. 0x8e,0x1f,0x98,0xb1,0x3b,0x20,0x44,0x28,
  41. 0x56,0x32,0xa8,0x03,0xaf,0xa9,0x73,0xeb,
  42. 0xde,0x0f,0xf2,0x44,0x87,0x7e,0xa6,0x0a,
  43. 0x4c,0xb0,0x43,0x2c,0xe5,0x77,0xc3,0x1b,
  44. 0xeb,0x00,0x9c,0x5c,0x2c,0x49,0xaa,0x2e,
  45. 0x4e,0xad,0xb2,0x17,0xad,0x8c,0xc0,0x9b };
  46. unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
  47. 0xcb,0x00,0x75,0x3f,0x45,0xa3,0x5e,0x8b,
  48. 0xb5,0xa0,0x3d,0x69,0x9a,0xc6,0x50,0x07,
  49. 0x27,0x2c,0x32,0xab,0x0e,0xde,0xd1,0x63,
  50. 0x1a,0x8b,0x60,0x5a,0x43,0xff,0x5b,0xed,
  51. 0x80,0x86,0x07,0x2b,0xa1,0xe7,0xcc,0x23,
  52. 0x58,0xba,0xec,0xa1,0x34,0xc8,0x25,0xa7 };
  53. unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
  54. 0x09,0x33,0x0c,0x33,0xf7,0x11,0x47,0xe8,
  55. 0x3d,0x19,0x2f,0xc7,0x82,0xcd,0x1b,0x47,
  56. 0x53,0x11,0x1b,0x17,0x3b,0x3b,0x05,0xd2,
  57. 0x2f,0xa0,0x80,0x86,0xe3,0xb0,0xf7,0x12,
  58. 0xfc,0xc7,0xc7,0x1a,0x55,0x7e,0x2d,0xb9,
  59. 0x66,0xc3,0xe9,0xfa,0x91,0x74,0x60,0x39 };
  60. unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
  61. 0x9d,0x0e,0x18,0x09,0x71,0x64,0x74,0xcb,
  62. 0x08,0x6e,0x83,0x4e,0x31,0x0a,0x4a,0x1c,
  63. 0xed,0x14,0x9e,0x9c,0x00,0xf2,0x48,0x52,
  64. 0x79,0x72,0xce,0xc5,0x70,0x4c,0x2a,0x5b,
  65. 0x07,0xb8,0xb3,0xdc,0x38,0xec,0xc4,0xeb,
  66. 0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85 };
  67. int main (int argc,char **argv)
  68. { unsigned char md[SHA512_DIGEST_LENGTH];
  69. int i;
  70. EVP_MD_CTX evp;
  71. #ifdef OPENSSL_IA32_SSE2
  72. /* Alternative to this is to call OpenSSL_add_all_algorithms...
  73. * The below code is retained exclusively for debugging purposes. */
  74. { char *env;
  75. if ((env=getenv("OPENSSL_ia32cap")))
  76. OPENSSL_ia32cap = strtoul (env,NULL,0);
  77. }
  78. #endif
  79. fprintf(stdout,"Testing SHA-512 ");
  80. EVP_Digest ("abc",3,md,NULL,EVP_sha512(),NULL);
  81. if (memcmp(md,app_c1,sizeof(app_c1)))
  82. { fflush(stdout);
  83. fprintf(stderr,"\nTEST 1 of 3 failed.\n");
  84. return 1;
  85. }
  86. else
  87. fprintf(stdout,"."); fflush(stdout);
  88. EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
  89. "efghijkl""fghijklm""ghijklmn""hijklmno"
  90. "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
  91. "mnopqrst""nopqrstu",112,md,NULL,EVP_sha512(),NULL);
  92. if (memcmp(md,app_c2,sizeof(app_c2)))
  93. { fflush(stdout);
  94. fprintf(stderr,"\nTEST 2 of 3 failed.\n");
  95. return 1;
  96. }
  97. else
  98. fprintf(stdout,"."); fflush(stdout);
  99. EVP_MD_CTX_init (&evp);
  100. EVP_DigestInit_ex (&evp,EVP_sha512(),NULL);
  101. for (i=0;i<1000000;i+=288)
  102. EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  103. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  104. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  105. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  106. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  107. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  108. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  109. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  110. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
  111. (1000000-i)<288?1000000-i:288);
  112. EVP_DigestFinal_ex (&evp,md,NULL);
  113. EVP_MD_CTX_cleanup (&evp);
  114. if (memcmp(md,app_c3,sizeof(app_c3)))
  115. { fflush(stdout);
  116. fprintf(stderr,"\nTEST 3 of 3 failed.\n");
  117. return 1;
  118. }
  119. else
  120. fprintf(stdout,"."); fflush(stdout);
  121. fprintf(stdout," passed.\n"); fflush(stdout);
  122. fprintf(stdout,"Testing SHA-384 ");
  123. EVP_Digest ("abc",3,md,NULL,EVP_sha384(),NULL);
  124. if (memcmp(md,app_d1,sizeof(app_d1)))
  125. { fflush(stdout);
  126. fprintf(stderr,"\nTEST 1 of 3 failed.\n");
  127. return 1;
  128. }
  129. else
  130. fprintf(stdout,"."); fflush(stdout);
  131. EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
  132. "efghijkl""fghijklm""ghijklmn""hijklmno"
  133. "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
  134. "mnopqrst""nopqrstu",112,md,NULL,EVP_sha384(),NULL);
  135. if (memcmp(md,app_d2,sizeof(app_d2)))
  136. { fflush(stdout);
  137. fprintf(stderr,"\nTEST 2 of 3 failed.\n");
  138. return 1;
  139. }
  140. else
  141. fprintf(stdout,"."); fflush(stdout);
  142. EVP_MD_CTX_init (&evp);
  143. EVP_DigestInit_ex (&evp,EVP_sha384(),NULL);
  144. for (i=0;i<1000000;i+=64)
  145. EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
  146. "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
  147. (1000000-i)<64?1000000-i:64);
  148. EVP_DigestFinal_ex (&evp,md,NULL);
  149. EVP_MD_CTX_cleanup (&evp);
  150. if (memcmp(md,app_d3,sizeof(app_d3)))
  151. { fflush(stdout);
  152. fprintf(stderr,"\nTEST 3 of 3 failed.\n");
  153. return 1;
  154. }
  155. else
  156. fprintf(stdout,"."); fflush(stdout);
  157. fprintf(stdout," passed.\n"); fflush(stdout);
  158. return 0;
  159. }
  160. #endif