Skip to content

Commit

Permalink
deps: update libsodium to 1.0.20
Browse files Browse the repository at this point in the history
Also, a couple of fixes in the updater.
  • Loading branch information
santigimeno committed Nov 14, 2024
1 parent 624dde8 commit c98aa3d
Show file tree
Hide file tree
Showing 36 changed files with 218 additions and 98 deletions.
2 changes: 1 addition & 1 deletion deps/sodium/LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ISC License
*
* Copyright (c) 2013-2023
* Copyright (c) 2013-2024
* Frank Denis <j at pureftpd dot org>
*
* Permission to use, copy, modify, and/or distribute this software for any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

#include "aegis128l_armcrypto.h"

#ifdef __clang__
#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target("+simd+crypto")
#endif

#ifndef __ARM_FEATURE_CRYPTO
#define __ARM_FEATURE_CRYPTO 1
#endif
Expand All @@ -32,6 +26,12 @@

#include <arm_neon.h>

#ifdef __clang__
#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target("+simd+crypto")
#endif

#define AES_BLOCK_LENGTH 16

typedef uint8x16_t aes_block_t;
Expand Down
23 changes: 21 additions & 2 deletions deps/sodium/src/libsodium/crypto_aead/aegis128l/aegis128l_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ aegis128l_absorb(const uint8_t *const src, aes_block_t *const state)
aegis128l_update(state, msg0, msg1);
}

static inline void
aegis128l_absorb2(const uint8_t *const src, aes_block_t *const state)
{
aes_block_t msg0, msg1, msg2, msg3;

msg0 = AES_BLOCK_LOAD(src + 0 * AES_BLOCK_LENGTH);
msg1 = AES_BLOCK_LOAD(src + 1 * AES_BLOCK_LENGTH);
msg2 = AES_BLOCK_LOAD(src + 2 * AES_BLOCK_LENGTH);
msg3 = AES_BLOCK_LOAD(src + 3 * AES_BLOCK_LENGTH);
aegis128l_update(state, msg0, msg1);
aegis128l_update(state, msg2, msg3);
}

