Skip to content

Commit

Permalink
Better exiting if nullptr & replace some asserts in aes_ossl.c
Browse files Browse the repository at this point in the history
Add MAYO_5 and updates

Signed-off-by: Basil Hess <bhe@zurich.ibm.com>
  • Loading branch information
bhess committed May 28, 2024
1 parent 31bfdb5 commit e68b556
Show file tree
Hide file tree
Showing 54 changed files with 7,462 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .CMake/alg_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ option(OQS_ENABLE_SIG_MAYO "Enable mayo algorithm family" ON)
cmake_dependent_option(OQS_ENABLE_SIG_mayo_1 "" ON "OQS_ENABLE_SIG_MAYO" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_mayo_2 "" ON "OQS_ENABLE_SIG_MAYO" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_mayo_3 "" ON "OQS_ENABLE_SIG_MAYO" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_mayo_5 "" ON "OQS_ENABLE_SIG_MAYO" OFF)
##### OQS_COPY_FROM_UPSTREAM_FRAGMENT_ADD_ENABLE_BY_ALG_END

if((OQS_MINIMAL_BUILD STREQUAL "ON"))
Expand Down Expand Up @@ -521,6 +522,12 @@ if(OQS_DIST_X86_64_BUILD OR (OQS_USE_AVX2_INSTRUCTIONS))
endif()
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux")
if(OQS_DIST_X86_64_BUILD OR (OQS_USE_AVX2_INSTRUCTIONS))
cmake_dependent_option(OQS_ENABLE_SIG_mayo_5_avx2 "" ON "OQS_ENABLE_SIG_mayo_5" OFF)
endif()
endif()

##### OQS_COPY_FROM_UPSTREAM_FRAGMENT_ADD_ENABLE_BY_ALG_CONDITIONAL_END

# Set XKCP (Keccak) required for Sphincs AVX2 code even if OpenSSL3 SHA3 is used:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ All names other than `ML-KEM` and `ML-DSA` are subject to change. `liboqs` makes
<!--- OQS_TEMPLATE_FRAGMENT_LIST_SIGS_START -->
- **CRYSTALS-Dilithium**: Dilithium2, Dilithium3, Dilithium5
- **Falcon**: Falcon-512, Falcon-1024, Falcon-padded-512, Falcon-padded-1024
- **MAYO**: MAYO\_1, MAYO\_2, MAYO\_3
- **MAYO**: MAYO\_1, MAYO\_2, MAYO\_3, MAYO\_5†
- **ML-DSA**: ML-DSA-44-ipd (alias: ML-DSA-44), ML-DSA-65-ipd (alias: ML-DSA-65), ML-DSA-87-ipd (alias: ML-DSA-87)
- **SPHINCS+-SHA2**: SPHINCS+-SHA2-128f-simple, SPHINCS+-SHA2-128s-simple, SPHINCS+-SHA2-192f-simple, SPHINCS+-SHA2-192s-simple, SPHINCS+-SHA2-256f-simple, SPHINCS+-SHA2-256s-simple
- **SPHINCS+-SHAKE**: SPHINCS+-SHAKE-128f-simple, SPHINCS+-SHAKE-128s-simple, SPHINCS+-SHAKE-192f-simple, SPHINCS+-SHAKE-192s-simple, SPHINCS+-SHAKE-256f-simple, SPHINCS+-SHAKE-256s-simple
Expand Down
10 changes: 10 additions & 0 deletions docs/algorithms/sig/mayo.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
| MAYO\_1 | NA | EUF-CMA | 1 | 1168 | 24 | 321 |
| MAYO\_2 | NA | EUF-CMA | 1 | 5488 | 24 | 180 |
| MAYO\_3 | NA | EUF-CMA | 3 | 2656 | 32 | 577 |
| MAYO\_5 | NA | EUF-CMA | 5 | 5008 | 40 | 838 |

## MAYO\_1 implementation characteristics

Expand Down Expand Up @@ -47,6 +48,15 @@ Are implementations chosen based on runtime CPU feature detection? **Yes**.

Are implementations chosen based on runtime CPU feature detection? **Yes**.

