ARMv8 assembly pack: add Cortex performance numbers.
[openssl.git] / crypto / sha / sha512t.c
index 8d2c760..210041d 100644 (file)
@@ -8,6 +8,16 @@
 #include <stdlib.h>
 
 #include <openssl/sha.h>
+#include <openssl/evp.h>
+#include <openssl/crypto.h>
+
+#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512)
+int main(int argc, char *argv[])
+{
+    printf("No SHA512 support\n");
+    return(0);
+}
+#else
 
 unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
        0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
@@ -63,14 +73,24 @@ unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
        0x07,0xb8,0xb3,0xdc,0x38,0xec,0xc4,0xeb,
        0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85 };
 
-int main ()
+int main (int argc,char **argv)
 { unsigned char md[SHA512_DIGEST_LENGTH];
   int          i;
-  SHA512_CTX   ctx;
+  EVP_MD_CTX   evp;
+
+#ifdef OPENSSL_IA32_SSE2
+    /* Alternative to this is to call OpenSSL_add_all_algorithms...
+     * The below code is retained exclusively for debugging purposes. */
+    { char      *env;
+
+       if ((env=getenv("OPENSSL_ia32cap")))
+           OPENSSL_ia32cap = strtoul (env,NULL,0);
+    }
+#endif
 
     fprintf(stdout,"Testing SHA-512 ");
 
-    SHA512("abc",3,md);
+    EVP_Digest ("abc",3,md,NULL,EVP_sha512(),NULL);
     if (memcmp(md,app_c1,sizeof(app_c1)))
     {  fflush(stdout);
        fprintf(stderr,"\nTEST 1 of 3 failed.\n");
@@ -79,10 +99,10 @@ int main ()
     else
        fprintf(stdout,"."); fflush(stdout);
 
-    SHA512("abcdefgh""bcdefghi""cdefghij""defghijk"
-          "efghijkl""fghijklm""ghijklmn""hijklmno"
-          "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
-          "mnopqrst""nopqrstu",112,md);
+    EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
+               "efghijkl""fghijklm""ghijklmn""hijklmno"
+               "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
+               "mnopqrst""nopqrstu",112,md,NULL,EVP_sha512(),NULL);
     if (memcmp(md,app_c2,sizeof(app_c2)))
     {  fflush(stdout);
        fprintf(stderr,"\nTEST 2 of 3 failed.\n");
@@ -91,12 +111,21 @@ int main ()
     else
        fprintf(stdout,"."); fflush(stdout);
 
-    SHA512_Init(&ctx);
-    for (i=0;i<1000000;i+=64)
-       SHA512_Update(&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
-                           "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
-                           (1000000-i)<64?1000000-i:64);
-    SHA512_Final(md,&ctx);
+    EVP_MD_CTX_init (&evp);
+    EVP_DigestInit_ex (&evp,EVP_sha512(),NULL);
+    for (i=0;i<1000000;i+=288)
+       EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
+                               (1000000-i)<288?1000000-i:288);
+    EVP_DigestFinal_ex (&evp,md,NULL);
+    EVP_MD_CTX_cleanup (&evp);
 
     if (memcmp(md,app_c3,sizeof(app_c3)))
     {  fflush(stdout);
@@ -110,7 +139,7 @@ int main ()
 
     fprintf(stdout,"Testing SHA-384 ");
 
-    SHA384("abc",3,md);
+    EVP_Digest ("abc",3,md,NULL,EVP_sha384(),NULL);
     if (memcmp(md,app_d1,sizeof(app_d1)))
     {  fflush(stdout);
        fprintf(stderr,"\nTEST 1 of 3 failed.\n");
@@ -119,10 +148,10 @@ int main ()
     else
        fprintf(stdout,"."); fflush(stdout);
 
-    SHA384("abcdefgh""bcdefghi""cdefghij""defghijk"
-          "efghijkl""fghijklm""ghijklmn""hijklmno"
-          "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
-          "mnopqrst""nopqrstu",112,md);
+    EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
+               "efghijkl""fghijklm""ghijklmn""hijklmno"
+               "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
+               "mnopqrst""nopqrstu",112,md,NULL,EVP_sha384(),NULL);
     if (memcmp(md,app_d2,sizeof(app_d2)))
     {  fflush(stdout);
        fprintf(stderr,"\nTEST 2 of 3 failed.\n");
@@ -131,12 +160,14 @@ int main ()
     else
        fprintf(stdout,"."); fflush(stdout);
 
-    SHA384_Init(&ctx);
+    EVP_MD_CTX_init (&evp);
+    EVP_DigestInit_ex (&evp,EVP_sha384(),NULL);
     for (i=0;i<1000000;i+=64)
-       SHA512_Update(&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
-                           "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
-                           (1000000-i)<64?1000000-i:64);
-    SHA384_Final(md,&ctx);
+       EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
+                               "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
+                               (1000000-i)<64?1000000-i:64);
+    EVP_DigestFinal_ex (&evp,md,NULL);
+    EVP_MD_CTX_cleanup (&evp);
 
     if (memcmp(md,app_d3,sizeof(app_d3)))
     {  fflush(stdout);
@@ -147,4 +178,7 @@ int main ()
        fprintf(stdout,"."); fflush(stdout);
 
     fprintf(stdout," passed.\n"); fflush(stdout);
+
+  return 0;
 }
+#endif