static void
aegis128l_enc(uint8_t *const dst, const uint8_t *const src, aes_block_t *const state)
{
Expand Down Expand Up @@ -152,7 +165,10 @@ encrypt_detached(uint8_t *c, uint8_t *mac, size_t maclen, const uint8_t *m, size

aegis128l_init(k, npub, state);

for (i = 0; i + RATE <= adlen; i += RATE) {
for (i = 0; i + RATE * 2 <= adlen; i += RATE * 2) {
aegis128l_absorb2(ad + i, state);
}
for (; i + RATE <= adlen; i += RATE) {
aegis128l_absorb(ad + i, state);
}
if (adlen % RATE) {
Expand Down Expand Up @@ -189,7 +205,10 @@ decrypt_detached(uint8_t *m, const uint8_t *c, size_t clen, const uint8_t *mac,

aegis128l_init(k, npub, state);

for (i = 0; i + RATE <= adlen; i += RATE) {
for (i = 0; i + RATE * 2 <= adlen; i += RATE * 2) {
aegis128l_absorb2(ad + i, state);
}
for (; i + RATE <= adlen; i += RATE) {
aegis128l_absorb(ad + i, state);
}
if (adlen % RATE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

#include "aegis256_armcrypto.h"

#ifdef __clang__
#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target("+simd+crypto")
#endif

#ifndef __ARM_FEATURE_CRYPTO
#define __ARM_FEATURE_CRYPTO 1
#endif
Expand All @@ -32,6 +26,12 @@

#include <arm_neon.h>

#ifdef __clang__
#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target("+simd+crypto")
#endif

#define AES_BLOCK_LENGTH 16

typedef uint8x16_t aes_block_t;
Expand Down
21 changes: 19 additions & 2 deletions deps/sodium/src/libsodium/crypto_aead/aegis256/aegis256_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ aegis256_absorb(const uint8_t *const src, aes_block_t *const state)
aegis256_update(state, msg);
}

static inline void
aegis256_absorb2(const uint8_t *const src, aes_block_t *const state)
{
aes_block_t msg, msg2;

msg = AES_BLOCK_LOAD(src + 0 * AES_BLOCK_LENGTH);
msg2 = AES_BLOCK_LOAD(src + 1 * AES_BLOCK_LENGTH);
aegis256_update(state, msg);
aegis256_update(state, msg2);
}

static void
aegis256_enc(uint8_t *const dst, const uint8_t *const src, aes_block_t *const state)
{
Expand Down Expand Up @@ -137,7 +148,10 @@ encrypt_detached(uint8_t *c, uint8_t *mac, size_t maclen, const uint8_t *m, size

aegis256_init(k, npub, state);

for (i = 0; i + RATE <= adlen; i += RATE) {
for (i = 0; i + 2 * RATE <= adlen; i += 2 * RATE) {
aegis256_absorb2(ad + i, state);
}
for (; i + RATE <= adlen; i += RATE) {
aegis256_absorb(ad + i, state);
}
if (adlen % RATE) {
Expand Down Expand Up @@ -174,7 +188,10 @@ decrypt_detached(uint8_t *m, const uint8_t *c, size_t clen, const uint8_t *mac,

aegis256_init(k, npub, state);

for (i = 0; i + RATE <= adlen; i += RATE) {
for (i = 0; i + 2 * RATE <= adlen; i += 2 * RATE) {
aegis256_absorb2(ad + i, state);
}
for (; i + RATE <= adlen; i += RATE) {
aegis256_absorb(ad + i, state);
}
if (adlen % RATE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#if defined(HAVE_TMMINTRIN_H) && defined(HAVE_WMMINTRIN_H)

#ifdef __GNUC__
#pragma GCC target("avx,aes,pclmul")
#endif
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("aes,avx,pclmul"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("aes,avx,pclmul")
# endif

#if !defined(_MSC_VER) || _MSC_VER < 1800
#define __vectorcall
Expand Down Expand Up @@ -1006,4 +1008,8 @@ crypto_aead_aes256gcm_is_available(void)
return sodium_runtime_has_pclmul() & sodium_runtime_has_aesni() & sodium_runtime_has_avx();
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#define __vectorcall
#endif

#ifdef __clang__
#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target("+simd+crypto")
#endif

#ifndef __ARM_FEATURE_CRYPTO
#define __ARM_FEATURE_CRYPTO 1
#endif
Expand All @@ -34,6 +28,12 @@

#include <arm_neon.h>

#ifdef __clang__
#pragma clang attribute push(__attribute__((target("neon,crypto,aes"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target("+simd+crypto")
#endif

#define ABYTES crypto_aead_aes256gcm_ABYTES
#define NPUBBYTES crypto_aead_aes256gcm_NPUBBYTES
#define KEYBYTES crypto_aead_aes256gcm_KEYBYTES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
#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>
Expand Down Expand Up @@ -46,4 +45,8 @@ blake2b_compress_avx2(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#if 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")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1")
# endif

# include <emmintrin.h>
Expand Down Expand Up @@ -84,4 +84,8 @@ blake2b_compress_sse41(blake2b_state *S,
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#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>
Expand Down Expand Up @@ -87,4 +88,8 @@ blake2b_compress_ssse3(blake2b_state *S,
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
5 changes: 5 additions & 0 deletions deps/sodium/src/libsodium/crypto_kdf/hkdf/kdf_hkdf_sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@ crypto_kdf_hkdf_sha512_bytes_max(void)
{
return crypto_kdf_hkdf_sha512_BYTES_MAX;
}

size_t crypto_kdf_hkdf_sha512_statebytes(void)
{
return sizeof(crypto_kdf_hkdf_sha512_state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#if defined(HAVE_TI_MODE) && defined(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

Expand Down Expand Up @@ -946,4 +948,8 @@ struct crypto_onetimeauth_poly1305_implementation
SODIUM_C99(.onetimeauth_final =) crypto_onetimeauth_poly1305_sse2_final
};

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
#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

# ifdef _MSC_VER
Expand Down Expand Up @@ -236,4 +235,9 @@ argon2_fill_segment_avx2(const argon2_instance_t *instance,
}
}
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
#if defined(HAVE_AVX512FINTRIN_H) && 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")
# pragma GCC target("avx512f")
# ifdef __clang__
# if __clang_major__ >= 18
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2,avx512f,evex512"))), apply_to = function)
# else
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2,avx512f"))), apply_to = function)
# endif
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1,avx2,avx512f")
# endif

# ifdef _MSC_VER
Expand Down Expand Up @@ -241,4 +243,9 @@ argon2_fill_segment_avx512f(const argon2_instance_t *instance,
}
}
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

#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

# ifdef _MSC_VER
Expand Down Expand Up @@ -235,4 +236,9 @@ argon2_fill_segment_ssse3(const argon2_instance_t *instance,
}
}
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Loading

0 comments on commit c98aa3d

Please sign in to comment.