summaryrefslogtreecommitdiff
path: root/libs/libsodium/src/crypto_stream
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-06-21 14:29:17 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-06-21 14:29:17 +0300
commit46ea86584a9787c8b9dc3983cf23d9b5b93b5841 (patch)
treefbaf3793ae2170f7982f08a62c028a23cd9afedd /libs/libsodium/src/crypto_stream
parent82e75be329dd0f30c0281ef9c3c08488b89d109f (diff)
fixes #4477 (libsodium: update to 1.0.20)
Diffstat (limited to 'libs/libsodium/src/crypto_stream')
-rw-r--r--libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c15
-rw-r--r--libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c13
-rw-r--r--libs/libsodium/src/crypto_stream/chacha20/dolbeau/u8.h31
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/stream_salsa20.h2
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm.S6
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm_namespace.h10
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6.h1
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c23
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c10
-rw-r--r--libs/libsodium/src/crypto_stream/salsa20/xmm6int/u0.h2
-rw-r--r--libs/libsodium/src/crypto_stream/xchacha20/stream_xchacha20.c2
11 files changed, 60 insertions, 55 deletions
diff --git a/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c b/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c
index 1e2cdf266c..ea27928964 100644
--- a/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c
+++ b/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c
@@ -6,23 +6,22 @@
#include "core.h"
#include "crypto_stream_chacha20.h"
#include "private/common.h"
-#include "private/sse2_64_32.h"
#include "utils.h"
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)
-# ifdef __GNUC__
-# pragma GCC target("sse2")
-# pragma GCC target("ssse3")
-# pragma GCC target("sse4.1")
-# pragma GCC target("avx2")
+# ifdef __clang__
+# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2"))), apply_to = function)
+# elif defined(__GNUC__)
+# pragma GCC target("sse2,ssse3,sse4.1,avx2")
# endif
# include <emmintrin.h>
# include <immintrin.h>
# include <smmintrin.h>
# include <tmmintrin.h>
+# include "private/sse2_64_32.h"
# include "../stream_chacha20.h"
# include "chacha20_dolbeau-avx2.h"
@@ -174,4 +173,8 @@ struct crypto_stream_chacha20_implementation
SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic
};
+# ifdef __clang__
+# pragma clang attribute pop
+# endif
+
#endif
diff --git a/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c b/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c
index ae5df1cc28..5175624fbb 100644
--- a/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c
+++ b/libs/libsodium/src/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c
@@ -6,18 +6,19 @@
#include "core.h"
#include "crypto_stream_chacha20.h"
#include "private/common.h"
-#include "private/sse2_64_32.h"
#include "utils.h"
#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)
-# ifdef __GNUC__
-# pragma GCC target("sse2")
-# pragma GCC target("ssse3")
+# ifdef __clang__
+# pragma clang attribute push(__attribute__((target("sse2,ssse3"))), apply_to = function)
+# elif defined(__GNUC__)
+# pragma GCC target("sse2,ssse3")
# endif
# include <emmintrin.h>
# include <tmmintrin.h>
+# include "private/sse2_64_32.h"
# include "../stream_chacha20.h"
# include "chacha20_dolbeau-ssse3.h"
@@ -168,4 +169,8 @@ struct crypto_stream_chacha20_implementation
SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic
};
+# ifdef __clang__
+# pragma clang attribute pop
+# endif
+
#endif
diff --git a/libs/libsodium/src/crypto_stream/chacha20/dolbeau/u8.h b/libs/libsodium/src/crypto_stream/chacha20/dolbeau/u8.h
index c92fbd3514..adc7da9ab8 100644
--- a/libs/libsodium/src/crypto_stream/chacha20/dolbeau/u8.h
+++ b/libs/libsodium/src/crypto_stream/chacha20/dolbeau/u8.h
@@ -2,21 +2,6 @@
#define VEC8_ROT(A, IMM) \
_mm256_or_si256(_mm256_slli_epi32(A, IMM), _mm256_srli_epi32(A, (32 - IMM)))
-/* implements a vector quarter round by-the-book (naive!) */
-#define VEC8_QUARTERROUND_NAIVE(A, B, C, D) \
- x_##A = _mm256_add_epi32(x_##A, x_##B); \
- t_##A = _mm256_xor_si256(x_##D, x_##A); \
- x_##D = VEC8_ROT(t_##A, 16); \
- x_##C = _mm256_add_epi32(x_##C, x_##D); \
- t_##C = _mm256_xor_si256(x_##B, x_##C); \
- x_##B = VEC8_ROT(t_##C, 12); \
- x_##A = _mm256_add_epi32(x_##A, x_##B); \
- t_##A = _mm256_xor_si256(x_##D, x_##A); \
- x_##D = VEC8_ROT(t_##A, 8); \
- x_##C = _mm256_add_epi32(x_##C, x_##D); \
- t_##C = _mm256_xor_si256(x_##B, x_##C); \
- x_##B = VEC8_ROT(t_##C, 7)
-
/* same, but replace 2 of the shift/shift/or "rotation" by byte shuffles (8 &
* 16) (better) */
#define VEC8_QUARTERROUND_SHUFFLE(A, B, C, D) \
@@ -33,22 +18,6 @@
t_##C = _mm256_xor_si256(x_##B, x_##C); \
x_##B = VEC8_ROT(t_##C, 7)
-/* same, but replace 2 of the shift/shift/or "rotation" by byte & word shuffles
- * (8 & 16) (not as good as previous) */
-#define VEC8_QUARTERROUND_SHUFFLE2(A, B, C, D) \
- x_##A = _mm256_add_epi32(x_##A, x_##B); \
- t_##A = _mm256_xor_si256(x_##D, x_##A); \
- x_##D = _mm256_shufflehi_epi16(_mm256_shufflelo_epi16(t_##A, 0xb1), 0xb1); \
- x_##C = _mm256_add_epi32(x_##C, x_##D); \
- t_##C = _mm256_xor_si256(x_##B, x_##C); \
- x_##B = VEC8_ROT(t_##C, 12); \
- x_##A = _mm256_add_epi32(x_##A, x_##B); \
- t_##A = _mm256_xor_si256(x_##D, x_##A); \
- x_##D = _mm256_shuffle_epi8(t_##A, rot8); \
- x_##C = _mm256_add_epi32(x_##C, x_##D); \
- t_##C = _mm256_xor_si256(x_##B, x_##C); \
- x_##B = VEC8_ROT(t_##C, 7)
-
#define VEC8_QUARTERROUND(A, B, C, D) VEC8_QUARTERROUND_SHUFFLE(A, B, C, D)
#define VEC8_LINE1(A, B, C, D) \
diff --git a/libs/libsodium/src/crypto_stream/salsa20/stream_salsa20.h b/libs/libsodium/src/crypto_stream/salsa20/stream_salsa20.h
index 0b5971ca48..0b5f3ab184 100644
--- a/libs/libsodium/src/crypto_stream/salsa20/stream_salsa20.h
+++ b/libs/libsodium/src/crypto_stream/salsa20/stream_salsa20.h
@@ -4,6 +4,8 @@
#include <stdint.h>
+#include "private/quirks.h"
+
typedef struct crypto_stream_salsa20_implementation {
int (*stream)(unsigned char *c, unsigned long long clen,
const unsigned char *n, const unsigned char *k);
diff --git a/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm.S b/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm.S
index 9ecea1b088..0406b29da9 100644
--- a/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm.S
+++ b/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm.S
@@ -1,5 +1,8 @@
#ifdef HAVE_AMD64_ASM
+#include "private/asm_cet.h"
+#include "salsa20_xmm6-asm_namespace.h"
+
.text
.p2align 5
@@ -15,6 +18,8 @@ ASM_HIDE_SYMBOL _stream_salsa20_xmm6
#endif
stream_salsa20_xmm6:
_stream_salsa20_xmm6:
+
+_CET_ENDBR
mov %rsp,%r11
and $31,%r11
add $512,%r11
@@ -56,6 +61,7 @@ ASM_HIDE_SYMBOL _stream_salsa20_xmm6_xor_ic
stream_salsa20_xmm6_xor_ic:
_stream_salsa20_xmm6_xor_ic:
+_CET_ENDBR
mov %rsp,%r11
and $31,%r11
add $512,%r11
diff --git a/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm_namespace.h b/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm_namespace.h
new file mode 100644
index 0000000000..15c5212ebf
--- /dev/null
+++ b/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6-asm_namespace.h
@@ -0,0 +1,10 @@
+#ifndef salsa20_xmm6_asm_namespace_H
+#define salsa20_xmm6_asm_namespace_H
+
+#define stream_salsa20_xmm6 _sodium_stream_salsa20_xmm6
+#define _stream_salsa20_xmm6 __sodium_stream_salsa20_xmm6
+
+#define stream_salsa20_xmm6_xor_ic _sodium_stream_salsa20_xmm6_xor_ic
+#define _stream_salsa20_xmm6_xor_ic __sodium_stream_salsa20_xmm6_xor_ic
+
+#endif
diff --git a/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6.h b/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6.h
index 3ccbb5e8e6..d88542fd24 100644
--- a/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6.h
+++ b/libs/libsodium/src/crypto_stream/salsa20/xmm6/salsa20_xmm6.h
@@ -3,6 +3,7 @@
#include "../stream_salsa20.h"
#include "crypto_stream_salsa20.h"
+#include "salsa20_xmm6-asm_namespace.h"
extern struct crypto_stream_salsa20_implementation
crypto_stream_salsa20_xmm6_implementation;
diff --git a/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c b/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c
index 95bb63fd13..41cc8a610a 100644
--- a/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c
+++ b/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c
@@ -5,23 +5,22 @@
#include "crypto_stream_salsa20.h"
#include "private/common.h"
-#include "private/sse2_64_32.h"
#include "utils.h"
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)
-# ifdef __GNUC__
-# pragma GCC target("sse2")
-# pragma GCC target("ssse3")
-# pragma GCC target("sse4.1")
-# pragma GCC target("avx2")
+# ifdef __clang__
+# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2"))), apply_to = function)
+# elif defined(__GNUC__)
+# pragma GCC target("sse2,ssse3,sse4.1,avx2")
# endif
-#include <emmintrin.h>
-#include <immintrin.h>
-#include <smmintrin.h>
-#include <tmmintrin.h>
+# include <emmintrin.h>
+# include <immintrin.h>
+# include <smmintrin.h>
+# include <tmmintrin.h>
+# include "private/sse2_64_32.h"
# include "../stream_salsa20.h"
# include "salsa20_xmm6int-avx2.h"
@@ -128,4 +127,8 @@ struct crypto_stream_salsa20_implementation
SODIUM_C99(.stream_xor_ic =) stream_avx2_xor_ic
};
+#ifdef __clang__
+# pragma clang attribute pop
+#endif
+
#endif
diff --git a/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c b/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c
index 41dc8193fc..c3694cd70f 100644
--- a/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c
+++ b/libs/libsodium/src/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c
@@ -5,15 +5,17 @@
#include "crypto_stream_salsa20.h"
#include "private/common.h"
-#include "private/sse2_64_32.h"
#include "utils.h"
#ifdef HAVE_EMMINTRIN_H
-# ifdef __GNUC__
+# ifdef __clang__
+# pragma clang attribute push(__attribute__((target("sse2"))), apply_to = function)
+# elif defined(__GNUC__)
# pragma GCC target("sse2")
# endif
# include <emmintrin.h>
+# include "private/sse2_64_32.h"
# include "../stream_salsa20.h"
# include "salsa20_xmm6int-sse2.h"
@@ -119,4 +121,8 @@ struct crypto_stream_salsa20_implementation
SODIUM_C99(.stream_xor_ic =) stream_sse2_xor_ic
};
+#ifdef __clang__
+# pragma clang attribute pop
+#endif
+
#endif
diff --git a/libs/libsodium/src/crypto_stream/salsa20/xmm6int/u0.h b/libs/libsodium/src/crypto_stream/salsa20/xmm6int/u0.h
index e2634b4a3e..cce494af6e 100644
--- a/libs/libsodium/src/crypto_stream/salsa20/xmm6int/u0.h
+++ b/libs/libsodium/src/crypto_stream/salsa20/xmm6int/u0.h
@@ -5,7 +5,7 @@ if (bytes > 0) {
__m128i diag3 = _mm_loadu_si128((const __m128i *) (x + 12));
__m128i a0, a1, a2, a3, a4, a5, a6, a7;
__m128i b0, b1, b2, b3, b4, b5, b6, b7;
- uint8_t partialblock[64];
+ uint8_t partialblock[64] = { 0 };
unsigned int i;
diff --git a/libs/libsodium/src/crypto_stream/xchacha20/stream_xchacha20.c b/libs/libsodium/src/crypto_stream/xchacha20/stream_xchacha20.c
index 47807e0a44..c9d7e70dcc 100644
--- a/libs/libsodium/src/crypto_stream/xchacha20/stream_xchacha20.c
+++ b/libs/libsodium/src/crypto_stream/xchacha20/stream_xchacha20.c
@@ -35,7 +35,7 @@ crypto_stream_xchacha20(unsigned char *c, unsigned long long clen,
COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES <= sizeof k2);
COMPILER_ASSERT(crypto_stream_chacha20_NONCEBYTES ==
crypto_stream_xchacha20_NONCEBYTES -
- crypto_core_hchacha20_INPUTBYTES);
+ crypto_core_hchacha20_INPUTBYTES);
return crypto_stream_chacha20(c, clen, n + crypto_core_hchacha20_INPUTBYTES,
k2);