-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: make libsodium an optional build dependency #9668
Draft
tobtoht
wants to merge
1
commit into
monero-project:master
Choose a base branch
from
tobtoht:libsodium_optional
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: ISC | ||
// SPDX-FileCopyrightText: 2013-2024 Frank Denis <j at pureftpd dot org> | ||
|
||
#include <stdint.h> | ||
|
||
#include "verify.h" | ||
|
||
#define crypto_verify_32_BYTES 32U | ||
|
||
#if defined(__x86_64__) && defined(__SSE2__) | ||
|
||
# ifdef __GNUC__ | ||
# pragma GCC target("sse2") | ||
# endif | ||
# include <emmintrin.h> | ||
|
||
static inline int | ||
crypto_verify_n(const unsigned char *x_, const unsigned char *y_, | ||
const int n) | ||
{ | ||
const __m128i zero = _mm_setzero_si128(); | ||
volatile __m128i v1, v2, z; | ||
volatile int m; | ||
int i; | ||
|
||
const volatile __m128i *volatile x = | ||
(const volatile __m128i *volatile) (const void *) x_; | ||
const volatile __m128i *volatile y = | ||
(const volatile __m128i *volatile) (const void *) y_; | ||
v1 = _mm_loadu_si128((const __m128i *) &x[0]); | ||
v2 = _mm_loadu_si128((const __m128i *) &y[0]); | ||
z = _mm_xor_si128(v1, v2); | ||
for (i = 1; i < n / 16; i++) { | ||
v1 = _mm_loadu_si128((const __m128i *) &x[i]); | ||
v2 = _mm_loadu_si128((const __m128i *) &y[i]); | ||
z = _mm_or_si128(z, _mm_xor_si128(v1, v2)); | ||
} | ||
m = _mm_movemask_epi8(_mm_cmpeq_epi32(z, zero)); | ||
v1 = zero; v2 = zero; z = zero; | ||
|
||
return (int) (((uint32_t) m + 1U) >> 16) - 1; | ||
} | ||
|
||
#else | ||
|
||
static inline int | ||
crypto_verify_n(const unsigned char *x_, const unsigned char *y_, | ||
const int n) | ||
{ | ||
const volatile unsigned char *volatile x = | ||
(const volatile unsigned char *volatile) x_; | ||
const volatile unsigned char *volatile y = | ||
(const volatile unsigned char *volatile) y_; | ||
volatile uint_fast16_t d = 0U; | ||
int i; | ||
|
||
for (i = 0; i < n; i++) { | ||
d |= x[i] ^ y[i]; | ||
} | ||
return (1 & ((d - 1) >> 8)) - 1; | ||
} | ||
|
||
#endif | ||
|
||
int | ||
crypto_verify_32(const unsigned char *x, const unsigned char *y) | ||
{ | ||
return crypto_verify_n(x, y, crypto_verify_32_BYTES); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: ISC | ||
// SPDX-FileCopyrightText: 2013-2024 Frank Denis <j at pureftpd dot org> | ||
|
||
#pragma once | ||
|
||
#include <stddef.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// fix naming collision with libsodium | ||
#define crypto_verify_32 monero_crypto_verify_32 | ||
|
||
int crypto_verify_32(const unsigned char *x, const unsigned char *y) | ||
__attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting: This very much requires strict aliasing disabled (which sodium does, quite explicitly, and by design; whereas this project's CMakeLists.txt suggest an intent to go the other direction):
The more creative the compiler vendors get, the more problematic even a single vendored function like this becomes.