]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/crypto/isa-l/isa-l_crypto/mh_sha1/mh_sha1_ref.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / mh_sha1 / mh_sha1_ref.c
index fee928a9c297d7aad339c4cf611dba5273d32bc1..71caba50ec315903b09ff491dc17b6bb5bbc0505 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.
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
 
+#if (__GNUC__ >= 11)
+# define OPT_FIX __attribute__ ((noipa))
+#else
+# define OPT_FIX
+#endif
+
 #define W(x) w[(x) & 15]
 
 #define step00_19(i,a,b,c,d,e) \
        if (i>15) W(i) = rol32(W(i-3)^W(i-8)^W(i-14)^W(i-16), 1); \
-       else W(i) = bswap(ww[i]); \
+       else W(i) = to_be32(ww[i]); \
        e += rol32(a,5) + F1(b,c,d) + 0x5A827999 + W(i); \
        b = rol32(b,30)
 
@@ -64,7 +70,7 @@
        e += rol32(a,5) + F4(b,c,d) + 0xCA62C1D6 + W(i); \
        b = rol32(b,30)
 
-void sha1_single_for_mh_sha1_ref(const uint8_t * data, uint32_t digest[])
+static void OPT_FIX sha1_single_for_mh_sha1_ref(const uint8_t * data, uint32_t digest[])
 {
        uint32_t a, b, c, d, e;
        uint32_t w[16] = { 0 };
@@ -171,11 +177,6 @@ void sha1_for_mh_sha1_ref(const uint8_t * input_data, uint32_t * digest, const u
 {
        uint32_t i, j;
        uint8_t buf[2 * SHA1_BLOCK_SIZE];
-       union {
-               uint64_t uint;
-               uint8_t uchar[8];
-       } convert;
-       uint8_t *p;
 
        digest[0] = MH_SHA1_H0;
        digest[1] = MH_SHA1_H1;
@@ -200,16 +201,7 @@ void sha1_for_mh_sha1_ref(const uint8_t * input_data, uint32_t * digest, const u
        else
                i = SHA1_BLOCK_SIZE;
 
-       convert.uint = 8 * len;
-       p = buf + i - 8;
-       p[0] = convert.uchar[7];
-       p[1] = convert.uchar[6];
-       p[2] = convert.uchar[5];
-       p[3] = convert.uchar[4];
-       p[4] = convert.uchar[3];
-       p[5] = convert.uchar[2];
-       p[6] = convert.uchar[1];
-       p[7] = convert.uchar[0];
+       *(uint64_t *) (buf + i - 8) = to_be64((uint64_t) len * 8);
 
        sha1_single_for_mh_sha1_ref(buf, digest);
        if (i == (2 * SHA1_BLOCK_SIZE))
@@ -355,8 +347,8 @@ void mh_sha1_block_ref(const uint8_t * input_data, uint32_t(*digests)[HASH_SEGS]
 }
 
 void mh_sha1_tail_ref(uint8_t * partial_buffer, uint32_t total_len,
-                          uint32_t(*mh_sha1_segs_digests)[HASH_SEGS], uint8_t * frame_buffer,
-                          uint32_t digests[SHA1_DIGEST_WORDS])
+                     uint32_t(*mh_sha1_segs_digests)[HASH_SEGS], uint8_t * frame_buffer,
+                     uint32_t digests[SHA1_DIGEST_WORDS])
 {
        uint64_t partial_buffer_len, len_in_bit;
 
@@ -375,13 +367,13 @@ void mh_sha1_tail_ref(uint8_t * partial_buffer, uint32_t total_len,
                memset(partial_buffer, 0, MH_SHA1_BLOCK_SIZE);
        }
        //Padding the block
-       len_in_bit = bswap64((uint64_t) total_len * 8);
+       len_in_bit = to_be64((uint64_t) total_len * 8);
        *(uint64_t *) (partial_buffer + MH_SHA1_BLOCK_SIZE - 8) = len_in_bit;
        mh_sha1_block_ref(partial_buffer, mh_sha1_segs_digests, frame_buffer, 1);
 
        //Calculate multi-hash SHA1 digests (segment digests as input message)
        sha1_for_mh_sha1_ref((uint8_t *) mh_sha1_segs_digests, digests,
-                        4 * SHA1_DIGEST_WORDS * HASH_SEGS);
+                            4 * SHA1_DIGEST_WORDS * HASH_SEGS);
 
        return;
 }