]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/crypto/isa-l/isa-l_crypto/sha256_mb/sha256_mb_rand_ssl_test.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / sha256_mb / sha256_mb_rand_ssl_test.c
index 70d86d9ed43bfb3c5fdb72473deb71f4730c5287..768bfca788bc02a7c42de145aea85f3f4007c988 100644 (file)
@@ -2,7 +2,7 @@
   Copyright(c) 2011-2016 Intel Corporation All rights reserved.
 
   Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions 
+  modification, are permitted provided that the following conditions
   are met:
     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <openssl/sha.h>
 #include "sha256_mb.h"
+#include "endian_helper.h"
 
 #define TEST_LEN  (1024*1024)
 #define TEST_BUFS 200
@@ -52,11 +53,6 @@ void rand_buffer(unsigned char *buf, const long buffer_size)
                buf[i] = rand();
 }
 
-unsigned int byteswap(unsigned int x)
-{
-       return (x >> 24) | (x >> 8 & 0xff00) | (x << 8 & 0xff0000) | (x << 24);
-}
-
 int main(void)
 {
        SHA256_HASH_CTX_MGR *mgr = NULL;
@@ -65,13 +61,19 @@ int main(void)
        uint32_t i, j, fail = 0;
        uint32_t lens[TEST_BUFS];
        unsigned int jobs, t;
+       int ret;
 
        printf("multibinary_sha256 test, %d sets of %dx%d max: ", RANDOMS, TEST_BUFS,
               TEST_LEN);
 
        srand(TEST_SEED);
 
-       posix_memalign((void *)&mgr, 16, sizeof(SHA256_HASH_CTX_MGR));
+       ret = posix_memalign((void *)&mgr, 16, sizeof(SHA256_HASH_CTX_MGR));
+       if ((ret != 0) || (mgr == NULL)) {
+               printf("posix_memalign failed test aborted\n");
+               return 1;
+       }
+
        sha256_ctx_mgr_init(mgr);
 
        for (i = 0; i < TEST_BUFS; i++) {
@@ -99,11 +101,11 @@ int main(void)
        for (i = 0; i < TEST_BUFS; i++) {
                for (j = 0; j < SHA256_DIGEST_NWORDS; j++) {
                        if (ctxpool[i].job.result_digest[j] !=
-                           byteswap(((uint32_t *) digest_ssl[i])[j])) {
+                           to_be32(((uint32_t *) digest_ssl[i])[j])) {
                                fail++;
                                printf("Test%d, digest%d fail %08X <=> %08X\n",
                                       i, j, ctxpool[i].job.result_digest[j],
-                                      byteswap(((uint32_t *) digest_ssl[i])[j]));
+                                      to_be32(((uint32_t *) digest_ssl[i])[j]));
                        }
                }
        }
@@ -116,7 +118,7 @@ int main(void)
                sha256_ctx_mgr_init(mgr);
 
                for (i = 0; i < jobs; i++) {
-                       // Ramdom buffer with ramdom len and contents
+                       // Random buffer with random len and contents
                        lens[i] = rand() % (TEST_LEN);
                        rand_buffer(bufs[i], lens[i]);
 
@@ -132,11 +134,11 @@ int main(void)
                for (i = 0; i < jobs; i++) {
                        for (j = 0; j < SHA256_DIGEST_NWORDS; j++) {
                                if (ctxpool[i].job.result_digest[j] !=
-                                   byteswap(((uint32_t *) digest_ssl[i])[j])) {
+                                   to_be32(((uint32_t *) digest_ssl[i])[j])) {
                                        fail++;
                                        printf("Test%d, digest%d fail %08X <=> %08X\n",
                                               i, j, ctxpool[i].job.result_digest[j],
-                                              byteswap(((uint32_t *) digest_ssl[i])[j]));
+                                              to_be32(((uint32_t *) digest_ssl[i])[j]));
                                }
                        }
                }