This repository was archived by the owner on Nov 1, 2022. It is now read-only.
forked from jedisct1/libsodium
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,819 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,27 @@ | ||
include(CheckCCompilerFlag) # check_c_compiler_flag | ||
|
||
function(libsodium_add_c_flag) | ||
if("${ARGC}" STREQUAL "1") | ||
set(flag "${ARGV0}") | ||
set(var_name "") | ||
elseif("${ARGC}" STREQUAL "2") | ||
set(flag "${ARGV0}") | ||
set(var_name "${ARGV1}") | ||
else() | ||
message(FATAL_ERROR "Unexpected: ${ARGC}") | ||
endif() | ||
|
||
unset(__libsodium_check CACHE) | ||
|
||
message(STATUS "Check flag: '${flag}'") | ||
check_c_compiler_flag(${flag} __libsodium_check) | ||
|
||
if(__libsodium_check) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) | ||
set("${var_name}" TRUE PARENT_SCOPE) | ||
else() | ||
set("${var_name}" FALSE PARENT_SCOPE) | ||
endif() | ||
|
||
unset(__libsodium_check CACHE) | ||
endfunction() |
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,36 @@ | ||
include(CMakeParseArguments) # cmake_parse_arguments | ||
include(CheckFunctionExists) # check_function_exists | ||
|
||
function(libsodium_add_have_macro) | ||
set(optional "") | ||
set(one FUNCTION CMAKE_VAR CPP_MACRO) | ||
set(multiple "") | ||
|
||
# Introduce: | ||
# * x_FUNCTION | ||
# * x_CMAKE_VAR | ||
# * x_CPP_MACRO | ||
cmake_parse_arguments(x "${optional}" "${one}" "${multiple}" "${ARGV}") | ||
|
||
if(NOT "${x_UNPARSED_ARGUMENTS}" STREQUAL "") | ||
message(FATAL_ERROR "Unparsed arguments: ${x_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
if("${x_FUNCTION}" STREQUAL "") | ||
message(FATAL_ERROR "FUNCTION required") | ||
endif() | ||
|
||
if("${x_CMAKE_VAR}" STREQUAL "") | ||
message(FATAL_ERROR "CMAKE_VAR required") | ||
endif() | ||
|
||
if("${x_CPP_MACRO}" STREQUAL "") | ||
message(FATAL_ERROR "CPP_MACRO required") | ||
endif() | ||
|
||
check_function_exists("${x_FUNCTION}" "${x_CMAKE_VAR}") | ||
|
||
if(${x_CMAKE_VAR}) | ||
add_definitions("-D${x_CPP_MACRO}=1") | ||
endif() | ||
endfunction() |
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,33 @@ | ||
include(CMakeParseArguments) # cmake_parse_arguments | ||
|
||
function(libsodium_try_compile) | ||
set(optional "") | ||
set(one SOURCE CMAKE_VAR CPP_MACRO COMPILE_DEFINITIONS) | ||
set(multiple "") | ||
|
||
# Introduce: | ||
# * x_SOURCE | ||
# * x_CMAKE_VAR | ||
# * x_CPP_MACRO | ||
# * x_COMPILE_DEFINITIONS | ||
cmake_parse_arguments(x "${optional}" "${one}" "${multiple}" "${ARGV}") | ||
|
||
if(NOT "${x_UNPARSED_ARGUMENTS}" STREQUAL "") | ||
message(FATAL_ERROR "Unparsed arguments: ${x_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
if("${x_CMAKE_VAR}" STREQUAL "") | ||
message(FATAL_ERROR "CMAKE_VAR required") | ||
endif() | ||
|
||
try_compile( | ||
${x_CMAKE_VAR} | ||
"${CMAKE_CURRENT_BINARY_DIR}/try_compile" | ||
"${CMAKE_CURRENT_LIST_DIR}/cmake/try_compile/${x_SOURCE}" | ||
COMPILE_DEFINITIONS "${x_COMPILE_DEFINITIONS}" | ||
) | ||
|
||
if(${x_CMAKE_VAR} AND NOT "${x_CPP_MACRO}" STREQUAL "") | ||
add_definitions("-D${x_CPP_MACRO}=1") | ||
endif() | ||
endfunction() |
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,6 @@ | ||
@PACKAGE_INIT@ | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") | ||
check_required_components("@PROJECT_NAME@") |
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,13 @@ | ||
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__) | ||
# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64) | ||
# error Windows x86_64 calling conventions are not supported yet | ||
# endif | ||
/* neat */ | ||
#else | ||
# error !x86_64 | ||
#endif | ||
|
||
void main() | ||
{ | ||
__asm__("pxor %xmm12,%xmm6"); | ||
} |
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,6 @@ | ||
int main(void) | ||
{ | ||
static volatile int _sodium_lock; | ||
__sync_lock_test_and_set(&_sodium_lock, 1); | ||
__sync_lock_release(&_sodium_lock); | ||
} |
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,14 @@ | ||
#ifdef __native_client__ | ||
# error NativeClient detected - Avoiding AVX2 opcodes | ||
#endif | ||
|
||
#pragma GCC target("avx2") | ||
|
||
#include <immintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m256 x = _mm256_set1_ps(3.14); | ||
__m256 y = _mm256_permutevar8x32_ps(x, _mm256_set1_epi32(42)); | ||
return _mm256_movemask_ps(_mm256_cmp_ps(x, y, _CMP_NEQ_OQ)); | ||
} |
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,13 @@ | ||
#ifdef __native_client__ | ||
# error NativeClient detected - Avoiding AVX512F opcodes | ||
#endif | ||
|
||
#pragma GCC target("avx512f") | ||
|
||
#include <immintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m512i x = _mm512_setzero_epi32(); | ||
__m512i y = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), x); | ||
} |
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,13 @@ | ||
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__) | ||
# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64) | ||
# error Windows x86_64 calling conventions are not supported yet | ||
# endif | ||
/* neat */ | ||
#else | ||
# error !x86_64 | ||
#endif | ||
|
||
void main() | ||
{ | ||
__asm__ __volatile__ ("vpunpcklqdq %xmm0,%xmm13,%xmm0"); | ||
} |
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,12 @@ | ||
#ifdef __native_client__ | ||
# error NativeClient detected - Avoiding AVX opcodes | ||
#endif | ||
|
||
#pragma GCC target("avx") | ||
|
||
#include <immintrin.h> | ||
|
||
int main(void) | ||
{ | ||
_mm256_zeroall(); | ||
} |
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,8 @@ | ||
void main() | ||
{ | ||
unsigned int cpu_info[4]; | ||
__asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" : | ||
"=a" (cpu_info[0]), "=&r" (cpu_info[1]), | ||
"=c" (cpu_info[2]), "=d" (cpu_info[3]) : | ||
"0" (0U), "2" (0U)); | ||
} |
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,8 @@ | ||
#pragma GCC target("sse2") | ||
|
||
#include <emmintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m128d x = _mm_setzero_pd(); | ||
} |
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,8 @@ | ||
#include <limits.h> | ||
#include <stdint.h> | ||
|
||
void main() | ||
{ | ||
(void) SIZE_MAX; | ||
(void) UINT64_MAX; | ||
} |
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,7 @@ | ||
#include <string.h> | ||
|
||
int main(void) | ||
{ | ||
char dummy[42]; | ||
(void) memset_s(dummy, (rsize_t) sizeof dummy, 0, (rsize_t) sizeof dummy); | ||
} |
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,7 @@ | ||
#if !defined(__native_client__) | ||
# error "__native_client__ not defined" | ||
#endif | ||
|
||
int main(void) | ||
{ | ||
} |
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,10 @@ | ||
#pragma GCC target("sse3") | ||
|
||
#include <pmmintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m128 x = _mm_addsub_ps( | ||
_mm_cvtpd_ps(_mm_setzero_pd()), _mm_cvtpd_ps(_mm_setzero_pd()) | ||
); | ||
} |
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,13 @@ | ||
#ifdef __native_client__ | ||
# error NativeClient detected - Avoiding RDRAND opcodes | ||
#endif | ||
|
||
#pragma GCC target("rdrnd") | ||
|
||
#include <immintrin.h> | ||
|
||
int main(void) | ||
{ | ||
unsigned long long x; | ||
_rdrand64_step(&x); | ||
} |
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,8 @@ | ||
#pragma GCC target("sse4.1") | ||
|
||
#include <smmintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m128i x = _mm_minpos_epu16(_mm_setzero_si128()); | ||
} |
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,30 @@ | ||
#ifndef __GNUC__ | ||
# error mode(TI) is a gcc extension | ||
#endif | ||
|
||
#if defined(__clang__) && !defined(__x86_64__) | ||
# error clang doesn't properly compile smult_curve25519_donna_c64.c | ||
#endif | ||
|
||
#ifndef NATIVE_LITTLE_ENDIAN | ||
# error donna_c64 currently requires a little endian CPU | ||
#endif | ||
|
||
#ifdef EMSCRIPTEN | ||
# error emscripten currently supports only shift operations on integers \ | ||
# larger than 64 bits | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
typedef unsigned uint128_t __attribute__((mode(TI))); | ||
|
||
void fcontract(uint128_t *t) | ||
{ | ||
*t += 0x8000000000000 - 1; | ||
} | ||
|
||
void main() | ||
{ | ||
(void) fcontract; | ||
} |
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,8 @@ | ||
#pragma GCC target("ssse3") | ||
|
||
#include <tmmintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m64 x = _mm_abs_pi32(_m_from_int(0)); | ||
} |
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,2 @@ | ||
__attribute__((weak)) void __dummy(void *x) { } | ||
void f(void *x) { __dummy(x); } |
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,14 @@ | ||
#ifdef __native_client__ | ||
# error NativeClient detected - Avoiding AESNI opcodes | ||
#endif | ||
|
||
#pragma GCC target("aes") | ||
#pragma GCC target("pclmul") | ||
|
||
#include <wmmintrin.h> | ||
|
||
int main(void) | ||
{ | ||
__m128i x = _mm_aesimc_si128(_mm_setzero_si128()); | ||
__m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0); | ||
} |
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,6 @@ | ||
#include <intrin.h> | ||
|
||
int main(void) | ||
{ | ||
(void) _xgetbv(0); | ||
} |
Oops, something went wrong.