mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-10-08 00:03:38 -04:00
Merge branch 'master' into cp-update-picnic
This commit is contained in:
commit
35688bf463
@ -46,7 +46,7 @@ if [[ ${ENABLE_KEX_RLWE_NEWHOPE} == 0 ]];then
|
||||
enable_disable_str+=" --disable-kex-rlwe-newhope"
|
||||
fi
|
||||
|
||||
if [[ ${ENABLE_KEX_SIDH_CLN16} == 0 ]];then
|
||||
if [[ ${ENABLE_KEX_SIDH_MSR} == 0 ]];then
|
||||
enable_disable_str+=" --disable-kex-sidh-cln16"
|
||||
fi
|
||||
|
||||
|
@ -9,7 +9,7 @@ matrix:
|
||||
env:
|
||||
- ENABLE_SIDH_IQC_REF=1
|
||||
- ENABLE_KEX_LWE_FRODO=0
|
||||
- ENABLE_KEX_SIDH_CLN16=0
|
||||
- ENABLE_KEX_SIDH_MSR=0
|
||||
- ENABLE_SIG_PICNIC=0
|
||||
- USE_OPENSSL=1
|
||||
- ENABLE_KEX_RLWE_NEWHOPE_AVX2=1
|
||||
|
@ -56,6 +56,7 @@ endif
|
||||
|
||||
installheaderdir=$(includedir)/oqs
|
||||
installheader_HEADERS=config.h \
|
||||
src/common/oqs.h \
|
||||
src/common/common.h \
|
||||
src/crypto/aes/aes.h \
|
||||
src/crypto/rand/rand.h \
|
||||
@ -197,6 +198,7 @@ endif
|
||||
links:
|
||||
$(MKDIR_P) include/oqs
|
||||
cp -f config.h include/oqs
|
||||
cp -f src/common/oqs.h include/oqs
|
||||
cp -f src/common/common.h include/oqs
|
||||
cp -f src/crypto/aes/aes.h include/oqs
|
||||
cp -f src/crypto/rand/rand.h include/oqs
|
||||
|
@ -35,6 +35,7 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\common\oqs.h" />
|
||||
<ClInclude Include="..\..\src\common\common.h" />
|
||||
<ClInclude Include="..\..\src\crypto\aes\aes.h" />
|
||||
<ClInclude Include="..\..\src\crypto\aes\aes_local.h" />
|
||||
@ -236,6 +237,7 @@
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -276,6 +278,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -316,6 +319,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -361,6 +365,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -407,6 +412,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -451,6 +457,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -495,6 +502,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
@ -544,6 +552,7 @@ msbuild /t:Rebuild /p:Configuration=Release "$(SolutionDir)..\src\sig_picnic\ex
|
||||
<PreBuildEvent>
|
||||
<Command>mkdir "$(SolutionDir)include\oqs"
|
||||
del /Q "$(SolutionDir)include\oqs\*.*"
|
||||
copy "$(SolutionDir)..\src\common\oqs.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\common\common.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\aes\aes.h" "$(SolutionDir)include\oqs\"
|
||||
copy "$(SolutionDir)..\src\crypto\rand\rand.h" "$(SolutionDir)include\oqs\"
|
||||
|
@ -185,6 +185,8 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\sig_picnic\external\picnic.h">
|
||||
<Filter>Sig_Picnic</Filter>
|
||||
<ClInclude Include="..\..\src\common\oqs.h">
|
||||
<Filter>Common</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -164,7 +164,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -183,7 +183,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@ -193,7 +193,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;oqs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -202,7 +202,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions); WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -222,18 +222,18 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions); WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;oqs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@ -244,7 +244,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
@ -267,7 +267,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
@ -279,7 +279,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;oqs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -290,7 +290,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions); WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
@ -314,11 +314,11 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions); WINDOWS</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -327,7 +327,7 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;oqs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4006 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -1,198 +1,3 @@
|
||||
diff --git a/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.c b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.c
|
||||
new file mode 100644
|
||||
index 0000000..5e750c3
|
||||
--- /dev/null
|
||||
+++ b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.c
|
||||
@@ -0,0 +1,159 @@
|
||||
+#if defined(WINDOWS)
|
||||
+#define UNUSED
|
||||
+// __attribute__ not supported in VS, is there something else I should define?
|
||||
+#else
|
||||
+#define UNUSED __attribute__((unused))
|
||||
+#endif
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#if !defined(WINDOWS)
|
||||
+#include <strings.h>
|
||||
+#include <unistd.h>
|
||||
+#endif
|
||||
+
|
||||
+#include <oqs/kex.h>
|
||||
+#include <oqs/rand.h>
|
||||
+
|
||||
+#include "kex_rlwe_newhope_avx2.h"
|
||||
+#include "newhope.c"
|
||||
+#include "params.h"
|
||||
+
|
||||
+OQS_KEX *OQS_KEX_rlwe_newhope_avx2_new(OQS_RAND *rand) {
|
||||
+ OQS_KEX *k = malloc(sizeof(OQS_KEX));
|
||||
+ if (k == NULL) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ k->method_name = strdup("RLWE NewHope AVX2");
|
||||
+ k->estimated_classical_security = 229; // http://eprint.iacr.org/2015/1092.pdf Table 1 NewHope dual known classical
|
||||
+ k->estimated_quantum_security = 206; // http://eprint.iacr.org/2015/1092.pdf Table 1 NewHope dual known quantum
|
||||
+ k->seed = NULL;
|
||||
+ k->seed_len = 0;
|
||||
+ k->named_parameters = 0;
|
||||
+ k->rand = rand;
|
||||
+ k->params = NULL;
|
||||
+ k->alice_0 = &OQS_KEX_rlwe_newhope_avx2_alice_0;
|
||||
+ k->bob = &OQS_KEX_rlwe_newhope_avx2_bob;
|
||||
+ k->alice_1 = &OQS_KEX_rlwe_newhope_avx2_alice_1;
|
||||
+ k->alice_priv_free = &OQS_KEX_rlwe_newhope_avx2_alice_priv_free;
|
||||
+ k->free = &OQS_KEX_rlwe_newhope_avx2_free;
|
||||
+ return k;
|
||||
+}
|
||||
+
|
||||
+int OQS_KEX_rlwe_newhope_avx2_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
+
|
||||
+ int ret;
|
||||
+
|
||||
+ /* allocate public/private key pair */
|
||||
+ *alice_msg = malloc(NEWHOPE_SENDABYTES);
|
||||
+ if (*alice_msg == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+ *alice_priv = malloc(sizeof(poly));
|
||||
+ if (*alice_priv == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* generate public/private key pair */
|
||||
+ newhope_keygen(*alice_msg, (poly *) (*alice_priv));
|
||||
+ *alice_msg_len = NEWHOPE_SENDABYTES;
|
||||
+
|
||||
+ ret = 1;
|
||||
+ goto cleanup;
|
||||
+
|
||||
+err:
|
||||
+ ret = 0;
|
||||
+ free(*alice_msg);
|
||||
+ *alice_msg = NULL;
|
||||
+ free(*alice_priv);
|
||||
+ *alice_priv = NULL;
|
||||
+
|
||||
+cleanup:
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+int OQS_KEX_rlwe_newhope_avx2_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
+
|
||||
+ int ret;
|
||||
+
|
||||
+ if (alice_msg_len != NEWHOPE_SENDABYTES) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* allocate message and session key */
|
||||
+ *bob_msg = malloc(NEWHOPE_SENDBBYTES);
|
||||
+ if (*bob_msg == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+ *key = malloc(32);
|
||||
+ if (*key == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* generate Bob's response */
|
||||
+ newhope_sharedb(*key, *bob_msg, alice_msg);
|
||||
+ *bob_msg_len = NEWHOPE_SENDBBYTES;
|
||||
+ *key_len = 32;
|
||||
+
|
||||
+ ret = 1;
|
||||
+ goto cleanup;
|
||||
+
|
||||
+err:
|
||||
+ ret = 0;
|
||||
+ free(*bob_msg);
|
||||
+ *bob_msg = NULL;
|
||||
+ free(*key);
|
||||
+ *key = NULL;
|
||||
+
|
||||
+cleanup:
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+int OQS_KEX_rlwe_newhope_avx2_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
+
|
||||
+ int ret;
|
||||
+
|
||||
+ if (bob_msg_len != NEWHOPE_SENDBBYTES) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* allocate session key */
|
||||
+ *key = malloc(32);
|
||||
+ if (*key == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* generate Alice's session key */
|
||||
+ newhope_shareda(*key, (poly *) alice_priv, bob_msg);
|
||||
+ *key_len = 32;
|
||||
+
|
||||
+ ret = 1;
|
||||
+ goto cleanup;
|
||||
+
|
||||
+err:
|
||||
+ ret = 0;
|
||||
+ free(*key);
|
||||
+ *key = NULL;
|
||||
+
|
||||
+cleanup:
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void OQS_KEX_rlwe_newhope_avx2_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
|
||||
+ if (alice_priv) {
|
||||
+ free(alice_priv);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void OQS_KEX_rlwe_newhope_avx2_free(OQS_KEX *k) {
|
||||
+ if (k) {
|
||||
+ free(k->named_parameters);
|
||||
+ k->named_parameters = NULL;
|
||||
+ free(k->method_name);
|
||||
+ k->method_name = NULL;
|
||||
+ }
|
||||
+ free(k);
|
||||
+}
|
||||
diff --git a/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.h b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.h
|
||||
new file mode 100644
|
||||
index 0000000..6ab8921
|
||||
--- /dev/null
|
||||
+++ b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.h
|
||||
@@ -0,0 +1,24 @@
|
||||
+/**
|
||||
+ * \file kex_rlwe_newhope.h
|
||||
+ * \brief Header for ring-LWE key exchange protocol NewHope
|
||||
+ */
|
||||
+
|
||||
+#ifndef __OQS_KEX_RLWE_NEWHOPE_AVX2_H
|
||||
+#define __OQS_KEX_RLWE_NEWHOPE_AVX2_H
|
||||
+
|
||||
+#include <stddef.h>
|
||||
+#include <stdint.h>
|
||||
+
|
||||
+#include <oqs/kex.h>
|
||||
+#include <oqs/rand.h>
|
||||
+
|
||||
+OQS_KEX *OQS_KEX_rlwe_newhope_avx2_new(OQS_RAND *rand);
|
||||
+
|
||||
+int OQS_KEX_rlwe_newhope_avx2_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
+int OQS_KEX_rlwe_newhope_avx2_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
+int OQS_KEX_rlwe_newhope_avx2_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
+
|
||||
+void OQS_KEX_rlwe_newhope_avx2_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
+void OQS_KEX_rlwe_newhope_avx2_free(OQS_KEX *k);
|
||||
+
|
||||
+#endif
|
||||
diff --git a/src/kex_rlwe_newhope/avx2/bitrev.s b/src/kex_rlwe_newhope/avx2/bitrev.s
|
||||
index 002a1ee..faff35f 100644
|
||||
--- a/src/kex_rlwe_newhope/avx2/bitrev.s
|
||||
@ -777,6 +582,203 @@ index beb93fe..7eac399 100644
|
||||
mov %rsp,%r11
|
||||
and $31,%r11
|
||||
add $0,%r11
|
||||
diff --git a/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.c b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.c
|
||||
new file mode 100644
|
||||
index 0000000..c30a95e
|
||||
--- /dev/null
|
||||
+++ b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.c
|
||||
@@ -0,0 +1,160 @@
|
||||
+#if defined(WINDOWS)
|
||||
+#define UNUSED
|
||||
+// __attribute__ not supported in VS, is there something else I should define?
|
||||
+#else
|
||||
+#define UNUSED __attribute__((unused))
|
||||
+#endif
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#if !defined(WINDOWS)
|
||||
+#include <strings.h>
|
||||
+#include <unistd.h>
|
||||
+#endif
|
||||
+
|
||||
+#include <oqs/common.h>
|
||||
+#include <oqs/kex.h>
|
||||
+#include <oqs/rand.h>
|
||||
+
|
||||
+#include "kex_rlwe_newhope_avx2.h"
|
||||
+#include "newhope.c"
|
||||
+#include "params.h"
|
||||
+
|
||||
+OQS_KEX *OQS_KEX_rlwe_newhope_avx2_new(OQS_RAND *rand) {
|
||||
+ OQS_KEX *k = malloc(sizeof(OQS_KEX));
|
||||
+ if (k == NULL) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ k->method_name = strdup("RLWE NewHope AVX2");
|
||||
+ k->estimated_classical_security = 229; // http://eprint.iacr.org/2015/1092.pdf Table 1 NewHope dual known classical
|
||||
+ k->estimated_quantum_security = 206; // http://eprint.iacr.org/2015/1092.pdf Table 1 NewHope dual known quantum
|
||||
+ k->seed = NULL;
|
||||
+ k->seed_len = 0;
|
||||
+ k->named_parameters = 0;
|
||||
+ k->rand = rand;
|
||||
+ k->params = NULL;
|
||||
+ k->alice_0 = &OQS_KEX_rlwe_newhope_avx2_alice_0;
|
||||
+ k->bob = &OQS_KEX_rlwe_newhope_avx2_bob;
|
||||
+ k->alice_1 = &OQS_KEX_rlwe_newhope_avx2_alice_1;
|
||||
+ k->alice_priv_free = &OQS_KEX_rlwe_newhope_avx2_alice_priv_free;
|
||||
+ k->free = &OQS_KEX_rlwe_newhope_avx2_free;
|
||||
+ return k;
|
||||
+}
|
||||
+
|
||||
+OQS_STATUS OQS_KEX_rlwe_newhope_avx2_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
+
|
||||
+ OQS_STATUS ret;
|
||||
+
|
||||
+ /* allocate public/private key pair */
|
||||
+ *alice_msg = malloc(NEWHOPE_SENDABYTES);
|
||||
+ if (*alice_msg == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+ *alice_priv = malloc(sizeof(poly));
|
||||
+ if (*alice_priv == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* generate public/private key pair */
|
||||
+ newhope_keygen(*alice_msg, (poly *) (*alice_priv));
|
||||
+ *alice_msg_len = NEWHOPE_SENDABYTES;
|
||||
+
|
||||
+ ret = OQS_SUCCESS;
|
||||
+ goto cleanup;
|
||||
+
|
||||
+err:
|
||||
+ ret = OQS_ERROR;
|
||||
+ free(*alice_msg);
|
||||
+ *alice_msg = NULL;
|
||||
+ free(*alice_priv);
|
||||
+ *alice_priv = NULL;
|
||||
+
|
||||
+cleanup:
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+OQS_STATUS OQS_KEX_rlwe_newhope_avx2_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
+
|
||||
+ OQS_STATUS ret;
|
||||
+
|
||||
+ if (alice_msg_len != NEWHOPE_SENDABYTES) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* allocate message and session key */
|
||||
+ *bob_msg = malloc(NEWHOPE_SENDBBYTES);
|
||||
+ if (*bob_msg == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+ *key = malloc(32);
|
||||
+ if (*key == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* generate Bob's response */
|
||||
+ newhope_sharedb(*key, *bob_msg, alice_msg);
|
||||
+ *bob_msg_len = NEWHOPE_SENDBBYTES;
|
||||
+ *key_len = 32;
|
||||
+
|
||||
+ ret = OQS_SUCCESS;
|
||||
+ goto cleanup;
|
||||
+
|
||||
+err:
|
||||
+ ret = OQS_ERROR;
|
||||
+ free(*bob_msg);
|
||||
+ *bob_msg = NULL;
|
||||
+ free(*key);
|
||||
+ *key = NULL;
|
||||
+
|
||||
+cleanup:
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+OQS_STATUS OQS_KEX_rlwe_newhope_avx2_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
+
|
||||
+ OQS_STATUS ret;
|
||||
+
|
||||
+ if (bob_msg_len != NEWHOPE_SENDBBYTES) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* allocate session key */
|
||||
+ *key = malloc(32);
|
||||
+ if (*key == NULL) {
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* generate Alice's session key */
|
||||
+ newhope_shareda(*key, (poly *) alice_priv, bob_msg);
|
||||
+ *key_len = 32;
|
||||
+
|
||||
+ ret = OQS_SUCCESS;
|
||||
+ goto cleanup;
|
||||
+
|
||||
+err:
|
||||
+ ret = OQS_ERROR;
|
||||
+ free(*key);
|
||||
+ *key = NULL;
|
||||
+
|
||||
+cleanup:
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void OQS_KEX_rlwe_newhope_avx2_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
|
||||
+ if (alice_priv) {
|
||||
+ free(alice_priv);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void OQS_KEX_rlwe_newhope_avx2_free(OQS_KEX *k) {
|
||||
+ if (k) {
|
||||
+ free(k->named_parameters);
|
||||
+ k->named_parameters = NULL;
|
||||
+ free(k->method_name);
|
||||
+ k->method_name = NULL;
|
||||
+ }
|
||||
+ free(k);
|
||||
+}
|
||||
diff --git a/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.h b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.h
|
||||
new file mode 100644
|
||||
index 0000000..5f40fc2
|
||||
--- /dev/null
|
||||
+++ b/src/kex_rlwe_newhope/avx2/kex_rlwe_newhope_avx2.h
|
||||
@@ -0,0 +1,25 @@
|
||||
+/**
|
||||
+ * \file kex_rlwe_newhope.h
|
||||
+ * \brief Header for ring-LWE key exchange protocol NewHope
|
||||
+ */
|
||||
+
|
||||
+#ifndef __OQS_KEX_RLWE_NEWHOPE_AVX2_H
|
||||
+#define __OQS_KEX_RLWE_NEWHOPE_AVX2_H
|
||||
+
|
||||
+#include <stddef.h>
|
||||
+#include <stdint.h>
|
||||
+
|
||||
+#include <oqs/common.h>
|
||||
+#include <oqs/kex.h>
|
||||
+#include <oqs/rand.h>
|
||||
+
|
||||
+OQS_KEX *OQS_KEX_rlwe_newhope_avx2_new(OQS_RAND *rand);
|
||||
+
|
||||
+OQS_STATUS OQS_KEX_rlwe_newhope_avx2_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
+OQS_STATUS OQS_KEX_rlwe_newhope_avx2_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
+OQS_STATUS OQS_KEX_rlwe_newhope_avx2_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
+
|
||||
+void OQS_KEX_rlwe_newhope_avx2_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
+void OQS_KEX_rlwe_newhope_avx2_free(OQS_KEX *k);
|
||||
+
|
||||
+#endif
|
||||
diff --git a/src/kex_rlwe_newhope/avx2/newhope.c b/src/kex_rlwe_newhope/avx2/newhope.c
|
||||
index b9f7a6c..f0c5ad9 100644
|
||||
--- a/src/kex_rlwe_newhope/avx2/newhope.c
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <oqs/common.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(WINDOWS)
|
||||
@ -26,3 +28,25 @@ void OQS_MEM_secure_free(void *ptr, size_t len) {
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void OQS_print_hex_string(const char *label, uint8_t *str, size_t len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
for (size_t i = 0; i < (len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Partially displays hexadecimal strings */
|
||||
void OQS_print_part_hex_string(const char *label, uint8_t *str, size_t len, size_t sub_len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
for (size_t i = 0; i < (sub_len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[i]);
|
||||
}
|
||||
printf("...");
|
||||
for (size_t i = 0; i < (sub_len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[len - sub_len + i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -1,10 +1,18 @@
|
||||
#ifndef __OQS_COMMON_H
|
||||
#define __OQS_COMMON_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define OQS_SUCCESS 1
|
||||
#define OQS_ERROR 0
|
||||
typedef int OQS_STATUS;
|
||||
#define OQS_SUCCESS 0
|
||||
#define OQS_ERROR -1
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void OQS_print_hex_string(const char *label, uint8_t *str, size_t len);
|
||||
|
||||
/* Partially displays hexadecimal strings */
|
||||
void OQS_print_part_hex_string(const char *label, uint8_t *str, size_t len, size_t sub_len);
|
||||
|
||||
void OQS_MEM_cleanse(void *ptr, size_t len);
|
||||
void OQS_MEM_secure_free(void *ptr, size_t len);
|
||||
|
15
src/common/oqs.h
Normal file
15
src/common/oqs.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef __OQS_H
|
||||
#define __OQS_H
|
||||
|
||||
#include <oqs/aes.h>
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/sha3.h>
|
||||
#include <oqs/sig.h>
|
||||
|
||||
#if !defined(WINDOWS)
|
||||
#include <oqs/config.h>
|
||||
#endif
|
||||
|
||||
#endif
|
@ -3,10 +3,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "../../ds_benchmark.h"
|
||||
#include "../../common/common.h"
|
||||
#include "aes.h"
|
||||
#include "aes_local.h"
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/rand_urandom_aesctr.h>
|
||||
#include <oqs/rand_urandom_chacha20.h>
|
||||
@ -143,8 +144,8 @@ void OQS_RAND_report_statistics(const unsigned long occurrences[256], const char
|
||||
return;
|
||||
}
|
||||
|
||||
int OQS_RAND_get_system_entropy(uint8_t *buf, size_t n) {
|
||||
int result = 0;
|
||||
OQS_STATUS OQS_RAND_get_system_entropy(uint8_t *buf, size_t n) {
|
||||
OQS_STATUS result = OQS_ERROR;
|
||||
|
||||
#if !defined(WINDOWS)
|
||||
int fd = 0;
|
||||
@ -170,7 +171,7 @@ int OQS_RAND_get_system_entropy(uint8_t *buf, size_t n) {
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
result = 1;
|
||||
result = OQS_SUCCESS;
|
||||
|
||||
err:
|
||||
#if !defined(WINDOWS)
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
|
||||
enum OQS_RAND_alg_name {
|
||||
OQS_RAND_alg_default,
|
||||
OQS_RAND_alg_urandom_chacha20,
|
||||
@ -94,5 +96,5 @@ double OQS_RAND_test_statistical_distance_from_uniform(const unsigned long occur
|
||||
double OQS_RAND_zscore_deviation_from_uniform(const unsigned long occurrences[256]);
|
||||
void OQS_RAND_report_statistics(const unsigned long occurrences[256], const char *indent);
|
||||
|
||||
int OQS_RAND_get_system_entropy(uint8_t *buf, size_t n);
|
||||
OQS_STATUS OQS_RAND_get_system_entropy(uint8_t *buf, size_t n);
|
||||
#endif
|
||||
|
@ -5,9 +5,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <oqs/rand.h>
|
||||
|
||||
#include "../../common/common.h"
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
struct rand_testcase {
|
||||
enum OQS_RAND_alg_name alg_name;
|
||||
@ -53,34 +51,24 @@ static void rand_test_distribution_64(OQS_RAND *rand, unsigned long occurrences[
|
||||
}
|
||||
}
|
||||
|
||||
static int rand_test_distribution_n(OQS_RAND *rand, unsigned long occurrences[256], int len) {
|
||||
static OQS_STATUS rand_test_distribution_n(OQS_RAND *rand, unsigned long occurrences[256], int len) {
|
||||
uint8_t *x = malloc(len);
|
||||
if (x == NULL) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
}
|
||||
OQS_RAND_n(rand, x, len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
OQS_RAND_test_record_occurrence(x[i], occurrences);
|
||||
}
|
||||
free(x);
|
||||
return 1;
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
#define PRINT_HEX_STRING(label, str, len) \
|
||||
{ \
|
||||
printf("%-20s (%4zu bytes): ", (label), (size_t)(len)); \
|
||||
for (size_t i = 0; i < (len); i++) { \
|
||||
printf("%02X", ((unsigned char *) (str))[i]); \
|
||||
} \
|
||||
printf("\n"); \
|
||||
}
|
||||
|
||||
static int rand_test_distribution_wrapper(enum OQS_RAND_alg_name alg_name, int iterations, bool quiet) {
|
||||
static OQS_STATUS rand_test_distribution_wrapper(enum OQS_RAND_alg_name alg_name, int iterations, bool quiet) {
|
||||
|
||||
OQS_RAND *rand = OQS_RAND_new(alg_name);
|
||||
if (rand == NULL) {
|
||||
eprintf("rand is NULL\n");
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
}
|
||||
|
||||
if (!quiet) {
|
||||
@ -90,25 +78,25 @@ static int rand_test_distribution_wrapper(enum OQS_RAND_alg_name alg_name, int i
|
||||
|
||||
uint8_t x[256];
|
||||
OQS_RAND_n(rand, x, 256);
|
||||
PRINT_HEX_STRING("OQS_RAND_n, n = 256", x, 256)
|
||||
OQS_print_hex_string("OQS_RAND_n, n = 256", x, 256);
|
||||
|
||||
uint8_t y8 = OQS_RAND_8(rand);
|
||||
PRINT_HEX_STRING("OQS_RAND_8", (uint8_t *) &y8, sizeof(y8));
|
||||
OQS_print_hex_string("OQS_RAND_8", (uint8_t *) &y8, sizeof(y8));
|
||||
y8 = OQS_RAND_8(rand);
|
||||
PRINT_HEX_STRING("OQS_RAND_8", (uint8_t *) &y8, sizeof(y8));
|
||||
OQS_print_hex_string("OQS_RAND_8", (uint8_t *) &y8, sizeof(y8));
|
||||
|
||||
uint32_t y32 = OQS_RAND_32(rand);
|
||||
PRINT_HEX_STRING("OQS_RAND_32", (uint8_t *) &y32, sizeof(y32));
|
||||
OQS_print_hex_string("OQS_RAND_32", (uint8_t *) &y32, sizeof(y32));
|
||||
y32 = OQS_RAND_32(rand);
|
||||
PRINT_HEX_STRING("OQS_RAND_32", (uint8_t *) &y32, sizeof(y32));
|
||||
OQS_print_hex_string("OQS_RAND_32", (uint8_t *) &y32, sizeof(y32));
|
||||
|
||||
uint64_t y64 = OQS_RAND_64(rand);
|
||||
PRINT_HEX_STRING("OQS_RAND_64", (uint8_t *) &y64, sizeof(y64));
|
||||
OQS_print_hex_string("OQS_RAND_64", (uint8_t *) &y64, sizeof(y64));
|
||||
y64 = OQS_RAND_64(rand);
|
||||
PRINT_HEX_STRING("OQS_RAND_64", (uint8_t *) &y64, sizeof(y64));
|
||||
OQS_print_hex_string("OQS_RAND_64", (uint8_t *) &y64, sizeof(y64));
|
||||
|
||||
OQS_RAND_n(rand, x, 256);
|
||||
PRINT_HEX_STRING("OQS_RAND_n, n = 256", x, 256)
|
||||
OQS_print_hex_string("OQS_RAND_n, n = 256", x, 256);
|
||||
}
|
||||
|
||||
printf("================================================================================\n");
|
||||
@ -150,12 +138,12 @@ static int rand_test_distribution_wrapper(enum OQS_RAND_alg_name alg_name, int i
|
||||
|
||||
OQS_RAND_free(rand);
|
||||
|
||||
return 1;
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int success;
|
||||
OQS_STATUS success;
|
||||
bool quiet = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
@ -179,19 +167,19 @@ int main(int argc, char **argv) {
|
||||
size_t rand_testcases_len = sizeof(rand_testcases) / sizeof(struct rand_testcase);
|
||||
for (size_t i = 0; i < rand_testcases_len; i++) {
|
||||
success = rand_test_distribution_wrapper(rand_testcases[i].alg_name, RAND_TEST_ITERATIONS, quiet);
|
||||
if (success != 1) {
|
||||
if (success != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
success = 1;
|
||||
success = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
success = 0;
|
||||
success = OQS_ERROR;
|
||||
eprintf("ERROR!\n");
|
||||
|
||||
cleanup:
|
||||
|
||||
return (success == 1) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
return (success == OQS_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <oqs/aes.h>
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/rand_urandom_aesctr.h>
|
||||
|
||||
@ -35,7 +36,7 @@ static oqs_rand_urandom_aesctr_ctx *oqs_rand_urandom_aesctr_ctx_new() {
|
||||
goto err;
|
||||
}
|
||||
uint8_t key[16];
|
||||
if (!OQS_RAND_get_system_entropy(key, 16)) {
|
||||
if (OQS_RAND_get_system_entropy(key, 16) != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
OQS_AES128_load_schedule(key, &rand_ctx->schedule, 1);
|
||||
|
@ -64,7 +64,7 @@ static OQS_RAND_urandom_chacha20_ctx *OQS_RAND_urandom_chacha20_ctx_new() {
|
||||
if (rand_ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (!OQS_RAND_get_system_entropy(rand_ctx->key, 32)) {
|
||||
if (OQS_RAND_get_system_entropy(rand_ctx->key, 32) != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
memset(rand_ctx->nonce, 0, 8);
|
||||
|
@ -20,18 +20,18 @@
|
||||
#include <oqs/kex_rlwe_newhope_avx2.h>
|
||||
#endif
|
||||
|
||||
#define UNUSED(expr) \
|
||||
do { \
|
||||
(void) (expr); \
|
||||
#define UNUSED_KEX(expr) \
|
||||
do { \
|
||||
(void) (expr); \
|
||||
} while (0)
|
||||
|
||||
OQS_KEX *OQS_KEX_new(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters) {
|
||||
|
||||
//To disable warnings when the function arguments are not being used depending
|
||||
//on which algorithm has been disabled
|
||||
UNUSED(seed);
|
||||
UNUSED(seed_len);
|
||||
UNUSED(named_parameters);
|
||||
UNUSED_KEX(seed);
|
||||
UNUSED_KEX(seed_len);
|
||||
UNUSED_KEX(named_parameters);
|
||||
|
||||
switch (alg_name) {
|
||||
case OQS_KEX_alg_default:
|
||||
@ -101,25 +101,25 @@ OQS_KEX *OQS_KEX_new(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8
|
||||
}
|
||||
}
|
||||
|
||||
int OQS_KEX_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
if (k == NULL) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
} else {
|
||||
return k->alice_0(k, alice_priv, alice_msg, alice_msg_len);
|
||||
}
|
||||
}
|
||||
|
||||
int OQS_KEX_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
if (k == NULL) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
} else {
|
||||
return k->bob(k, alice_msg, alice_msg_len, bob_msg, bob_msg_len, key, key_len);
|
||||
}
|
||||
}
|
||||
|
||||
int OQS_KEX_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
if (k == NULL) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
} else {
|
||||
return k->alice_1(k, alice_priv, bob_msg, bob_msg_len, key, key_len);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
#if !defined(WINDOWS)
|
||||
@ -92,9 +93,10 @@ typedef struct OQS_KEX {
|
||||
* @param alice_priv Alice's private key
|
||||
* @param alice_msg Alice's message (public key + optional additional data)
|
||||
* @param alice_msg_len Alice's message length
|
||||
* @return 1 on success, or 0 on failure
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure
|
||||
*/
|
||||
int (*alice_0)(OQS_KEX *k, void **alive_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS(*alice_0)
|
||||
(OQS_KEX *k, void **alive_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
|
||||
/**
|
||||
* Pointer to a function for shared key generation by Bob.
|
||||
@ -106,9 +108,10 @@ typedef struct OQS_KEX {
|
||||
* @param bob_msg_len Bob's message length
|
||||
* @param key Shared key
|
||||
* @param key_len Shared key length
|
||||
* @return 1 on success, or 0 on failure
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure
|
||||
*/
|
||||
int (*bob)(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS(*bob)
|
||||
(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
/**
|
||||
* Pointer to a function for shared key generation by Alice.
|
||||
@ -119,9 +122,10 @@ typedef struct OQS_KEX {
|
||||
* @param bob_msg_len Bob's message length
|
||||
* @param key Shared key
|
||||
* @param key_len Shared key length
|
||||
* @return 1 on success, or 0 on failure
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure
|
||||
*/
|
||||
int (*alice_1)(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS(*alice_1)
|
||||
(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
/**
|
||||
* Pointer to a function for freeing Alice's private key
|
||||
@ -154,9 +158,9 @@ typedef struct OQS_KEX {
|
||||
*/
|
||||
OQS_KEX *OQS_KEX_new(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters);
|
||||
|
||||
int OQS_KEX_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_free(OQS_KEX *k);
|
||||
|
@ -9,16 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void disp_hex_string(const char *label, uint8_t *str, size_t len);
|
||||
|
||||
/* Partially displays hexadecimal strings */
|
||||
void disp_part_hex_string(const char *label, uint8_t *str, size_t len,
|
||||
size_t sub_len);
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
/* Cleaning up memory etc */
|
||||
void cleanup(uint8_t *alice_msg, size_t alice_msg_len, uint8_t *alice_key,
|
||||
@ -83,7 +74,7 @@ int main(void) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
disp_part_hex_string("Alice message", alice_msg, alice_msg_len, 20);
|
||||
OQS_print_part_hex_string("Alice message", alice_msg, alice_msg_len, 20);
|
||||
|
||||
/* Bob's response */
|
||||
success = OQS_KEX_bob(kex, alice_msg, alice_msg_len, &bob_msg, &bob_msg_len,
|
||||
@ -96,8 +87,8 @@ int main(void) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
disp_part_hex_string("Bob message", bob_msg, bob_msg_len, 20);
|
||||
disp_hex_string("Bob session key", bob_key, bob_key_len);
|
||||
OQS_print_part_hex_string("Bob message", bob_msg, bob_msg_len, 20);
|
||||
OQS_print_hex_string("Bob session key", bob_key, bob_key_len);
|
||||
|
||||
/* Alice processes Bob's response */
|
||||
success = OQS_KEX_alice_1(kex, alice_priv, bob_msg, bob_msg_len, &alice_key,
|
||||
@ -110,7 +101,7 @@ int main(void) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
disp_hex_string("Alice session key", alice_key, alice_key_len);
|
||||
OQS_print_hex_string("Alice session key", alice_key, alice_key_len);
|
||||
|
||||
/* Compare key lengths */
|
||||
if (alice_key_len != bob_key_len) {
|
||||
@ -128,8 +119,8 @@ int main(void) {
|
||||
if (success != 0) {
|
||||
eprintf("ERROR: Alice's session key and Bob's session "
|
||||
"key are not equal!\n");
|
||||
disp_hex_string("Alice session key", alice_key, alice_key_len);
|
||||
disp_hex_string("Bob session key", bob_key, bob_key_len);
|
||||
OQS_print_hex_string("Alice session key", alice_key, alice_key_len);
|
||||
OQS_print_hex_string("Bob session key", bob_key, bob_key_len);
|
||||
cleanup(alice_msg, alice_msg_len, alice_key, alice_key_len, bob_msg,
|
||||
bob_msg_len, bob_key, bob_key_len, alice_priv, kex, rnd);
|
||||
|
||||
@ -144,27 +135,6 @@ int main(void) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void disp_hex_string(const char *label, uint8_t *str, size_t len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
for (size_t i = 0; i < (len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void disp_part_hex_string(const char *label, uint8_t *str, size_t len,
|
||||
size_t sub_len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
for (size_t i = 0; i < (sub_len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[i]);
|
||||
}
|
||||
printf("...");
|
||||
for (size_t i = 0; i < (sub_len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[len - sub_len + i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void cleanup(uint8_t *alice_msg, size_t alice_msg_len, uint8_t *alice_key,
|
||||
size_t alice_key_len, uint8_t *bob_msg, size_t bob_msg_len,
|
||||
uint8_t *bob_key, size_t bob_key_len, void *alice_priv,
|
||||
|
@ -7,11 +7,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "../ds_benchmark.h"
|
||||
#include "../common/common.h"
|
||||
|
||||
struct kex_testcase {
|
||||
enum OQS_KEX_alg_name alg_name;
|
||||
@ -61,19 +59,10 @@ struct kex_testcase kex_testcases[] = {
|
||||
#define KEX_TEST_ITERATIONS 100
|
||||
#define KEX_BENCH_SECONDS_DEFAULT 1
|
||||
|
||||
#define PRINT_HEX_STRING(label, str, len) \
|
||||
{ \
|
||||
printf("%-20s (%4zu bytes): ", (label), (size_t)(len)); \
|
||||
for (size_t i = 0; i < (len); i++) { \
|
||||
printf("%02X", ((unsigned char *) (str))[i]); \
|
||||
} \
|
||||
printf("\n"); \
|
||||
}
|
||||
|
||||
static int kex_test_correctness(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters, const int print, unsigned long occurrences[256]) {
|
||||
static OQS_STATUS kex_test_correctness(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters, const int print, unsigned long occurrences[256]) {
|
||||
|
||||
OQS_KEX *kex = NULL;
|
||||
int rc;
|
||||
OQS_STATUS rc;
|
||||
|
||||
void *alice_priv = NULL;
|
||||
uint8_t *alice_msg = NULL;
|
||||
@ -101,36 +90,36 @@ static int kex_test_correctness(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name,
|
||||
|
||||
/* Alice's initial message */
|
||||
rc = OQS_KEX_alice_0(kex, &alice_priv, &alice_msg, &alice_msg_len);
|
||||
if (rc != 1) {
|
||||
if (rc != OQS_SUCCESS) {
|
||||
eprintf("OQS_KEX_alice_0 failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (print) {
|
||||
PRINT_HEX_STRING("Alice message", alice_msg, alice_msg_len)
|
||||
OQS_print_part_hex_string("Alice message", alice_msg, alice_msg_len, 20);
|
||||
}
|
||||
|
||||
/* Bob's response */
|
||||
rc = OQS_KEX_bob(kex, alice_msg, alice_msg_len, &bob_msg, &bob_msg_len, &bob_key, &bob_key_len);
|
||||
if (rc != 1) {
|
||||
if (rc != OQS_SUCCESS) {
|
||||
eprintf("OQS_KEX_bob failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (print) {
|
||||
PRINT_HEX_STRING("Bob message", bob_msg, bob_msg_len)
|
||||
PRINT_HEX_STRING("Bob session key", bob_key, bob_key_len)
|
||||
OQS_print_part_hex_string("Bob message", bob_msg, bob_msg_len, 20);
|
||||
OQS_print_hex_string("Bob session key", bob_key, bob_key_len);
|
||||
}
|
||||
|
||||
/* Alice processes Bob's response */
|
||||
rc = OQS_KEX_alice_1(kex, alice_priv, bob_msg, bob_msg_len, &alice_key, &alice_key_len);
|
||||
if (rc != 1) {
|
||||
if (rc != OQS_SUCCESS) {
|
||||
eprintf("OQS_KEX_alice_1 failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (print) {
|
||||
PRINT_HEX_STRING("Alice session key", alice_key, alice_key_len)
|
||||
OQS_print_hex_string("Alice session key", alice_key, alice_key_len);
|
||||
}
|
||||
|
||||
/* compare session key lengths and values */
|
||||
@ -138,11 +127,10 @@ static int kex_test_correctness(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name,
|
||||
eprintf("ERROR: Alice's session key and Bob's session key are different lengths (%zu vs %zu)\n", alice_key_len, bob_key_len);
|
||||
goto err;
|
||||
}
|
||||
rc = memcmp(alice_key, bob_key, alice_key_len);
|
||||
if (rc != 0) {
|
||||
if (memcmp(alice_key, bob_key, alice_key_len) != 0) {
|
||||
eprintf("ERROR: Alice's session key and Bob's session key are not equal\n");
|
||||
PRINT_HEX_STRING("Alice session key", alice_key, alice_key_len)
|
||||
PRINT_HEX_STRING("Bob session key", bob_key, bob_key_len)
|
||||
OQS_print_hex_string("Alice session key", alice_key, alice_key_len);
|
||||
OQS_print_hex_string("Bob session key", bob_key, bob_key_len);
|
||||
goto err;
|
||||
}
|
||||
if (print) {
|
||||
@ -155,11 +143,11 @@ static int kex_test_correctness(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name,
|
||||
OQS_RAND_test_record_occurrence(alice_key[i], occurrences);
|
||||
}
|
||||
|
||||
rc = 1;
|
||||
rc = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
rc = 0;
|
||||
rc = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
free(alice_msg);
|
||||
@ -172,9 +160,9 @@ cleanup:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int kex_test_correctness_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters, int iterations, bool quiet) {
|
||||
static OQS_STATUS kex_test_correctness_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters, int iterations, bool quiet) {
|
||||
OQS_KEX *kex = NULL;
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
unsigned long occurrences[256];
|
||||
for (int i = 0; i < 256; i++) {
|
||||
@ -183,7 +171,7 @@ static int kex_test_correctness_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name al
|
||||
|
||||
ret = kex_test_correctness(rand, alg_name, seed, seed_len, named_parameters, quiet ? 0 : 1, occurrences);
|
||||
|
||||
if (ret != 1) {
|
||||
if (ret != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -199,7 +187,7 @@ static int kex_test_correctness_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name al
|
||||
printf("================================================================================\n");
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
ret = kex_test_correctness(rand, alg_name, seed, seed_len, named_parameters, 0, occurrences);
|
||||
if (ret != 1) {
|
||||
if (ret != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -207,11 +195,11 @@ static int kex_test_correctness_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name al
|
||||
OQS_RAND_report_statistics(occurrences, "");
|
||||
printf("\n\n");
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
OQS_KEX_free(kex);
|
||||
@ -229,10 +217,10 @@ static void cleanup_bob(uint8_t *bob_msg, uint8_t *bob_key) {
|
||||
free(bob_key);
|
||||
}
|
||||
|
||||
static int kex_bench_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters, const size_t seconds) {
|
||||
static OQS_STATUS kex_bench_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters, const size_t seconds) {
|
||||
|
||||
OQS_KEX *kex = NULL;
|
||||
int rc;
|
||||
OQS_STATUS rc;
|
||||
|
||||
void *alice_priv = NULL;
|
||||
uint8_t *alice_msg = NULL;
|
||||
@ -264,11 +252,11 @@ static int kex_bench_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, con
|
||||
|
||||
printf("Communication (bytes): A->B: %zu, B->A: %zu, total: %zu; classical/quantum security bits [%u:%u] \n", alice_msg_len, bob_msg_len, alice_msg_len + bob_msg_len, kex->estimated_classical_security, kex->estimated_quantum_security);
|
||||
|
||||
rc = 1;
|
||||
rc = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
rc = 0;
|
||||
rc = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
free(alice_msg);
|
||||
@ -281,10 +269,10 @@ cleanup:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int kex_mem_bench_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters) {
|
||||
static OQS_STATUS kex_mem_bench_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8_t *seed, const size_t seed_len, const char *named_parameters) {
|
||||
|
||||
OQS_KEX *kex = NULL;
|
||||
int rc;
|
||||
OQS_STATUS rc;
|
||||
|
||||
void *alice_priv = NULL;
|
||||
uint8_t *alice_msg = NULL;
|
||||
@ -309,11 +297,11 @@ static int kex_mem_bench_wrapper(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name,
|
||||
OQS_KEX_bob(kex, alice_msg, alice_msg_len, &bob_msg, &bob_msg_len, &bob_key, &bob_key_len);
|
||||
OQS_KEX_alice_1(kex, alice_priv, bob_msg, bob_msg_len, &alice_key, &alice_key_len);
|
||||
|
||||
rc = 1;
|
||||
rc = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
rc = 0;
|
||||
rc = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
free(alice_msg);
|
||||
@ -346,7 +334,7 @@ void print_help() {
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int success = 1;
|
||||
OQS_STATUS success = OQS_SUCCESS;
|
||||
bool run_all = true;
|
||||
bool quiet = false;
|
||||
bool bench = false;
|
||||
@ -398,12 +386,12 @@ int main(int argc, char **argv) {
|
||||
if (run_all || kex_testcases[i].run == 1) {
|
||||
success = kex_mem_bench_wrapper(rand, kex_testcases[i].alg_name, kex_testcases[i].seed, kex_testcases[i].seed_len, kex_testcases[i].named_parameters);
|
||||
}
|
||||
if (success != 1) {
|
||||
if (success != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
printf("memory benchmarks done, exiting..\n");
|
||||
success = 1;
|
||||
success = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -412,7 +400,7 @@ int main(int argc, char **argv) {
|
||||
int num_iter = kex_testcases[i].iter;
|
||||
success = kex_test_correctness_wrapper(rand, kex_testcases[i].alg_name, kex_testcases[i].seed, kex_testcases[i].seed_len, kex_testcases[i].named_parameters, num_iter, quiet);
|
||||
}
|
||||
if (success != 1) {
|
||||
if (success != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -427,15 +415,15 @@ int main(int argc, char **argv) {
|
||||
PRINT_TIMER_FOOTER
|
||||
}
|
||||
|
||||
success = 1;
|
||||
success = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
success = 0;
|
||||
success = OQS_ERROR;
|
||||
eprintf("ERROR!\n");
|
||||
|
||||
cleanup:
|
||||
OQS_RAND_free(rand);
|
||||
|
||||
return (success == 1) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
return (success == OQS_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ OQS_KEX *OQS_KEX_code_mcbits_new(OQS_RAND *rand) {
|
||||
return k;
|
||||
}
|
||||
|
||||
int OQS_KEX_code_mcbits_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_code_mcbits_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*alice_priv = NULL;
|
||||
*alice_msg = NULL;
|
||||
@ -61,11 +61,11 @@ int OQS_KEX_code_mcbits_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **
|
||||
|
||||
oqs_kex_mcbits_gen_keypair(*alice_msg, *alice_priv, k->rand);
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*alice_msg);
|
||||
*alice_msg = NULL;
|
||||
free(*alice_priv);
|
||||
@ -76,9 +76,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_code_mcbits_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_code_mcbits_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*bob_msg = NULL;
|
||||
*key = NULL;
|
||||
@ -100,10 +100,10 @@ int OQS_KEX_code_mcbits_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const s
|
||||
oqs_kex_mcbits_encrypt(*bob_msg, bob_msg_len, *key, 32, alice_msg, k->rand);
|
||||
*key_len = 32;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
free(*key);
|
||||
@ -113,9 +113,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_code_mcbits_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_code_mcbits_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*key = NULL;
|
||||
|
||||
@ -130,11 +130,11 @@ int OQS_KEX_code_mcbits_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const
|
||||
}
|
||||
oqs_kex_mcbits_decrypt(*key, key_len, bob_msg, CRYPTO_BYTES + 32, alice_priv);
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*key);
|
||||
*key = NULL;
|
||||
|
||||
|
@ -9,14 +9,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_code_mcbits_new(OQS_RAND *rand);
|
||||
|
||||
int OQS_KEX_code_mcbits_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_code_mcbits_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_code_mcbits_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_code_mcbits_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_code_mcbits_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_code_mcbits_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_code_mcbits_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_code_mcbits_free(OQS_KEX *k);
|
||||
|
@ -9,14 +9,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_lwe_frodo_new_recommended(OQS_RAND *rand, const uint8_t *seed, const size_t seed_len, const char *named_parameters);
|
||||
|
||||
int OQS_KEX_lwe_frodo_alice_0_recommended(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_lwe_frodo_bob_recommended(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_lwe_frodo_alice_1_recommended(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_lwe_frodo_alice_0_recommended(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_lwe_frodo_bob_recommended(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_lwe_frodo_alice_1_recommended(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_lwe_frodo_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_lwe_frodo_free(OQS_KEX *k);
|
||||
|
@ -85,9 +85,9 @@ err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int MACRIFY(OQS_KEX_lwe_frodo_alice_0)(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS MACRIFY(OQS_KEX_lwe_frodo_alice_0)(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
struct oqs_kex_lwe_frodo_params *params = (struct oqs_kex_lwe_frodo_params *) k->params;
|
||||
|
||||
@ -118,7 +118,7 @@ int MACRIFY(OQS_KEX_lwe_frodo_alice_0)(OQS_KEX *k, void **alice_priv, uint8_t **
|
||||
|
||||
oqs_kex_lwe_frodo_pack(*alice_msg, PARAMS_REC_PUB_LENGTH, b, PARAMS_N * PARAMS_NBAR, PARAMS_LOG2Q);
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
@ -127,15 +127,15 @@ err:
|
||||
*alice_msg = NULL;
|
||||
free(*alice_priv);
|
||||
*alice_priv = NULL;
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MACRIFY(OQS_KEX_lwe_frodo_bob)(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS MACRIFY(OQS_KEX_lwe_frodo_bob)(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
struct oqs_kex_lwe_frodo_params *params = (struct oqs_kex_lwe_frodo_params *) k->params;
|
||||
|
||||
@ -196,11 +196,11 @@ int MACRIFY(OQS_KEX_lwe_frodo_bob)(OQS_KEX *k, const uint8_t *alice_msg, const s
|
||||
*bob_msg_len = PARAMS_REC_PUB_LENGTH + PARAMS_REC_HINT_LENGTH;
|
||||
*key_len = PARAMS_KEY_BYTES;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
OQS_MEM_secure_free(*key, PARAMS_KEY_BYTES);
|
||||
@ -214,9 +214,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MACRIFY(OQS_KEX_lwe_frodo_alice_1)(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS MACRIFY(OQS_KEX_lwe_frodo_alice_1)(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
*key = NULL;
|
||||
|
||||
/* check length of other party's public key */
|
||||
@ -247,11 +247,11 @@ int MACRIFY(OQS_KEX_lwe_frodo_alice_1)(UNUSED OQS_KEX *k, const void *alice_priv
|
||||
|
||||
*key_len = PARAMS_KEY_BYTES;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
OQS_MEM_secure_free(*key, PARAMS_KEY_BYTES);
|
||||
*key = NULL;
|
||||
|
||||
|
@ -52,7 +52,7 @@ static uint8_t get_entropy_from_dev_urandom(ENTROPY_CMD cmd, uint8_t *out) {
|
||||
}
|
||||
if (cmd == GET_BYTE_OF_ENTROPY) {
|
||||
// TODO: why is this called to get entropy bytes one by one?
|
||||
if (!OQS_RAND_get_system_entropy(out, 1)) {
|
||||
if (OQS_RAND_get_system_entropy(out, 1) != OQS_SUCCESS) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -65,9 +65,9 @@ typedef struct OQS_KEX_ntru_alice_priv {
|
||||
uint8_t *priv_key;
|
||||
} OQS_KEX_ntru_alice_priv;
|
||||
|
||||
int OQS_KEX_ntru_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_ntru_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
int ret = 0;
|
||||
OQS_STATUS ret = OQS_ERROR;
|
||||
uint32_t rc;
|
||||
DRBG_HANDLE drbg;
|
||||
OQS_KEX_ntru_alice_priv *ntru_alice_priv = NULL;
|
||||
@ -78,7 +78,7 @@ int OQS_KEX_ntru_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_m
|
||||
/* initialize NTRU DRBG */
|
||||
rc = ntru_crypto_drbg_instantiate(256, (uint8_t *) "OQS Alice", strlen("OQS Alice"), (ENTROPY_FN) &get_entropy_from_dev_urandom, &drbg);
|
||||
if (rc != DRBG_OK)
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
|
||||
/* allocate private key */
|
||||
ntru_alice_priv = malloc(sizeof(OQS_KEX_ntru_alice_priv));
|
||||
@ -109,11 +109,11 @@ int OQS_KEX_ntru_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_m
|
||||
goto err;
|
||||
*alice_msg_len = (size_t) ntru_alice_msg_len;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
if (ntru_alice_priv != NULL)
|
||||
free(ntru_alice_priv->priv_key);
|
||||
free(ntru_alice_priv);
|
||||
@ -126,9 +126,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_ntru_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_ntru_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
uint32_t rc;
|
||||
DRBG_HANDLE drbg;
|
||||
|
||||
@ -138,7 +138,7 @@ int OQS_KEX_ntru_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_ms
|
||||
/* initialize NTRU DRBG */
|
||||
rc = ntru_crypto_drbg_instantiate(256, (uint8_t *) "OQS Bob", strlen("OQS Bob"), (ENTROPY_FN) &get_entropy_from_dev_urandom, &drbg);
|
||||
if (rc != DRBG_OK)
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
|
||||
/* generate random session key */
|
||||
*key_len = 256 / 8;
|
||||
@ -165,11 +165,11 @@ int OQS_KEX_ntru_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_ms
|
||||
goto err;
|
||||
*bob_msg_len = (size_t) ntru_bob_msg_len;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
free(*key);
|
||||
@ -180,9 +180,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_ntru_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_ntru_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
uint32_t rc;
|
||||
|
||||
*key = NULL;
|
||||
@ -207,11 +207,11 @@ int OQS_KEX_ntru_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_
|
||||
goto err;
|
||||
*key_len = (size_t) ntru_key_len;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*key);
|
||||
*key = NULL;
|
||||
cleanup:
|
||||
|
@ -11,14 +11,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_ntru_new(OQS_RAND *rand);
|
||||
|
||||
int OQS_KEX_ntru_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_ntru_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_ntru_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_ntru_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_ntru_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_ntru_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_ntru_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_ntru_free(OQS_KEX *k);
|
||||
|
@ -48,9 +48,9 @@ OQS_KEX *OQS_KEX_rlwe_bcns15_new(OQS_RAND *rand) {
|
||||
return k;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_bcns15_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_bcns15_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
uint32_t *alice_msg_32 = NULL;
|
||||
|
||||
*alice_priv = NULL;
|
||||
@ -71,11 +71,11 @@ int OQS_KEX_rlwe_bcns15_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_m
|
||||
*alice_msg = (uint8_t *) alice_msg_32;
|
||||
*alice_msg_len = 1024 * sizeof(uint32_t);
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(alice_msg_32);
|
||||
OQS_MEM_secure_free(*alice_priv, 1024 * sizeof(uint32_t));
|
||||
*alice_priv = NULL;
|
||||
@ -84,9 +84,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_bcns15_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_bcns15_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
uint32_t *bob_priv = NULL;
|
||||
uint64_t *key_64 = NULL;
|
||||
@ -122,11 +122,11 @@ int OQS_KEX_rlwe_bcns15_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t a
|
||||
*key = (uint8_t *) key_64;
|
||||
*key_len = 16 * sizeof(uint64_t);
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
OQS_MEM_secure_free(key_64, 16 * sizeof(uint64_t));
|
||||
@ -137,9 +137,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_bcns15_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_bcns15_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
uint64_t *key_64 = NULL;
|
||||
|
||||
@ -161,11 +161,11 @@ int OQS_KEX_rlwe_bcns15_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_
|
||||
*key = (uint8_t *) key_64;
|
||||
*key_len = 16 * sizeof(uint64_t);
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
OQS_MEM_secure_free(key_64, 16 * sizeof(uint64_t));
|
||||
|
||||
cleanup:
|
||||
|
@ -9,14 +9,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_rlwe_bcns15_new(OQS_RAND *rand);
|
||||
|
||||
int OQS_KEX_rlwe_bcns15_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_rlwe_bcns15_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_rlwe_bcns15_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_bcns15_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_bcns15_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_bcns15_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_rlwe_bcns15_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_rlwe_bcns15_free(OQS_KEX *k);
|
||||
|
@ -42,9 +42,9 @@ OQS_KEX *OQS_KEX_rlwe_msrln16_new(OQS_RAND *rand) {
|
||||
return k;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_msrln16_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_msrln16_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*alice_priv = NULL;
|
||||
/* alice_msg is alice's public key */
|
||||
@ -64,11 +64,11 @@ int OQS_KEX_rlwe_msrln16_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_
|
||||
}
|
||||
*alice_msg_len = OQS_RLWE_MSRLN16_PKA_BYTES;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*alice_msg);
|
||||
*alice_msg = NULL;
|
||||
free(*alice_priv);
|
||||
@ -78,9 +78,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_msrln16_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_msrln16_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*bob_msg = NULL;
|
||||
*key = NULL;
|
||||
@ -104,11 +104,11 @@ int OQS_KEX_rlwe_msrln16_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t
|
||||
*key_len = OQS_RLWE_MSRLN16_SHAREDKEY_BYTES;
|
||||
*bob_msg_len = OQS_RLWE_MSRLN16_PKB_BYTES;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
free(*key);
|
||||
@ -119,9 +119,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_msrln16_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_msrln16_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*key = NULL;
|
||||
|
||||
@ -140,11 +140,11 @@ int OQS_KEX_rlwe_msrln16_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, cons
|
||||
|
||||
*key_len = OQS_RLWE_MSRLN16_SHAREDKEY_BYTES;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*key);
|
||||
*key = NULL;
|
||||
|
||||
|
@ -9,14 +9,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_rlwe_msrln16_new(OQS_RAND *rand);
|
||||
|
||||
int OQS_KEX_rlwe_msrln16_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_rlwe_msrln16_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_rlwe_msrln16_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_msrln16_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_msrln16_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_msrln16_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_rlwe_msrln16_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_rlwe_msrln16_free(OQS_KEX *k);
|
||||
|
@ -38,9 +38,9 @@ OQS_KEX *OQS_KEX_rlwe_newhope_new(OQS_RAND *rand) {
|
||||
return k;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_newhope_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_newhope_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*alice_priv = NULL;
|
||||
*alice_msg = NULL;
|
||||
@ -59,11 +59,11 @@ int OQS_KEX_rlwe_newhope_alice_0(UNUSED OQS_KEX *k, void **alice_priv, uint8_t *
|
||||
keygen(*alice_msg, (poly *) (*alice_priv), k->rand);
|
||||
*alice_msg_len = NEWHOPE_SENDABYTES;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*alice_msg);
|
||||
*alice_msg = NULL;
|
||||
free(*alice_priv);
|
||||
@ -74,9 +74,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_newhope_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_newhope_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*bob_msg = NULL;
|
||||
*key = NULL;
|
||||
@ -100,11 +100,11 @@ int OQS_KEX_rlwe_newhope_bob(UNUSED OQS_KEX *k, const uint8_t *alice_msg, const
|
||||
*bob_msg_len = NEWHOPE_SENDBBYTES;
|
||||
*key_len = 32;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
free(*key);
|
||||
@ -115,9 +115,9 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_rlwe_newhope_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_rlwe_newhope_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
*key = NULL;
|
||||
|
||||
@ -135,11 +135,11 @@ int OQS_KEX_rlwe_newhope_alice_1(UNUSED OQS_KEX *k, const void *alice_priv, cons
|
||||
shareda(*key, (poly *) alice_priv, bob_msg);
|
||||
*key_len = 32;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*key);
|
||||
*key = NULL;
|
||||
|
||||
|
@ -9,14 +9,15 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_rlwe_newhope_new(OQS_RAND *rand);
|
||||
|
||||
int OQS_KEX_rlwe_newhope_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_rlwe_newhope_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_rlwe_newhope_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_newhope_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_newhope_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_rlwe_newhope_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_rlwe_newhope_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_rlwe_newhope_free(OQS_KEX *k);
|
||||
|
@ -69,8 +69,8 @@ err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv,
|
||||
uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv,
|
||||
uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
|
||||
public_params_t *params = (public_params_t *) k->params;
|
||||
private_key_t Alice_private_key;
|
||||
@ -107,13 +107,13 @@ int OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv,
|
||||
oqs_sidh_iqc_ref_public_key_clear(Alice_public_key);
|
||||
oqs_sidh_iqc_ref_point_clear(kernel_gen);
|
||||
|
||||
return 1;
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
int OQS_KEX_sidh_iqc_ref_bob(OQS_KEX *k, const uint8_t *alice_msg,
|
||||
UNUSED const size_t alice_msg_len,
|
||||
uint8_t **bob_msg, size_t *bob_msg_len,
|
||||
uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_sidh_iqc_ref_bob(OQS_KEX *k, const uint8_t *alice_msg,
|
||||
UNUSED const size_t alice_msg_len,
|
||||
uint8_t **bob_msg, size_t *bob_msg_len,
|
||||
uint8_t **key, size_t *key_len) {
|
||||
|
||||
public_params_t *params = (public_params_t *) k->params;
|
||||
|
||||
@ -163,13 +163,13 @@ int OQS_KEX_sidh_iqc_ref_bob(OQS_KEX *k, const uint8_t *alice_msg,
|
||||
oqs_sidh_iqc_ref_point_clear(kernel_gen);
|
||||
oqs_sidh_iqc_ref_fp2_clear(Bob_shared_key);
|
||||
|
||||
return 1;
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
int OQS_KEX_sidh_iqc_ref_alice_1(OQS_KEX *k, const void *alice_priv,
|
||||
const uint8_t *bob_msg,
|
||||
UNUSED const size_t bob_msg_len, uint8_t **key,
|
||||
size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_sidh_iqc_ref_alice_1(OQS_KEX *k, const void *alice_priv,
|
||||
const uint8_t *bob_msg,
|
||||
UNUSED const size_t bob_msg_len, uint8_t **key,
|
||||
size_t *key_len) {
|
||||
|
||||
public_params_t *params = (public_params_t *) k->params;
|
||||
|
||||
@ -201,7 +201,7 @@ int OQS_KEX_sidh_iqc_ref_alice_1(OQS_KEX *k, const void *alice_priv,
|
||||
oqs_sidh_iqc_ref_public_key_clear(Bob_public_key);
|
||||
oqs_sidh_iqc_ref_fp2_clear(Alice_shared_key);
|
||||
|
||||
return 1;
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
void OQS_KEX_sidh_iqc_ref_alice_priv_free(UNUSED OQS_KEX *k, void *alice_priv) {
|
||||
|
@ -9,14 +9,15 @@ extern "C" {
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand, const char *named_parameters);
|
||||
|
||||
int OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_sidh_iqc_ref_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_sidh_iqc_ref_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_sidh_iqc_ref_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_sidh_iqc_ref_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_sidh_iqc_ref_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_sidh_iqc_ref_free(OQS_KEX *k);
|
||||
|
@ -141,10 +141,10 @@ cleanup:
|
||||
return k;
|
||||
}
|
||||
|
||||
int OQS_KEX_sidh_msr_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
int ret = 0;
|
||||
OQS_STATUS OQS_KEX_sidh_msr_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len) {
|
||||
OQS_STATUS ret = OQS_ERROR;
|
||||
if (!k || !alice_priv || !alice_msg || !alice_msg_len) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
}
|
||||
|
||||
*alice_priv = NULL;
|
||||
@ -172,11 +172,11 @@ int OQS_KEX_sidh_msr_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg,
|
||||
}
|
||||
*alice_msg_len = sidh_ctx->pub_key_len;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*alice_msg);
|
||||
*alice_msg = NULL;
|
||||
free(*alice_priv);
|
||||
@ -186,13 +186,13 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_sidh_msr_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_sidh_msr_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
uint8_t *bob_priv = NULL;
|
||||
|
||||
if (!k || !alice_msg || !bob_msg || !bob_msg_len || !key || !key_len) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
}
|
||||
|
||||
*bob_msg = NULL;
|
||||
@ -237,11 +237,11 @@ int OQS_KEX_sidh_msr_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alic
|
||||
}
|
||||
*key_len = sidh_ctx->shared_secret_len;
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*bob_msg);
|
||||
*bob_msg = NULL;
|
||||
free(*key);
|
||||
@ -253,12 +253,12 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OQS_KEX_sidh_msr_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
OQS_STATUS OQS_KEX_sidh_msr_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len) {
|
||||
|
||||
int ret;
|
||||
OQS_STATUS ret;
|
||||
|
||||
if (!k || !alice_priv || !bob_msg || !key || !key_len) {
|
||||
return 0;
|
||||
return OQS_ERROR;
|
||||
}
|
||||
|
||||
SIDH_CTX *sidh_ctx = (SIDH_CTX *) k->ctx;
|
||||
@ -287,11 +287,11 @@ int OQS_KEX_sidh_msr_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
ret = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
ret = 0;
|
||||
ret = OQS_ERROR;
|
||||
free(*key);
|
||||
*key = NULL;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/kex.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
@ -19,9 +20,9 @@
|
||||
|
||||
OQS_KEX *OQS_KEX_sidh_msr_new(OQS_RAND *rand, const char *named_parameters);
|
||||
|
||||
int OQS_KEX_sidh_msr_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
int OQS_KEX_sidh_msr_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
int OQS_KEX_sidh_msr_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_sidh_msr_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
|
||||
OQS_STATUS OQS_KEX_sidh_msr_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
OQS_STATUS OQS_KEX_sidh_msr_alice_1(OQS_KEX *k, const void *alice_priv, const uint8_t *bob_msg, const size_t bob_msg_len, uint8_t **key, size_t *key_len);
|
||||
|
||||
void OQS_KEX_sidh_msr_alice_priv_free(OQS_KEX *k, void *alice_priv);
|
||||
void OQS_KEX_sidh_msr_free(OQS_KEX *k);
|
||||
|
@ -7,16 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/sig.h>
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void disp_hex_string(const char *label, uint8_t *str, size_t len);
|
||||
|
||||
/* Partially displays hexadecimal strings */
|
||||
void disp_part_hex_string(const char *label, uint8_t *str, size_t len,
|
||||
size_t sub_len);
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
/* Cleaning up memory etc */
|
||||
void cleanup(uint8_t *msg, size_t msg_len, uint8_t *sig, size_t sig_len,
|
||||
@ -87,8 +78,8 @@ int main(void) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
disp_hex_string("Private key", priv, s->priv_key_len);
|
||||
disp_hex_string("Public key", pub, s->pub_key_len);
|
||||
OQS_print_hex_string("Private key", priv, s->priv_key_len);
|
||||
OQS_print_hex_string("Public key", pub, s->pub_key_len);
|
||||
|
||||
/* Allocates the memory for the message to sign */
|
||||
msg_len = 64; // TODO: randomize based on scheme's max length
|
||||
@ -102,7 +93,7 @@ int main(void) {
|
||||
|
||||
/* Generates a random message to sign */
|
||||
OQS_RAND_n(rnd, msg, msg_len);
|
||||
disp_hex_string("Message", msg, msg_len);
|
||||
OQS_print_hex_string("Message", msg, msg_len);
|
||||
|
||||
/* Allocates memory for the signature */
|
||||
sig_len = s->max_sig_len;
|
||||
@ -125,7 +116,7 @@ int main(void) {
|
||||
|
||||
if (sig_len > 40) {
|
||||
// only print the parts of the sig if too long
|
||||
disp_part_hex_string("Signature", sig, sig_len, 20);
|
||||
OQS_print_part_hex_string("Signature", sig, sig_len, 20);
|
||||
}
|
||||
|
||||
/* Verification */
|
||||
@ -144,27 +135,6 @@ int main(void) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void disp_hex_string(const char *label, uint8_t *str, size_t len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
for (size_t i = 0; i < (len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void disp_part_hex_string(const char *label, uint8_t *str, size_t len,
|
||||
size_t sub_len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
for (size_t i = 0; i < (sub_len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[i]);
|
||||
}
|
||||
printf("...");
|
||||
for (size_t i = 0; i < (sub_len); i++) {
|
||||
printf("%02X", ((unsigned char *) (str))[len - sub_len + i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Cleaning up memory etc */
|
||||
void cleanup(uint8_t *msg, size_t msg_len, uint8_t *sig, size_t sig_len,
|
||||
uint8_t *pub, uint8_t *priv, OQS_SIG *s, OQS_RAND *rnd) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/sig.h>
|
||||
#ifdef ENABLE_SIG_PICNIC
|
||||
@ -39,7 +40,7 @@ OQS_SIG *OQS_SIG_new(OQS_RAND *rand, enum OQS_SIG_algid algid) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int OQS_SIG_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
OQS_STATUS OQS_SIG_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
if (s == NULL) {
|
||||
return OQS_ERROR;
|
||||
} else {
|
||||
@ -47,7 +48,7 @@ int OQS_SIG_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
}
|
||||
}
|
||||
|
||||
int OQS_SIG_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len) {
|
||||
OQS_STATUS OQS_SIG_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len) {
|
||||
if (s == NULL) {
|
||||
return OQS_ERROR;
|
||||
} else {
|
||||
@ -55,7 +56,7 @@ int OQS_SIG_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, cons
|
||||
}
|
||||
}
|
||||
|
||||
int OQS_SIG_verify(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len) {
|
||||
OQS_STATUS OQS_SIG_verify(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len) {
|
||||
if (s == NULL) {
|
||||
return OQS_ERROR;
|
||||
} else {
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
/**
|
||||
@ -83,7 +85,8 @@ struct OQS_SIG {
|
||||
* @param pub The signer's public key.
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure.
|
||||
*/
|
||||
int (*keygen)(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
OQS_STATUS(*keygen)
|
||||
(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
|
||||
/**
|
||||
* Pointer to a function for signature generation.
|
||||
@ -96,7 +99,8 @@ struct OQS_SIG {
|
||||
* @param sig_len In: length of sig, out: length of the generated signature.
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure.
|
||||
*/
|
||||
int (*sign)(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len);
|
||||
OQS_STATUS(*sign)
|
||||
(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len);
|
||||
|
||||
/**
|
||||
* Pointer to a function for signature verification.
|
||||
@ -107,9 +111,10 @@ struct OQS_SIG {
|
||||
* @param msg_len Length of the signed message.
|
||||
* @param sig The signature to verify.
|
||||
* @param sig_len Length of the signature to verify.
|
||||
@return OQS_SUCCESS on success, or OQS_ERROR on failure.
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure.
|
||||
*/
|
||||
int (*verify)(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len);
|
||||
OQS_STATUS(*verify)
|
||||
(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -130,7 +135,7 @@ OQS_SIG *OQS_SIG_new(OQS_RAND *rand, enum OQS_SIG_algid algid);
|
||||
* must have allocated s->pub_key_len bytes.
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure
|
||||
*/
|
||||
int OQS_SIG_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
OQS_STATUS OQS_SIG_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
|
||||
/**
|
||||
* Generates a new signature.
|
||||
@ -142,7 +147,7 @@ int OQS_SIG_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
* @param sig_len Pointer to the length of the generated signature.
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure
|
||||
*/
|
||||
int OQS_SIG_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len);
|
||||
OQS_STATUS OQS_SIG_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len);
|
||||
|
||||
/**
|
||||
* Verifies a signature.
|
||||
@ -154,7 +159,7 @@ int OQS_SIG_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, cons
|
||||
* @param sig_len Length of the signature.
|
||||
* @return OQS_SUCCESS on success, or OQS_ERROR on failure
|
||||
*/
|
||||
int OQS_SIG_verify(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len);
|
||||
OQS_STATUS OQS_SIG_verify(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len);
|
||||
|
||||
/**
|
||||
* Frees the signature object, de-initializing the underlying library code.
|
||||
|
@ -7,12 +7,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/sig.h>
|
||||
#include <oqs/rand.h>
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "../ds_benchmark.h"
|
||||
#include "../common/common.h"
|
||||
|
||||
// TODO: add signature size to benchmark
|
||||
|
||||
@ -38,31 +35,9 @@ struct sig_testcase sig_testcases[] = {
|
||||
#define SIG_TEST_ITERATIONS 100
|
||||
#define SIG_BENCH_SECONDS 1
|
||||
|
||||
#define PRINT_HEX_STRING(label, str, len) \
|
||||
{ \
|
||||
printf("%-20s (%4zu bytes): ", (label), (size_t)(len)); \
|
||||
for (size_t i = 0; i < (len); i++) { \
|
||||
printf("%02X", ((unsigned char *) (str))[i]); \
|
||||
} \
|
||||
printf("\n"); \
|
||||
}
|
||||
static OQS_STATUS sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const int print) {
|
||||
|
||||
#define PRINT_PARTIAL_HEX_STRING(label, str, len, sublen) \
|
||||
{ \
|
||||
printf("%-20s (%4zu bytes): ", (label), (size_t)(len)); \
|
||||
for (size_t i = 0; i < (sublen); i++) { \
|
||||
printf("%02X", ((unsigned char *) (str))[i]); \
|
||||
} \
|
||||
printf("..."); \
|
||||
for (size_t i = 0; i < (sublen); i++) { \
|
||||
printf("%02X", ((unsigned char *) (str))[len - sublen + i]); \
|
||||
} \
|
||||
printf("\n"); \
|
||||
}
|
||||
|
||||
static int sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const int print) {
|
||||
|
||||
int rc;
|
||||
OQS_STATUS rc;
|
||||
|
||||
uint8_t *priv = NULL;
|
||||
uint8_t *pub = NULL;
|
||||
@ -97,14 +72,14 @@ static int sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const
|
||||
}
|
||||
|
||||
rc = OQS_SIG_keygen(s, priv, pub);
|
||||
if (rc != 1) {
|
||||
if (rc != OQS_SUCCESS) {
|
||||
eprintf("OQS_SIG_keygen failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (print) {
|
||||
PRINT_HEX_STRING("Private key", priv, s->priv_key_len)
|
||||
PRINT_HEX_STRING("Public key", pub, s->pub_key_len)
|
||||
OQS_print_hex_string("Private key", priv, s->priv_key_len);
|
||||
OQS_print_hex_string("Public key", pub, s->pub_key_len);
|
||||
}
|
||||
|
||||
/* Generate message to sign */
|
||||
@ -116,7 +91,7 @@ static int sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const
|
||||
}
|
||||
OQS_RAND_n(rand, msg, msg_len);
|
||||
if (print) {
|
||||
PRINT_HEX_STRING("Message", msg, msg_len)
|
||||
OQS_print_hex_string("Message", msg, msg_len);
|
||||
}
|
||||
|
||||
/* Signature */
|
||||
@ -128,7 +103,7 @@ static int sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const
|
||||
}
|
||||
|
||||
rc = OQS_SIG_sign(s, priv, msg, msg_len, sig, &sig_len);
|
||||
if (rc != 1) {
|
||||
if (rc != OQS_SUCCESS) {
|
||||
eprintf("OQS_SIG_sign failed\n");
|
||||
goto err;
|
||||
}
|
||||
@ -136,13 +111,13 @@ static int sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const
|
||||
if (print) {
|
||||
if (sig_len > 40) {
|
||||
// only print the parts of the sig if too long
|
||||
PRINT_PARTIAL_HEX_STRING("Signature", sig, sig_len, 20);
|
||||
OQS_print_part_hex_string("Signature", sig, sig_len, 20);
|
||||
}
|
||||
}
|
||||
|
||||
/* Verification */
|
||||
rc = OQS_SIG_verify(s, pub, msg, msg_len, sig, sig_len);
|
||||
if (rc != 1) {
|
||||
if (rc != OQS_SUCCESS) {
|
||||
eprintf("ERROR: OQS_SIG_verify failed\n");
|
||||
goto err;
|
||||
}
|
||||
@ -152,11 +127,11 @@ static int sig_test_correctness(OQS_RAND *rand, enum OQS_SIG_algid algid, const
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
rc = 1;
|
||||
rc = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
rc = 0;
|
||||
rc = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
if (msg != NULL) {
|
||||
@ -178,29 +153,29 @@ cleanup:
|
||||
return rc;
|
||||
}
|
||||
|
||||
UNUSED static int sig_test_correctness_wrapper(OQS_RAND *rand, enum OQS_SIG_algid algid, int iterations, bool quiet) {
|
||||
int ret;
|
||||
UNUSED static OQS_STATUS sig_test_correctness_wrapper(OQS_RAND *rand, enum OQS_SIG_algid algid, int iterations, bool quiet) {
|
||||
OQS_STATUS ret;
|
||||
ret = sig_test_correctness(rand, algid, !quiet);
|
||||
if (ret != 1) {
|
||||
if (ret != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
printf("Testing correctness and randomness of signature for %d iterations\n", iterations);
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
ret = sig_test_correctness(rand, algid, 0);
|
||||
if (ret != 1) {
|
||||
if (ret != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
printf("All signatures were valid.\n");
|
||||
printf("\n\n");
|
||||
return 1;
|
||||
return OQS_SUCCESS;
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
UNUSED static int sig_bench_wrapper(OQS_RAND *rand, enum OQS_SIG_algid algid, const int seconds) {
|
||||
int rc;
|
||||
UNUSED static OQS_STATUS sig_bench_wrapper(OQS_RAND *rand, enum OQS_SIG_algid algid, const int seconds) {
|
||||
OQS_STATUS rc;
|
||||
|
||||
uint8_t *priv = NULL;
|
||||
uint8_t *pub = NULL;
|
||||
@ -252,11 +227,11 @@ UNUSED static int sig_bench_wrapper(OQS_RAND *rand, enum OQS_SIG_algid algid, co
|
||||
OQS_SIG_sign(s, priv, msg, msg_len, sig, &sig_len);
|
||||
TIME_OPERATION_SECONDS({ OQS_SIG_verify(s, pub, msg, msg_len, sig, sig_len); }, "verify", seconds);
|
||||
|
||||
rc = 1;
|
||||
rc = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
rc = 0;
|
||||
rc = OQS_ERROR;
|
||||
|
||||
cleanup:
|
||||
free(priv);
|
||||
@ -270,7 +245,7 @@ cleanup:
|
||||
|
||||
#ifdef ENABLE_SIG_PICNIC
|
||||
int main(int argc, char **argv) {
|
||||
int success = 1;
|
||||
OQS_STATUS success = OQS_SUCCESS;
|
||||
bool run_all = true;
|
||||
bool quiet = false;
|
||||
bool bench = false;
|
||||
@ -317,7 +292,7 @@ int main(int argc, char **argv) {
|
||||
int num_iter = sig_testcases[i].iter;
|
||||
success = sig_test_correctness_wrapper(rand, sig_testcases[i].algid, num_iter, quiet);
|
||||
}
|
||||
if (success != 1) {
|
||||
if (success != OQS_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -332,22 +307,22 @@ int main(int argc, char **argv) {
|
||||
PRINT_TIMER_FOOTER
|
||||
}
|
||||
|
||||
success = 1;
|
||||
success = OQS_SUCCESS;
|
||||
goto cleanup;
|
||||
|
||||
err:
|
||||
success = 0;
|
||||
success = OQS_ERROR;
|
||||
eprintf("ERROR!\n");
|
||||
|
||||
cleanup:
|
||||
if (rand) {
|
||||
OQS_RAND_free(rand);
|
||||
}
|
||||
return (success == 1) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
return (success == OQS_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
#else // !ENABLE_SIG_PICNIC
|
||||
int main() {
|
||||
printf("No signature algorithm available. Make sure configure was run properly; see Readme.md.\n");
|
||||
return 0;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
@ -42,7 +42,7 @@ typedef struct PICNIC_CTX {
|
||||
picnic_params_t params;
|
||||
} PICNIC_CTX;
|
||||
|
||||
int OQS_SIG_picnic_get(OQS_SIG *s, enum OQS_SIG_algid algid) {
|
||||
OQS_STATUS OQS_SIG_picnic_get(OQS_SIG *s, enum OQS_SIG_algid algid) {
|
||||
if (s == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
@ -108,7 +108,7 @@ int OQS_SIG_picnic_get(OQS_SIG *s, enum OQS_SIG_algid algid) {
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
int OQS_SIG_picnic_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
OQS_STATUS OQS_SIG_picnic_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
if (s == NULL || priv == NULL || pub == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
@ -116,7 +116,7 @@ int OQS_SIG_picnic_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
picnic_privatekey_t sk;
|
||||
picnic_params_t parameters = ((PICNIC_CTX *) s->ctx)->params;
|
||||
int ret = picnic_keygen(parameters, &pk, &sk);
|
||||
if (ret != 0) {
|
||||
if (ret != 0) { // DO NOT modify this return code to OQS_SUCCESS/OQS_ERROR
|
||||
return OQS_ERROR;
|
||||
}
|
||||
// serialize the public key
|
||||
@ -135,7 +135,7 @@ int OQS_SIG_picnic_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub) {
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
int OQS_SIG_picnic_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len) {
|
||||
OQS_STATUS OQS_SIG_picnic_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len) {
|
||||
if (s == NULL || priv == NULL || msg == NULL || sig == NULL || sig_len == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
@ -151,7 +151,7 @@ int OQS_SIG_picnic_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *ms
|
||||
return OQS_SUCCESS;
|
||||
}
|
||||
|
||||
int OQS_SIG_picnic_verify(UNUSED const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len) {
|
||||
OQS_STATUS OQS_SIG_picnic_verify(UNUSED const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len) {
|
||||
if (pub == NULL || msg == NULL || sig == NULL) {
|
||||
return OQS_ERROR;
|
||||
}
|
||||
|
@ -9,12 +9,13 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <oqs/common.h>
|
||||
#include <oqs/sig.h>
|
||||
#include <oqs/rand.h>
|
||||
|
||||
int OQS_SIG_picnic_get(OQS_SIG *sig, enum OQS_SIG_algid algid);
|
||||
int OQS_SIG_picnic_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
int OQS_SIG_picnic_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len);
|
||||
int OQS_SIG_picnic_verify(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len);
|
||||
OQS_STATUS OQS_SIG_picnic_get(OQS_SIG *sig, enum OQS_SIG_algid algid);
|
||||
OQS_STATUS OQS_SIG_picnic_keygen(const OQS_SIG *s, uint8_t *priv, uint8_t *pub);
|
||||
OQS_STATUS OQS_SIG_picnic_sign(const OQS_SIG *s, const uint8_t *priv, const uint8_t *msg, const size_t msg_len, uint8_t *sig, size_t *sig_len);
|
||||
OQS_STATUS OQS_SIG_picnic_verify(const OQS_SIG *s, const uint8_t *pub, const uint8_t *msg, const size_t msg_len, const uint8_t *sig, const size_t sig_len);
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user