## MAYO\_5 implementation characteristics

| Implementation source | Identifier in upstream | Supported architecture(s) | Supported operating system(s) | CPU extension(s) used | No branching-on-secrets claimed? | No branching-on-secrets checked by valgrind? | Large stack usage? |
|:---------------------------------:|:-------------------------|:----------------------------|:--------------------------------|:------------------------|:-----------------------------------|:-----------------------------------------------|:---------------------|
| [Primary Source](#primary-source) | opt | All | All | None | True | True | False |
| [Primary Source](#primary-source) | avx2 | x86\_64 | Darwin,Linux | AVX2 | True | True | True |

Are implementations chosen based on runtime CPU feature detection? **Yes**.

## Explanation of Terms

- **Large Stack Usage**: Implementations identified as having such may cause failures when running in threads or in constrained environments.
31 changes: 31 additions & 0 deletions docs/algorithms/sig/mayo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,34 @@ parameter-sets:
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- name: MAYO_5
claimed-nist-level: 5
claimed-security: EUF-CMA
length-public-key: 5008
length-secret-key: 40
length-signature: 838
implementations-switch-on-runtime-cpu-features: true
implementations:
- upstream: primary-upstream
upstream-id: opt
supported-platforms: all
common-crypto:
- SHA3: liboqs
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- upstream: primary-upstream
upstream-id: avx2
supported-platforms:
- architecture: x86_64
operating_systems:
- Darwin
- Linux
required_flags:
- avx2
common-crypto:
- SHA3: liboqs
- AES: liboqs
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: true
71 changes: 64 additions & 7 deletions docs/cbom.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"bomFormat": "CBOM",
"specVersion": "1.4-cbom-1.0",
"serialNumber": "urn:uuid:0366b737-0d62-4de3-92e9-adfae8c1326a",
"serialNumber": "urn:uuid:dbce4160-9dc5-450c-b83c-0cb0345d7045",
"version": 1,
"metadata": {
"timestamp": "2024-05-08T14:51:11.690367",
"timestamp": "2024-05-24T18:35:02.761477",
"component": {
"type": "library",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@248c78af58129f2d59faed9cace2567c82d1b992",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@580d494efeee25edd354eaa2e0fe6581d552b827",
"name": "liboqs",
"version": "248c78af58129f2d59faed9cace2567c82d1b992"
"version": "580d494efeee25edd354eaa2e0fe6581d552b827"
}
},
"components": [
{
"type": "library",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@248c78af58129f2d59faed9cace2567c82d1b992",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@580d494efeee25edd354eaa2e0fe6581d552b827",
"name": "liboqs",
"version": "248c78af58129f2d59faed9cace2567c82d1b992"
"version": "580d494efeee25edd354eaa2e0fe6581d552b827"
},
{
"type": "crypto-asset",
Expand Down Expand Up @@ -1659,6 +1659,46 @@
"nistQuantumSecurityLevel": 3
}
},
{
"type": "crypto-asset",
"bom-ref": "alg:MAYO_5:generic",
"name": "MAYO",
"cryptoProperties": {
"assetType": "algorithm",
"algorithmProperties": {
"variant": "MAYO_5",
"primitive": "signature",
"implementationLevel": "softwarePlainRam",
"cryptoFunctions": [
"keygen",
"sign",
"verify"
],
"implementationPlatform": "generic"
},
"nistQuantumSecurityLevel": 5
}
},
{
"type": "crypto-asset",
"bom-ref": "alg:MAYO_5:x86_64",
"name": "MAYO",
"cryptoProperties": {
"assetType": "algorithm",
"algorithmProperties": {
"variant": "MAYO_5",
"primitive": "signature",
"implementationLevel": "softwarePlainRam",
"cryptoFunctions": [
"keygen",
"sign",
"verify"
],
"implementationPlatform": "x86_64"
},
"nistQuantumSecurityLevel": 5
}
},
{
"type": "crypto-asset",
"bom-ref": "alg:ML-DSA-44-ipd:generic",
Expand Down Expand Up @@ -2288,7 +2328,7 @@
],
"dependencies": [
{
"ref": "pkg:github/open-quantum-safe/liboqs@248c78af58129f2d59faed9cace2567c82d1b992",
"ref": "pkg:github/open-quantum-safe/liboqs@580d494efeee25edd354eaa2e0fe6581d552b827",
"dependsOn": [
"alg:BIKE-L1:x86_64",
"alg:BIKE-L3:x86_64",
Expand Down Expand Up @@ -2372,6 +2412,8 @@
"alg:MAYO_2:x86_64",
"alg:MAYO_3:generic",
"alg:MAYO_3:x86_64",
"alg:MAYO_5:generic",
"alg:MAYO_5:x86_64",
"alg:ML-DSA-44-ipd:generic",
"alg:ML-DSA-44-ipd:x86_64",
"alg:ML-DSA-65-ipd:generic",
Expand Down Expand Up @@ -3016,6 +3058,21 @@
],
"dependencyType": "uses"
},
{
"ref": "alg:MAYO_5:generic",
"dependsOn": [
"alg:sha3"
],
"dependencyType": "uses"
},
{
"ref": "alg:MAYO_5:x86_64",
"dependsOn": [
"alg:sha3",
"alg:aes"
],
"dependencyType": "uses"
},
{
"ref": "alg:ML-DSA-44-ipd:generic",
"dependsOn": [
Expand Down
5 changes: 5 additions & 0 deletions scripts/copy_from_upstream/copy_from_upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,8 @@ sigs:
pqclean_scheme: mayo_3
pretty_name_full: MAYO_3
signed_msg_order: sig_then_msg
-
scheme: "5"
pqclean_scheme: mayo_5
pretty_name_full: MAYO_5
signed_msg_order: sig_then_msg
14 changes: 8 additions & 6 deletions src/common/aes/aes_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void AES128_ECB_enc_sch(const uint8_t *plaintext, const size_t plaintext_

static void AES128_CTR_inc_stream_iv(const uint8_t *iv, size_t iv_len, const void *schedule, uint8_t *out, size_t out_len) {
EVP_CIPHER_CTX *ctr_ctx = OSSL_FUNC(EVP_CIPHER_CTX_new());
assert(ctr_ctx != NULL);
OQS_EXIT_IF_NULLPTR(ctr_ctx, "OpenSSL");
uint8_t iv_ctr[16];
if (iv_len == 12) {
memcpy(iv_ctr, iv, 12);
Expand All @@ -94,11 +94,12 @@ static void AES128_CTR_inc_stream_iv(const uint8_t *iv, size_t iv_len, const voi

static void AES128_CTR_inc_init(const uint8_t *key, void **schedule) {
*schedule = malloc(sizeof(struct key_schedule));
OQS_EXIT_IF_NULLPTR(*schedule, "OpenSSL");

struct key_schedule *ks = (struct key_schedule *) *schedule;
EVP_CIPHER_CTX *ctr_ctx = OSSL_FUNC(EVP_CIPHER_CTX_new)();
assert(ctr_ctx != NULL);
OQS_EXIT_IF_NULLPTR(ctr_ctx, "OpenSSL");

OQS_EXIT_IF_NULLPTR(*schedule, "OpenSSL");
ks->for_ECB = 0;
ks->ctx = ctr_ctx;
memcpy(ks->key, key, 16);
Expand Down Expand Up @@ -139,11 +140,12 @@ static void AES256_ECB_load_schedule(const uint8_t *key, void **schedule) {

static void AES256_CTR_inc_init(const uint8_t *key, void **schedule) {
*schedule = malloc(sizeof(struct key_schedule));
OQS_EXIT_IF_NULLPTR(*schedule, "OpenSSL");

struct key_schedule *ks = (struct key_schedule *) *schedule;
EVP_CIPHER_CTX *ctr_ctx = OSSL_FUNC(EVP_CIPHER_CTX_new)();
assert(ctr_ctx != NULL);
OQS_EXIT_IF_NULLPTR(ctr_ctx, "OpenSSL");

OQS_EXIT_IF_NULLPTR(*schedule, "OpenSSL");
ks->for_ECB = 0;
ks->ctx = ctr_ctx;
memcpy(ks->key, key, 32);
Expand Down Expand Up @@ -190,7 +192,7 @@ static void AES256_ECB_enc_sch(const uint8_t *plaintext, const size_t plaintext_

static void AES256_CTR_inc_stream_iv(const uint8_t *iv, size_t iv_len, const void *schedule, uint8_t *out, size_t out_len) {
EVP_CIPHER_CTX *ctr_ctx = OSSL_FUNC(EVP_CIPHER_CTX_new)();
assert(ctr_ctx != NULL);
OQS_EXIT_IF_NULLPTR(ctr_ctx, "OpenSSL");
uint8_t iv_ctr[16];
if (iv_len == 12) {
memcpy(iv_ctr, iv, 12);
Expand Down
2 changes: 2 additions & 0 deletions src/oqsconfig.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,6 @@
#cmakedefine OQS_ENABLE_SIG_mayo_2_avx2 1
#cmakedefine OQS_ENABLE_SIG_mayo_3 1
#cmakedefine OQS_ENABLE_SIG_mayo_3_avx2 1
#cmakedefine OQS_ENABLE_SIG_mayo_5 1
#cmakedefine OQS_ENABLE_SIG_mayo_5_avx2 1
///// OQS_COPY_FROM_UPSTREAM_FRAGMENT_ADD_ALG_ENABLE_DEFINES_END
18 changes: 18 additions & 0 deletions src/sig/mayo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,22 @@ if(OQS_ENABLE_SIG_mayo_3_avx2)
set(_MAYO_OBJS ${_MAYO_OBJS} $<TARGET_OBJECTS:mayo_3_avx2>)
endif()

if(OQS_ENABLE_SIG_mayo_5)
add_library(mayo_5_opt OBJECT sig_mayo_5.c pqmayo_mayo_5_opt/api.c pqmayo_mayo_5_opt/arithmetic.c pqmayo_mayo_5_opt/mayo.c pqmayo_mayo_5_opt/params.c)
target_compile_options(mayo_5_opt PUBLIC -DMAYO_VARIANT=MAYO_5 -DMAYO_BUILD_TYPE_OPT -DHAVE_RANDOMBYTES_NORETVAL -DHAVE_STACKEFFICIENT)
target_include_directories(mayo_5_opt PRIVATE ${CMAKE_CURRENT_LIST_DIR}/pqmayo_mayo_5_opt)
target_include_directories(mayo_5_opt PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims)
target_compile_options(mayo_5_opt PUBLIC -DMAYO_VARIANT=MAYO_5 -DMAYO_BUILD_TYPE_OPT -DHAVE_RANDOMBYTES_NORETVAL -DHAVE_STACKEFFICIENT)
set(_MAYO_OBJS ${_MAYO_OBJS} $<TARGET_OBJECTS:mayo_5_opt>)
endif()

if(OQS_ENABLE_SIG_mayo_5_avx2)
add_library(mayo_5_avx2 OBJECT pqmayo_mayo_5_avx2/api.c pqmayo_mayo_5_avx2/arithmetic.c pqmayo_mayo_5_avx2/mayo.c pqmayo_mayo_5_avx2/params.c)
target_include_directories(mayo_5_avx2 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/pqmayo_mayo_5_avx2)
target_include_directories(mayo_5_avx2 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims)
target_compile_options(mayo_5_avx2 PRIVATE -mavx2)
target_compile_options(mayo_5_avx2 PUBLIC -DMAYO_VARIANT=MAYO_5 -DMAYO_BUILD_TYPE_AVX2 -DMAYO_AVX -DHAVE_RANDOMBYTES_NORETVAL -DHAVE_STACKEFFICIENT)
set(_MAYO_OBJS ${_MAYO_OBJS} $<TARGET_OBJECTS:mayo_5_avx2>)
endif()

set(MAYO_OBJS ${_MAYO_OBJS} PARENT_SCOPE)
Loading

0 comments on commit e68b556

Please sign in to comment.