Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove s2n's internal Kyber512 implementation, and rely on AWS-LC for Kyber support #4283

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 1 addition & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)

option(S2N_NO_PQ "Disables all Post Quantum Crypto code. You likely want this
for older compilers or uncommon platforms." OFF)
option(S2N_NO_PQ_ASM "Turns off the ASM for PQ Crypto even if it's available for the toolchain.
You likely want this on older compilers." OFF)
Comment on lines -22 to -25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep these options and just have them be no-ops? Does CMake warn or error out if you pass an option that doesn't exist?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my experience, cmake just warns about unrecognized options.

CMake Warning:
  Manually-specified variables were not used by the project:

    S2N_FIPS
    S2N_INTERN_LIBCRYPTO
    S2N_NO_PQ


-- Build files have been written to: /home/ubuntu/aws-lc/build

also, there may be cases when users link against AWS-LC but still don't want PQ enabled (admittedly, i can't think of a strong use-case for this off the top of my head). why remove these options?

Copy link
Contributor Author

@alexw91 alexw91 Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove these options?

Enabling the S2N_NO_PQ flag causes the build to skip compiling the Kyber code in the pq-crypto directory of s2n. It's confusing to keep around a flag to skip compiling code that doesn't exist anymore.

As far as I'm aware, the S2N_NO_PQ flag has only been enabled when it's been needed to keep s2n compiling on very old compiler versions that don't know about certain modern x86_64 instructions used in some of the Kyber assembly optimizations, and used to keep s2n compiling on some more obscure CPU architectures (MIPS, PowerPC, etc) that the NIST Kyber reference code doesn't compile for but that the AWS Common Runtime SDK targets. For both of these use cases (old compilers and obscure architectures), the S2N_NO_PQ flag is no longer needed. Here's a link to when this flag was originally introduced to workaround build failures on MIPS platforms.

We don't have equivalent flags to disable entire algorithms across the whole s2n-tls codebase (S2N_NO_RSA, S2N_NO_X25519, S2N_NO_CHACHAPOLY, etc). This PR is meant to bring Kyber more in line with how all other crypto algorithms are treated in s2n, and have the necessary logic that detects if the algorithm is supported by the libcrypto that s2n is compiled against.

option(SEARCH_LIBCRYPTO "Set this if you want to let S2N search libcrypto for you,
otherwise a crypto target needs to be defined." ON)
option(UNSAFE_TREAT_WARNINGS_AS_ERRORS "Compiler warnings are treated as errors. Warnings may
Expand Down Expand Up @@ -62,47 +58,25 @@ file(GLOB_RECURSE TLS_SRC "tls/*.c")
file(GLOB UTILS_HEADERS "utils/*.h")
file(GLOB UTILS_SRC "utils/*.c")

# Always include the top-level pq-crypto/ files
file(GLOB PQ_HEADERS "pq-crypto/*.h")
file(GLOB PQ_SRC "pq-crypto/*.c")

message(STATUS "Detected CMAKE_SYSTEM_PROCESSOR as ${CMAKE_SYSTEM_PROCESSOR}")

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
message(STATUS "Detected 32-Bit system - disabling PQ crypto assembly optimizations")
set(S2N_NO_PQ_ASM ON)
message(STATUS "Detected 32-Bit system")
else()
message(STATUS "Detected 64-Bit system")
endif()
lrstewart marked this conversation as resolved.
Show resolved Hide resolved

if(S2N_NO_PQ)
# PQ is disabled, so we do not include any PQ crypto code
message(STATUS "S2N_NO_PQ flag was detected - disabling PQ crypto")
set(S2N_NO_PQ_ASM ON)
else()
# PQ is enabled, so include all of the PQ crypto code
file(GLOB PQ_HEADERS
"pq-crypto/*.h"
"pq-crypto/kyber_r3/*.h")

file(GLOB PQ_SRC
"pq-crypto/*.c"
"pq-crypto/kyber_r3/*.c")
endif()

##be nice to visual studio users
if(MSVC)
source_group("Header Files\\s2n\\api" FILES ${API_HEADERS} ${API_UNSTABLE_HEADERS})
source_group("Header Files\\s2n\\crypto" FILES ${CRYPTO_HEADERS})
source_group("Header Files\\s2n\\error" FILES ${ERROR_HEADERS})
source_group("Header Files\\s2n\\pq-crypto" FILES ${PQ_HEADERS})
source_group("Header Files\\s2n\\stuffer" FILES ${STUFFER_HEADERS})
source_group("Header Files\\s2n\\tls" FILES ${TLS_HEADERS})
source_group("Header Files\\s2n\\utils" FILES ${UTILS_HEADERS})

source_group("Source Files\\crypto" FILES ${CRYPTO_SRC})
source_group("Source Files\\error" FILES ${ERROR_SRC})
source_group("Source Files\\pq-crypto" FILES ${PQ_SRC})
source_group("Source Files\\stuffer" FILES ${STUFFER_SRC})
source_group("Source Files\\tls" FILES ${TLS_SRC})
source_group("Source Files\\utils" FILES ${UTILS_SRC})
Expand Down Expand Up @@ -135,7 +109,6 @@ file(GLOB S2N_HEADERS
${API_UNSTABLE_HEADERS}
${CRYPTO_HEADERS}
${ERROR_HEADERS}
${PQ_HEADERS}
${STUFFER_HEADERS}
${TLS_HEADERS}
${UTILS_HEADERS}
Expand All @@ -144,7 +117,6 @@ file(GLOB S2N_HEADERS
file(GLOB S2N_SRC
${CRYPTO_SRC}
${ERROR_SRC}
${PQ_SRC}
${STUFFER_SRC}
${TLS_SRC}
${UTILS_SRC}
Expand Down Expand Up @@ -186,10 +158,6 @@ if(NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS -Wl,-z,noexecstack,-z,relro,-z,now)
endif()

if(S2N_NO_PQ)
add_definitions(-DS2N_NO_PQ)
endif()

# Whether to fail the build when compiling s2n's portable C code with non-portable assembly optimizations. Doing this
# can lead to runtime crashes if build artifacts are built on modern hardware, but deployed to older hardware without
# newer CPU instructions. s2n, by default, should be backwards compatible with older CPU types so this flag should be
Expand Down Expand Up @@ -367,32 +335,6 @@ if (NOT S2N_EXECINFO_AVAILABLE)
endif()
feature_probe_result(S2N_STACKTRACE ${S2N_STACKTRACE})

set(S2N_KYBER512R3_AVX2_BMI2 FALSE)
if(NOT S2N_NO_PQ_ASM)
# Kyber Round-3 code has several different optimizations which require
# specific compiler flags to be supported by the compiler.
# So for each needed instruction set extension we check if the compiler
# supports it and set proper compiler flags to be added later to the
# Kyber compilation units.
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|amd64|AMD64)$")
# Some platforms support -mavx2 flag but not m256 intrinsics required to use them. Only enable Kyber assembly
# optimizations if both are supported. See https://github.com/aws/s2n-tls/pull/3005 for more info.
if(S2N_KYBER512R3_AVX2_BMI2_SUPPORTED AND S2N_KYBER512R3_M256_INTRINSICS_SUPPORTED)
set(S2N_KYBER512R3_AVX2_BMI2 TRUE)
enable_language(ASM)

# add the assembly files to the project
FILE(GLOB KYBER512R3_AVX2_BMI2_ASM_SRCS "pq-crypto/kyber_r3/*_avx2.S")
target_sources(${PROJECT_NAME} PRIVATE ${KYBER512R3_AVX2_BMI2_ASM_SRCS})

# compile the C files with avx flags
FILE(GLOB KYBER512R3_AVX2_BMI2_SRCS "pq-crypto/kyber_r3/*_avx2.c")
set_source_files_properties(${KYBER512R3_AVX2_BMI2_SRCS} PROPERTIES COMPILE_FLAGS ${S2N_KYBER512R3_AVX2_BMI2_SUPPORTED_FLAGS})
endif()
endif()
endif()
feature_probe_result(S2N_KYBER512R3_AVX2_BMI2 ${S2N_KYBER512R3_AVX2_BMI2})

if (S2N_INTERN_LIBCRYPTO)

# Check if the AWS::crypto target has beeen added and handle it
Expand Down
22 changes: 0 additions & 22 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


============================================================================
S2N SUBCOMPONENTS:

The s2n Project contains subcomponents with separate copyright notices
and license terms. Your use of the source code for these subcomponents is
subject to the terms and conditions of the following licenses.


========================================================================
Third party MIT licenses
========================================================================

The following components are provided under the MIT License. See project link for details.


SIKE
-> s2n/pq-crypto/sike_r1/LICENSE.txt



6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ include s2n.mk

.PHONY : libs
libs:
$(MAKE) -C pq-crypto
$(MAKE) -C utils
$(MAKE) -C error
$(MAKE) -C stuffer
Expand Down Expand Up @@ -101,12 +100,11 @@ run-lcov:
$(MAKE) -C bin lcov
$(MAKE) -C crypto lcov
$(MAKE) -C error lcov
$(MAKE) -C pq-crypto run-lcov
$(MAKE) -C stuffer lcov
$(MAKE) -C tests lcov
$(MAKE) -C tls run-lcov
$(MAKE) -C utils lcov
lcov -a crypto/coverage.info -a error/coverage.info -a pq-crypto/coverage.info -a pq-crypto/kyber_r3/coverage.info -a stuffer/coverage.info -a tls/coverage.info -a $(wildcard tls/*/coverage.info) -a utils/coverage.info --output ${COVERAGE_DIR}/all_coverage.info
lcov -a crypto/coverage.info -a error/coverage.info -a stuffer/coverage.info -a tls/coverage.info -a $(wildcard tls/*/coverage.info) -a utils/coverage.info --output ${COVERAGE_DIR}/all_coverage.info

.PHONY : run-genhtml
run-genhtml:
Expand All @@ -115,7 +113,6 @@ run-genhtml:

.PHONY : indent
indent:
$(MAKE) -C pq-crypto indentsource
$(MAKE) -C tests indentsource
$(MAKE) -C stuffer indentsource
$(MAKE) -C crypto indentsource
Expand Down Expand Up @@ -147,7 +144,6 @@ uninstall:

.PHONY : clean
clean:
$(MAKE) -C pq-crypto clean
$(MAKE) -C tests clean
$(MAKE) -C stuffer decruft
$(MAKE) -C crypto decruft
Expand Down
1 change: 0 additions & 1 deletion bindings/rust/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ cp -r \
../../api \
../../crypto \
../../error \
../../pq-crypto \
../../stuffer \
../../tls \
../../utils \
Expand Down
2 changes: 2 additions & 0 deletions bindings/rust/s2n-tls-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ fn build_vendored() {

let mut build = builder(&libcrypto);

// TODO: update rust bindings to handle no pq-crypto dir

Comment on lines +96 to +97
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do a separate PR to fix the rust build once this is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not updating the bindings break anything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it shouldn't. If pq was enabled at all, we would fall back to the cmake build. The rust build change will basically just be deleting the special casing for that.

let pq = option_env("CARGO_FEATURE_PQ").is_some();

// TODO each pq section needs to be built separately since it
Expand Down
4 changes: 2 additions & 2 deletions codebuild/bin/grep_simple_mistakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FAILED=0
# Grep for any instances of raw memcpy() function. s2n code should instead be
# using one of the *_ENSURE_MEMCPY macros.
#############################################
S2N_FILES_ASSERT_NOT_USING_MEMCPY=$(find "$PWD" -type f -name "s2n*.[ch]" -not -path "*/tests/*" -not -path "*/pq-crypto/*")
S2N_FILES_ASSERT_NOT_USING_MEMCPY=$(find "$PWD" -type f -name "s2n*.[ch]" -not -path "*/tests/*")
for file in $S2N_FILES_ASSERT_NOT_USING_MEMCPY; do
RESULT_NUM_LINES=`grep 'memcpy(' $file | wc -l`
if [ "${RESULT_NUM_LINES}" != 0 ]; then
Expand Down Expand Up @@ -180,7 +180,7 @@ done
## Assert that there are no new uses of S2N_ERROR_IF
# TODO add crypto, tls (see https://github.com/aws/s2n-tls/issues/2635)
#############################################
S2N_ERROR_IF_FREE="bin error pq-crypto scram stuffer utils tests"
S2N_ERROR_IF_FREE="bin error scram stuffer utils tests"
for dir in $S2N_ERROR_IF_FREE; do
files=$(find "$dir" -type f -name "*.c" -path "*")
for file in $files; do
Expand Down
1 change: 0 additions & 1 deletion compliance/generate_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ duvet \
--source-pattern '(*=,*#)bin/**/*.[ch]' \
--source-pattern '(*=,*#)crypto/**/*.[ch]' \
--source-pattern '(*=,*#)error/**/*.[ch]' \
--source-pattern '(*=,*#)pq-crypto/**/*.[ch]' \
--source-pattern '(*=,*#)stuffer/**/*.[ch]' \
--source-pattern '(*=,*#)tests/**/*.[ch]' \
--source-pattern '(*=,*#)tls/**/*.[ch]' \
Expand Down
27 changes: 6 additions & 21 deletions pq-crypto/s2n_kyber_evp.c → crypto/s2n_kyber_evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
#include <openssl/evp.h>
#include <stddef.h>

#include "crypto/s2n_pq.h"
#include "error/s2n_errno.h"
#include "pq-crypto/s2n_pq.h"
#include "tls/s2n_kem.h"
#include "utils/s2n_safety.h"
#include "utils/s2n_safety_macros.h"

#if defined(S2N_LIBCRYPTO_SUPPORTS_KYBER) && !defined(S2N_NO_PQ)
#if defined(S2N_LIBCRYPTO_SUPPORTS_KYBER)

DEFINE_POINTER_CLEANUP_FUNC(EVP_PKEY *, EVP_PKEY_free);
DEFINE_POINTER_CLEANUP_FUNC(EVP_PKEY_CTX *, EVP_PKEY_CTX_free);

int s2n_kyber_evp_generate_keypair(IN const struct s2n_kem *kem, OUT uint8_t *public_key,
OUT uint8_t *secret_key)
{
POSIX_ENSURE(s2n_pq_is_enabled(), S2N_ERR_PQ_DISABLED);
DEFER_CLEANUP(EVP_PKEY_CTX *kyber_pkey_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_KEM, NULL), EVP_PKEY_CTX_free_pointer);
POSIX_GUARD_PTR(kyber_pkey_ctx);
POSIX_GUARD_OSSL(EVP_PKEY_CTX_kem_set_params(kyber_pkey_ctx, kem->kem_nid), S2N_ERR_PQ_CRYPTO);
Expand All @@ -53,7 +52,6 @@ int s2n_kyber_evp_generate_keypair(IN const struct s2n_kem *kem, OUT uint8_t *pu
int s2n_kyber_evp_encapsulate(IN const struct s2n_kem *kem, OUT uint8_t *ciphertext, OUT uint8_t *shared_secret,
IN const uint8_t *public_key)
{
POSIX_ENSURE(s2n_pq_is_enabled(), S2N_ERR_PQ_DISABLED);
DEFER_CLEANUP(EVP_PKEY *kyber_pkey = EVP_PKEY_kem_new_raw_public_key(kem->kem_nid, public_key, kem->public_key_length), EVP_PKEY_free_pointer);
POSIX_GUARD_PTR(kyber_pkey);

Expand All @@ -74,7 +72,6 @@ int s2n_kyber_evp_encapsulate(IN const struct s2n_kem *kem, OUT uint8_t *ciphert
int s2n_kyber_evp_decapsulate(IN const struct s2n_kem *kem, OUT uint8_t *shared_secret, IN const uint8_t *ciphertext,
IN const uint8_t *private_key)
{
POSIX_ENSURE(s2n_pq_is_enabled(), S2N_ERR_PQ_DISABLED);
DEFER_CLEANUP(EVP_PKEY *kyber_pkey = EVP_PKEY_kem_new_raw_secret_key(kem->kem_nid, private_key, kem->private_key_length), EVP_PKEY_free_pointer);
POSIX_GUARD_PTR(kyber_pkey);

Expand All @@ -90,36 +87,24 @@ int s2n_kyber_evp_decapsulate(IN const struct s2n_kem *kem, OUT uint8_t *shared_
return S2N_SUCCESS;
}

#elif !defined(S2N_NO_PQ) /* Use interned Kyber512 implementation, otherwise bail. */
#else /* If !S2N_LIBCRYPTO_SUPPORTS_KYBER, we won't have a Kyber impl so define relevant stubs here. */

Comment on lines +90 to 91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change? Wont' we break anyone using pq with a libcrypto other than awslc?
What kind of effect should this have on our version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change? Wont' we break anyone using pq with a libcrypto other than awslc?

All AWS teams that are currently using Hybrid PQ TLS are able to use s2n-tls with AWS-LC. I'm not aware of any other external users, but if there are others using s2n's Kyber implementation with an Openssl libcrypto, they will gracefully fall back to regular classical algorithms. This PR would be a behavioral change in which SupportedGroup is negotiated at runtime by s2n, but likely not a "breaking" change. Customers won't start receiving errors from s2n after this change if using PQ TLS Policies, but if they have tests that confirm that a specific Kyber SupportedGroup was negotiated then those tests might fail.

In the AWS SDK Java documentation, we've also mentioned that these PQ algorithms may stopped being supported at any time.

What kind of effect should this have on our version?

From reading the versioning policy doc, the line "Possible backwards-incompatible changes. These changes will be noted and explained in detail in the release notes" best fits this change. I think bumping s2n-tls from 1.3.56 to 1.4.0 would be preferred.

int s2n_kyber_evp_generate_keypair(IN const struct s2n_kem *kem, OUT uint8_t *public_key,
OUT uint8_t *secret_key)
{
POSIX_ENSURE(s2n_pq_is_enabled(), S2N_ERR_PQ_DISABLED);
if (kem == &s2n_kyber_512_r3) {
return s2n_kyber_512_r3_crypto_kem_keypair(kem, public_key, secret_key);
}
POSIX_BAIL(S2N_ERR_UNIMPLEMENTED);
POSIX_BAIL(S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API);
}

int s2n_kyber_evp_encapsulate(IN const struct s2n_kem *kem, OUT uint8_t *ciphertext, OUT uint8_t *shared_secret,
IN const uint8_t *public_key)
{
POSIX_ENSURE(s2n_pq_is_enabled(), S2N_ERR_PQ_DISABLED);
if (kem == &s2n_kyber_512_r3) {
return s2n_kyber_512_r3_crypto_kem_enc(kem, ciphertext, shared_secret, public_key);
}
POSIX_BAIL(S2N_ERR_UNIMPLEMENTED);
POSIX_BAIL(S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API);
Comment on lines -112 to +101
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should keep S2N_ERR_PQ_DISABLED and use that here? Since this is a breaking change, we might want a very specific error.

You'll also need to update fewer tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should keep S2N_ERR_PQ_DISABLED and use that here?

S2N_ERR_PQ_DISABLED, to me, has always meant "the user who was compiling s2n-tls decided to disable the PQ code in the ./pq-crypto directory". Since the pq-crypto directory doesn't exist anymore, keeping around that error message seems confusing to me.

In this case, something in s2n has called s2n's Kyber KEM API, and s2n doesn't have a Kyber libcrypto API that it can call (since the libcrypto s2n was compiled against doesn't support Kyber), so S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API seems like the best fit.

we might want a very specific error.

I feel like S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API is that very specific error. Or would you prefer that I create a S2N_ERR_NO_SUPPORTED_PQ_LIBCRYPTO_API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about what you said above:

I'm not aware of any other external users, but if there are others using s2n's Kyber implementation with an Openssl libcrypto, they will gracefully fall back to regular classical algorithms. This PR would be a behavioral change in which SupportedGroup is negotiated at runtime by s2n, but likely not a "breaking" change. Customers won't start receiving errors from s2n after this change if using PQ TLS Policies, but if they have tests that confirm that a specific Kyber SupportedGroup was negotiated then those tests might fail.

If we don't expect to ever actually hit this logic and to just fall back to classical, then S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API is fine. But if it's possible for us to break a customer and for them to see this error message related to that new failure, we should probably use a message that mentions PQ like S2N_ERR_NO_SUPPORTED_PQ_LIBCRYPTO_API.

So it sounds like we're fine with S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API, because customers shouldn't receive any errors related to this change.

}

int s2n_kyber_evp_decapsulate(IN const struct s2n_kem *kem, OUT uint8_t *shared_secret, IN const uint8_t *ciphertext,
IN const uint8_t *secret_key)
{
POSIX_ENSURE(s2n_pq_is_enabled(), S2N_ERR_PQ_DISABLED);
if (kem == &s2n_kyber_512_r3) {
return s2n_kyber_512_r3_crypto_kem_dec(kem, shared_secret, ciphertext, secret_key);
}
POSIX_BAIL(S2N_ERR_UNIMPLEMENTED);
POSIX_BAIL(S2N_ERR_NO_SUPPORTED_LIBCRYPTO_API);
}

#endif
File renamed without changes.
22 changes: 17 additions & 5 deletions pq-crypto/s2n_pq_random.h → crypto/s2n_pq.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@
* permissions and limitations under the License.
*/

#pragma once
#include "s2n_pq.h"

#include "utils/s2n_result.h"
#include "crypto/s2n_openssl.h"

typedef S2N_RESULT (*s2n_get_random_bytes_callback)(uint8_t *buffer, uint32_t num_bytes);
bool s2n_libcrypto_supports_kyber()
{
/* S2N_LIBCRYPTO_SUPPORTS_KYBER will be auto-detected and #defined if
* ./tests/features/S2N_LIBCRYPTO_SUPPORTS_KYBER.c successfully compiles
*/
#if defined(S2N_LIBCRYPTO_SUPPORTS_KYBER)
return true;
#else
return false;
#endif
}

S2N_RESULT s2n_get_random_bytes(uint8_t *buffer, uint32_t num_bytes);
S2N_RESULT s2n_set_rand_bytes_callback_for_testing(s2n_get_random_bytes_callback rand_bytes_callback);
bool s2n_pq_is_enabled()
{
return s2n_libcrypto_supports_kyber();
}
6 changes: 0 additions & 6 deletions pq-crypto/s2n_pq.h → crypto/s2n_pq.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@
#include <stdbool.h>

#include "crypto/s2n_fips.h"
#include "pq-crypto/s2n_pq_asm.h"
#include "utils/s2n_result.h"
#include "utils/s2n_safety.h"

bool s2n_kyber512r3_is_avx2_bmi2_enabled(void);
S2N_RESULT s2n_try_enable_kyber512r3_opt_avx2_bmi2(void);
S2N_RESULT s2n_disable_kyber512r3_opt_avx2_bmi2(void);

bool s2n_pq_is_enabled(void);
bool s2n_libcrypto_supports_kyber(void);
S2N_RESULT s2n_pq_init(void);
1 change: 0 additions & 1 deletion error/s2n_errno.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ static const char *no_such_error = "Internal s2n error";
ERR_ENTRY(S2N_ERR_INVALID_STATE, "Invalid state, this is the result of invalid use of an API. Check the API documentation for the function that raised this error for more info") \
ERR_ENTRY(S2N_ERR_UNSUPPORTED_WITH_QUIC, "Functionality not supported when running with QUIC support enabled") \
ERR_ENTRY(S2N_ERR_PQ_CRYPTO, "An error occurred in a post-quantum crypto function") \
ERR_ENTRY(S2N_ERR_PQ_DISABLED, "Post-quantum crypto is disabled") \
ERR_ENTRY(S2N_ERR_DUPLICATE_PSK_IDENTITIES, "The list of pre-shared keys provided contains duplicate psk identities") \
ERR_ENTRY(S2N_ERR_OFFERED_PSKS_TOO_LONG, "The total pre-shared key data is too long to send over the wire") \
ERR_ENTRY(S2N_ERR_INVALID_SESSION_TICKET, "Session ticket data is not valid") \
Expand Down
1 change: 0 additions & 1 deletion error/s2n_errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ typedef enum {
S2N_ERR_ASYNC_CALLBACK_FAILED,
S2N_ERR_ASYNC_MORE_THAN_ONE,
S2N_ERR_PQ_CRYPTO,
S2N_ERR_PQ_DISABLED,
S2N_ERR_INVALID_CERT_STATE,
S2N_ERR_INVALID_EARLY_DATA_STATE,
S2N_ERR_PKEY_CTX_INIT,
Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# permissions and limitations under the License.
#

OBJS = $(wildcard ../utils/*.o ../stuffer/*.o ../tls/*.o ../tls/*/*.o ../iana/*.o ../crypto/*.o ../error/*.o ../pq-crypto/*.o ../pq-crypto/kyber_r3/*.o)
OBJS = $(wildcard ../utils/*.o ../stuffer/*.o ../tls/*.o ../tls/*/*.o ../iana/*.o ../crypto/*.o ../error/*.o)

.PHONY : all
all: libs2n.a libs2n.so libs2n.dylib
Expand Down
Loading
Loading