diff --git a/.CMake/alg_support.cmake b/.CMake/alg_support.cmake index 144bf98c92..e3b18805fa 100644 --- a/.CMake/alg_support.cmake +++ b/.CMake/alg_support.cmake @@ -178,6 +178,9 @@ option(OQS_ENABLE_SIG_ML_DSA "Enable ml_dsa algorithm family" ON) cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_44 "" ON "OQS_ENABLE_SIG_ML_DSA" OFF) cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_65 "" ON "OQS_ENABLE_SIG_ML_DSA" OFF) cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_87 "" ON "OQS_ENABLE_SIG_ML_DSA" OFF) +cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_44_extmu "" ON "OQS_ENABLE_SIG_ML_DSA" OFF) +cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_65_extmu "" ON "OQS_ENABLE_SIG_ML_DSA" OFF) +cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_87_extmu "" ON "OQS_ENABLE_SIG_ML_DSA" OFF) option(OQS_ENABLE_SIG_FALCON "Enable falcon algorithm family" ON) cmake_dependent_option(OQS_ENABLE_SIG_falcon_512 "" ON "OQS_ENABLE_SIG_FALCON" OFF) @@ -672,6 +675,42 @@ if(OQS_DIST_ARM64_V8_BUILD OR (OQS_USE_ARM_NEON_INSTRUCTIONS AND OQS_USE_ARM_NEO endif() endif() +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") +if(OQS_DIST_X86_64_BUILD OR (OQS_USE_AVX2_INSTRUCTIONS AND OQS_USE_BMI2_INSTRUCTIONS AND OQS_USE_POPCNT_INSTRUCTIONS)) + cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64 "" ON "OQS_ENABLE_SIG_ml_dsa_44_extmu" OFF) +endif() +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") +if(OQS_DIST_ARM64_V8_BUILD OR (OQS_USE_ARM_NEON_INSTRUCTIONS AND OQS_USE_ARM_NEON_INSTRUCTIONS)) + cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64 "" ON "OQS_ENABLE_SIG_ml_dsa_44_extmu" OFF) +endif() +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") +if(OQS_DIST_X86_64_BUILD OR (OQS_USE_AVX2_INSTRUCTIONS AND OQS_USE_BMI2_INSTRUCTIONS AND OQS_USE_POPCNT_INSTRUCTIONS)) + cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64 "" ON "OQS_ENABLE_SIG_ml_dsa_65_extmu" OFF) +endif() +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") +if(OQS_DIST_ARM64_V8_BUILD OR (OQS_USE_ARM_NEON_INSTRUCTIONS AND OQS_USE_ARM_NEON_INSTRUCTIONS)) + cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64 "" ON "OQS_ENABLE_SIG_ml_dsa_65_extmu" OFF) +endif() +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") +if(OQS_DIST_X86_64_BUILD OR (OQS_USE_AVX2_INSTRUCTIONS AND OQS_USE_BMI2_INSTRUCTIONS AND OQS_USE_POPCNT_INSTRUCTIONS)) + cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64 "" ON "OQS_ENABLE_SIG_ml_dsa_87_extmu" OFF) +endif() +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin") +if(OQS_DIST_ARM64_V8_BUILD OR (OQS_USE_ARM_NEON_INSTRUCTIONS AND OQS_USE_ARM_NEON_INSTRUCTIONS)) + cmake_dependent_option(OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64 "" ON "OQS_ENABLE_SIG_ml_dsa_87_extmu" OFF) +endif() +endif() + if(OQS_DIST_X86_64_BUILD OR (OQS_USE_AVX2_INSTRUCTIONS)) cmake_dependent_option(OQS_ENABLE_SIG_falcon_512_avx2 "" ON "OQS_ENABLE_SIG_falcon_512" OFF) diff --git a/scripts/copy_from_upstream/copy_from_upstream.py b/scripts/copy_from_upstream/copy_from_upstream.py index 136cf56bc3..955e7b52fa 100755 --- a/scripts/copy_from_upstream/copy_from_upstream.py +++ b/scripts/copy_from_upstream/copy_from_upstream.py @@ -628,6 +628,23 @@ def handle_implementation(impl, family, scheme, dst_basedir): def process_families(instructions, basedir, with_kat, with_generator, with_libjade=False): for family in instructions['kems'] + instructions['sigs']: + extmu_variants = [] + for s in family['schemes']: + if 'metadata' in s and any('signature_signature_extmu' in imp for imp in s['metadata']['implementations']): + ext_s = copy.deepcopy(s) + ext_s['scheme'] += "_extmu" + ext_s['scheme_c'] += "_extmu" + ext_s['pretty_name_full'] += "-extmu" + ext_s['is_extmu'] = True + for imp in ext_s['metadata']['implementations']: + if 'signature_signature_extmu' in imp: + imp['signature_signature'] = imp['signature_signature_extmu'] + if 'signature_verify_extmu' in imp: + imp['signature_verify'] = imp['signature_verify_extmu'] + imp['api-with-context-string'] = False + extmu_variants.append(ext_s) + family['schemes'].extend(extmu_variants) + try: os.makedirs(os.path.join(basedir, 'src', family['type'], family['name'])) except: @@ -699,8 +716,7 @@ def process_families(instructions, basedir, with_kat, with_generator, with_libja scheme['scheme'], str(ke), impl['name'])) pass - - if with_kat: + if with_kat and not scheme.get('is_extmu', False): if family in instructions['kems']: try: if kats['kem'][scheme['pretty_name_full']]['single'] != scheme['metadata']['nistkat-sha256']: diff --git a/scripts/copy_from_upstream/src/sig/family/CMakeLists.txt b/scripts/copy_from_upstream/src/sig/family/CMakeLists.txt index d5db314e29..23a73a4910 100644 --- a/scripts/copy_from_upstream/src/sig/family/CMakeLists.txt +++ b/scripts/copy_from_upstream/src/sig/family/CMakeLists.txt @@ -26,10 +26,12 @@ endif() {%- endif %} {%- for scheme in schemes -%} + {%- if not scheme.is_extmu %} + {%- set has_extmu = (schemes | selectattr("scheme_c", "equalto", scheme['scheme_c'] ~ "_extmu") | list | length > 0) %} {%- for impl in scheme['metadata']['implementations'] -%} {%- if impl['name'] == scheme['default_implementation'] %} -if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}{%- if 'alias_scheme' in scheme %} OR OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}{%- endif %}) +if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}{%- if 'alias_scheme' in scheme %} OR OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}{%- endif %}{%- if has_extmu %} OR OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}_extmu{%- endif %}) add_library({{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }} OBJECT sig_{{ family }}_{{ scheme['scheme'] }}.c {% for source_file in impl['sources']|sort -%}{{ impl['upstream']['name'] }}_{{ scheme['pqclean_scheme'] }}_{{ impl['name'] }}/{{ source_file }}{%- if not loop.last %} {% endif -%}{%- endfor -%}{%- if common_deps is defined %}{%- for cdep in common_deps %}{%- if cdep['include_only'] and 'common_dep' in impl and cdep['name'] in impl['common_dep'] %} {% for sf in cdep['sources_addl']|sort -%}{{ upstream_location }}_{{ cdep['name'] }}/{{ sf }}{%- if not loop.last %} {% endif -%}{%- endfor %}{%- endif %}{%- endfor %}{%- endif -%}) {%- if impl['compile_opts'] %} target_compile_options({{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }} PUBLIC {{ impl['compile_opts'] }}) @@ -37,7 +39,7 @@ if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}{%- if 'alias_scheme' in {%- else %} -if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}_{{ impl['name'] }}{%- if 'alias_scheme' in scheme %} OR OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}_{{ impl['name'] }}{%- endif %}) +if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}_{{ impl['name'] }}{%- if 'alias_scheme' in scheme %} OR OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}_{{ impl['name'] }}{%- endif %}{%- if has_extmu %} OR OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}_extmu_{{ impl['name'] }}{%- endif %}) add_library({{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }} OBJECT {% for source_file in impl['sources']|sort -%}{{ impl['upstream']['name'] }}_{{ scheme['pqclean_scheme'] }}_{{ impl['name'] }}/{{ source_file }}{%- if not loop.last %} {% endif -%}{%- endfor -%}{%- if common_deps is defined %}{%- for cdep in common_deps %}{%- if cdep['include_only'] and 'common_dep' in impl and cdep['name'] in impl['common_dep'] %} {% for sf in cdep['sources_addl']|sort -%}{{ upstream_location }}_{{ cdep['name'] }}/{{ sf }}{%- if not loop.last %} {% endif -%}{%- endfor %}{%- endif %}{%- endfor %}{%- endif -%}) {%- endif %} target_include_directories({{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/{{ impl['upstream']['name'] }}_{{ scheme['pqclean_scheme'] }}_{{ impl['name'] }}) @@ -57,7 +59,17 @@ if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}_{{ impl['name'] }}{%- if {%- endif %} set(_{{ family|upper }}_OBJS ${_{{ family|upper }}_OBJS} $) endif() - {%- endfor -%} + {%- endfor %} + {%- else %} + +if(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme_c'] }}) + add_library({{ family }}_{{ scheme['scheme'] }} OBJECT sig_{{ family }}_{{ scheme['scheme'] }}.c) + {%- set base_pqclean = scheme['pqclean_scheme'] | replace('-extmu', '') %} + target_include_directories({{ family }}_{{ scheme['scheme'] }} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/{{ scheme['metadata']['implementations'][0]['upstream']['name'] }}_{{ base_pqclean }}_{{ scheme['default_implementation'] }}) + target_include_directories({{ family }}_{{ scheme['scheme'] }} PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) + set(_{{ family|upper }}_OBJS ${_{{ family|upper }}_OBJS} $) +endif() + {%- endif %} {%- endfor %} set({{ family|upper }}_OBJS ${_{{ family|upper }}_OBJS} PARENT_SCOPE) diff --git a/scripts/copy_from_upstream/src/sig/family/sig_family.h b/scripts/copy_from_upstream/src/sig/family/sig_family.h index 63e571b656..bcf31bc198 100644 --- a/scripts/copy_from_upstream/src/sig/family/sig_family.h +++ b/scripts/copy_from_upstream/src/sig/family/sig_family.h @@ -11,6 +11,9 @@ #define OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_public_key {{ scheme['metadata']['length-public-key'] }} #define OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_secret_key {{ scheme['metadata']['length-secret-key'] }} #define OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_signature {{ scheme['metadata']['length-signature'] }} +{%- if scheme.is_extmu and 'length-mu' in scheme['metadata'] %} +#define OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu {{ scheme['metadata']['length-mu'] }} +{%- endif %} OQS_SIG *OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_new(void); OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_keypair(uint8_t *public_key, uint8_t *secret_key); diff --git a/scripts/copy_from_upstream/src/sig/family/sig_scheme.c b/scripts/copy_from_upstream/src/sig/family/sig_scheme.c index fc0a910a3a..6235b36f9a 100644 --- a/scripts/copy_from_upstream/src/sig/family/sig_scheme.c +++ b/scripts/copy_from_upstream/src/sig/family/sig_scheme.c @@ -99,7 +99,7 @@ extern int {{ scheme['metadata']['default_keypair_signature'] }}(uint8_t *pk, ui {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} extern int {{ scheme['metadata']['default_signature_signature'] }}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *ctx, size_t ctxlen, const uint8_t *sk); {%- else %} -extern int {{ scheme['metadata']['default_signature_signature'] }}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk); +extern int {{ scheme['metadata']['default_signature_signature'] }}(uint8_t *sig, size_t *siglen, const uint8_t *m, {% if not scheme.is_extmu %}size_t mlen, {% endif %}const uint8_t *sk); {%- endif %} {%- if impl['signature_verify'] %} @@ -110,7 +110,7 @@ extern int {{ scheme['metadata']['default_signature_signature'] }}(uint8_t *sig, {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} extern int {{ scheme['metadata']['default_verify_signature'] }}(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *ctx, size_t ctxlen, const uint8_t *pk); {%- else %} -extern int {{ scheme['metadata']['default_verify_signature'] }}(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk); +extern int {{ scheme['metadata']['default_verify_signature'] }}(const uint8_t *sig, size_t siglen, const uint8_t *m, {% if not scheme.is_extmu %}size_t mlen, {% endif %}const uint8_t *pk); {%- endif %} {%- endfor %} @@ -128,20 +128,20 @@ extern int PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} extern int {{ impl['signature_signature'] }}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *ctx, size_t ctxlen, const uint8_t *sk); {%- else %} -extern int {{ impl['signature_signature'] }}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk); +extern int {{ impl['signature_signature'] }}(uint8_t *sig, size_t *siglen, const uint8_t *m, {% if not scheme.is_extmu %}size_t mlen, {% endif %}const uint8_t *sk); {%- endif %} {%- else %} -extern int PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk); +extern int PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_signature(uint8_t *sig, size_t *siglen, const uint8_t *m, {% if not scheme.is_extmu %}size_t mlen, {% endif %}const uint8_t *sk); {%- endif %} {%- if impl['signature_verify'] %} {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} extern int {{ impl['signature_verify'] }}(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *ctx, size_t ctxlen, const uint8_t *pk); {%- else %} -extern int {{ impl['signature_verify'] }}(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk); +extern int {{ impl['signature_verify'] }}(const uint8_t *sig, size_t siglen, const uint8_t *m, {% if not scheme.is_extmu %}size_t mlen, {% endif %}const uint8_t *pk); {%- endif %} {%- else %} -extern int PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk); +extern int PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_verify(const uint8_t *sig, size_t siglen, const uint8_t *m, {% if not scheme.is_extmu %}size_t mlen, {% endif %}const uint8_t *pk); {%- endif %} #endif {%- endfor %} @@ -181,6 +181,11 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_keypair(uint8_t * } OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) { +{%- if scheme.is_extmu %} + if (message_len != OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu) { + return OQS_ERROR; + } +{%- endif %} {%- for impl in scheme['metadata']['implementations'] if impl['name'] != scheme['default_implementation'] %} {%- if loop.first %} #if defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }}) {%- if 'alias_scheme' in scheme %} || defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}_{{ impl['name'] }}){%- endif %} @@ -196,10 +201,10 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign(uint8_t *sig {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) {{ impl['signature_signature'] }}(signature, signature_len, message, message_len, NULL, 0, secret_key); {%- else %} - {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) {{ impl['signature_signature'] }}(signature, signature_len, message, message_len, secret_key); + {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) {{ impl['signature_signature'] }}(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}secret_key); {%- endif %} {%- else %} - {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_signature(signature, signature_len, message, message_len, secret_key); + {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_signature(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}secret_key); {%- endif %} {%- if impl.get('required_flags', false) %} #if defined(OQS_DIST_BUILD) @@ -207,7 +212,7 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign(uint8_t *sig {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} return (OQS_STATUS) {{ scheme['metadata']['default_signature_signature'] }}(signature, signature_len, message, message_len, NULL, 0, secret_key); {%- else %} - return (OQS_STATUS) {{ scheme['metadata']['default_signature_signature'] }}(signature, signature_len, message, message_len, secret_key); + return (OQS_STATUS) {{ scheme['metadata']['default_signature_signature'] }}(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}secret_key); {%- endif %} } #endif /* OQS_DIST_BUILD */ @@ -220,7 +225,7 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign(uint8_t *sig {%- if 'api-with-context-string' in default_impl and default_impl['api-with-context-string'] %} return (OQS_STATUS) {{ scheme['metadata']['default_signature_signature'] }}(signature, signature_len, message, message_len, NULL, 0, secret_key); {%- else %} - return (OQS_STATUS) {{ scheme['metadata']['default_signature_signature'] }}(signature, signature_len, message, message_len, secret_key); + return (OQS_STATUS) {{ scheme['metadata']['default_signature_signature'] }}(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}secret_key); {%- endif %} {%- if scheme['metadata']['implementations']|rejectattr('name', 'equalto', scheme['default_implementation'])|list %} #endif @@ -228,6 +233,11 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign(uint8_t *sig } OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) { +{%- if scheme.is_extmu %} + if (message_len != OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu) { + return OQS_ERROR; + } +{%- endif %} {%- for impl in scheme['metadata']['implementations'] if impl['name'] != scheme['default_implementation'] %} {%- if loop.first %} #if defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }}) {%- if 'alias_scheme' in scheme %} || defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}_{{ impl['name'] }}){%- endif %} @@ -243,10 +253,10 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify(const uint {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) {{ impl['signature_verify'] }}(signature, signature_len, message, message_len, NULL, 0, public_key); {%- else %} - {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) {{ impl['signature_verify'] }}(signature, signature_len, message, message_len, public_key); + {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) {{ impl['signature_verify'] }}(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}public_key); {%- endif %} {%- else %} - {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_verify(signature, signature_len, message, message_len, public_key); + {% if impl.get('required_flags', false) %} {% endif %}return (OQS_STATUS) PQCLEAN_{{ scheme['pqclean_scheme_c']|upper }}_{{ impl['name']|upper }}_crypto_sign_verify(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}public_key); {%- endif %} {%- if impl.get('required_flags', false) %} #if defined(OQS_DIST_BUILD) @@ -254,7 +264,7 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify(const uint {%- if 'api-with-context-string' in impl and impl['api-with-context-string'] %} return (OQS_STATUS) {{ scheme['metadata']['default_verify_signature'] }}(signature, signature_len, message, message_len, NULL, 0, public_key); {%- else %} - return (OQS_STATUS) {{ scheme['metadata']['default_verify_signature'] }}(signature, signature_len, message, message_len, public_key); + return (OQS_STATUS) {{ scheme['metadata']['default_verify_signature'] }}(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}public_key); {%- endif %} } #endif /* OQS_DIST_BUILD */ @@ -267,7 +277,7 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify(const uint {%- if 'api-with-context-string' in default_impl and default_impl['api-with-context-string'] %} return (OQS_STATUS) {{ scheme['metadata']['default_verify_signature'] }}(signature, signature_len, message, message_len, NULL, 0, public_key); {%- else %} - return (OQS_STATUS) {{ scheme['metadata']['default_verify_signature'] }}(signature, signature_len, message, message_len, public_key); + return (OQS_STATUS) {{ scheme['metadata']['default_verify_signature'] }}(signature, signature_len, message, {% if not scheme.is_extmu %}message_len, {% endif %}public_key); {%- endif %} {%- if scheme['metadata']['implementations']|rejectattr('name', 'equalto', scheme['default_implementation'])|list %} #endif @@ -277,6 +287,11 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify(const uint {%- set default_impl = scheme['metadata']['implementations'] | selectattr("name", "equalto", scheme['default_implementation']) | first %} {%- if 'api-with-context-string' in default_impl and default_impl['api-with-context-string'] %} OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *secret_key) { +{%- if scheme.is_extmu %} + if (message_len != OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu) { + return OQS_ERROR; + } +{%- endif %} {%- for impl in scheme['metadata']['implementations'] if impl['name'] != scheme['default_implementation'] %} {%- if loop.first %} #if defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }}) {%- if 'alias_scheme' in scheme %} || defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}_{{ impl['name'] }}){%- endif %} @@ -312,6 +327,11 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign_with_ctx_str } OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *public_key) { +{%- if scheme.is_extmu %} + if (message_len != OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu) { + return OQS_ERROR; + } +{%- endif %} {%- for impl in scheme['metadata']['implementations'] if impl['name'] != scheme['default_implementation'] %} {%- if loop.first %} #if defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['scheme'] }}_{{ impl['name'] }}) {%- if 'alias_scheme' in scheme %} || defined(OQS_ENABLE_SIG_{{ family }}_{{ scheme['alias_scheme'] }}_{{ impl['name'] }}){%- endif %} @@ -348,6 +368,11 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify_with_ctx_s {%- else %} OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *secret_key) { +{%- if scheme.is_extmu %} + if (message_len != OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu) { + return OQS_ERROR; + } +{%- endif %} if (ctx_str == NULL && ctx_str_len == 0) { return OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign(signature, signature_len, message, message_len, secret_key); } else { @@ -356,6 +381,11 @@ OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_sign_with_ctx_str } OQS_API OQS_STATUS OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *public_key) { +{%- if scheme.is_extmu %} + if (message_len != OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_length_mu) { + return OQS_ERROR; + } +{%- endif %} if (ctx_str == NULL && ctx_str_len == 0) { return OQS_SIG_{{ family }}_{{ scheme['scheme'] }}_verify(message, message_len, signature, signature_len, public_key); } else { diff --git a/scripts/copy_from_upstream/tests/kat_sig.c/combine_message_signature.fragment b/scripts/copy_from_upstream/tests/kat_sig.c/combine_message_signature.fragment index 2e6c215056..5869054b70 100644 --- a/scripts/copy_from_upstream/tests/kat_sig.c/combine_message_signature.fragment +++ b/scripts/copy_from_upstream/tests/kat_sig.c/combine_message_signature.fragment @@ -1,4 +1,5 @@ {% for family in instructions['sigs'] %}{% for scheme in family['schemes'] %} +{%- if not scheme.get('is_extmu', False) %} } else if (0 == strcmp(sig->method_name, "{{ scheme['pretty_name_full'] }}"){%- if 'alias_scheme' in scheme %} || 0 == strcmp(sig->method_name, "{{ scheme['alias_pretty_name_full'] }}"){%- endif -%}) { {%- if scheme['signed_msg_order'] == 'sig_then_msg' %} // signed_msg = signature || msg @@ -63,5 +64,4 @@ {%- else %} // not yet implemented return OQS_ERROR; -{%- endif %}{% endfor %}{% endfor %} - +{%- endif %}{%- endif %}{%- endfor %}{% endfor %} diff --git a/src/oqsconfig.h.cmake b/src/oqsconfig.h.cmake index 5ff0f3c781..5089b90c86 100644 --- a/src/oqsconfig.h.cmake +++ b/src/oqsconfig.h.cmake @@ -176,6 +176,15 @@ #cmakedefine OQS_ENABLE_SIG_ml_dsa_87 1 #cmakedefine OQS_ENABLE_SIG_ml_dsa_87_x86_64 1 #cmakedefine OQS_ENABLE_SIG_ml_dsa_87_aarch64 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_44_extmu 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_65_extmu 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_87_extmu 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64 1 +#cmakedefine OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64 1 #cmakedefine OQS_ENABLE_SIG_FALCON 1 #cmakedefine OQS_ENABLE_SIG_falcon_512 1 diff --git a/src/sig/ml_dsa/CMakeLists.txt b/src/sig/ml_dsa/CMakeLists.txt index 730bcb5c82..d3748971dc 100644 --- a/src/sig/ml_dsa/CMakeLists.txt +++ b/src/sig/ml_dsa/CMakeLists.txt @@ -5,7 +5,7 @@ set(_ML_DSA_OBJS "") -if(OQS_ENABLE_SIG_ml_dsa_44) +if(OQS_ENABLE_SIG_ml_dsa_44 OR OQS_ENABLE_SIG_ml_dsa_44_extmu) add_library(ml_dsa_44_ref OBJECT sig_ml_dsa_44.c mldsa-native_ml-dsa-44_ref/mldsa/src/ct.c mldsa-native_ml-dsa-44_ref/mldsa/src/debug.c mldsa-native_ml-dsa-44_ref/mldsa/src/packing.c mldsa-native_ml-dsa-44_ref/mldsa/src/poly.c mldsa-native_ml-dsa-44_ref/mldsa/src/poly_kl.c mldsa-native_ml-dsa-44_ref/mldsa/src/polyvec.c mldsa-native_ml-dsa-44_ref/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-44_ref/mldsa/src/sign.c) target_compile_options(ml_dsa_44_ref PUBLIC -DMLD_CONFIG_PARAMETER_SET=44 -DMLD_CONFIG_FILE="../../integration/liboqs/config_c.h") target_include_directories(ml_dsa_44_ref PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-44_ref) @@ -14,7 +14,7 @@ if(OQS_ENABLE_SIG_ml_dsa_44) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_44_x86_64) +if(OQS_ENABLE_SIG_ml_dsa_44_x86_64 OR OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64) add_library(ml_dsa_44_x86_64 OBJECT mldsa-native_ml-dsa-44_x86_64/mldsa/src/ct.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/debug.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/consts.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/intt_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/ntt_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/rej_uniform_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/native/x86_64/src/rej_uniform_table.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/packing.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/poly.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/poly_kl.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/polyvec.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-44_x86_64/mldsa/src/sign.c) target_include_directories(ml_dsa_44_x86_64 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-44_x86_64) target_include_directories(ml_dsa_44_x86_64 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) @@ -23,7 +23,7 @@ if(OQS_ENABLE_SIG_ml_dsa_44_x86_64) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_44_aarch64) +if(OQS_ENABLE_SIG_ml_dsa_44_aarch64 OR OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64) add_library(ml_dsa_44_aarch64 OBJECT mldsa-native_ml-dsa-44_aarch64/mldsa/src/ct.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/debug.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/aarch64_zetas.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/intt_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_table.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/native/aarch64/src/rej_uniform_table.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/packing.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/poly.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/poly_kl.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/polyvec.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-44_aarch64/mldsa/src/sign.c) target_include_directories(ml_dsa_44_aarch64 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-44_aarch64) target_include_directories(ml_dsa_44_aarch64 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) @@ -32,7 +32,7 @@ if(OQS_ENABLE_SIG_ml_dsa_44_aarch64) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_65) +if(OQS_ENABLE_SIG_ml_dsa_65 OR OQS_ENABLE_SIG_ml_dsa_65_extmu) add_library(ml_dsa_65_ref OBJECT sig_ml_dsa_65.c mldsa-native_ml-dsa-65_ref/mldsa/src/ct.c mldsa-native_ml-dsa-65_ref/mldsa/src/debug.c mldsa-native_ml-dsa-65_ref/mldsa/src/packing.c mldsa-native_ml-dsa-65_ref/mldsa/src/poly.c mldsa-native_ml-dsa-65_ref/mldsa/src/poly_kl.c mldsa-native_ml-dsa-65_ref/mldsa/src/polyvec.c mldsa-native_ml-dsa-65_ref/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-65_ref/mldsa/src/sign.c) target_compile_options(ml_dsa_65_ref PUBLIC -DMLD_CONFIG_PARAMETER_SET=65 -DMLD_CONFIG_FILE="../../integration/liboqs/config_c.h") target_include_directories(ml_dsa_65_ref PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-65_ref) @@ -41,7 +41,7 @@ if(OQS_ENABLE_SIG_ml_dsa_65) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_65_x86_64) +if(OQS_ENABLE_SIG_ml_dsa_65_x86_64 OR OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64) add_library(ml_dsa_65_x86_64 OBJECT mldsa-native_ml-dsa-65_x86_64/mldsa/src/ct.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/debug.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/consts.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/intt_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/ntt_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/rej_uniform_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/native/x86_64/src/rej_uniform_table.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/packing.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/poly.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/poly_kl.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/polyvec.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-65_x86_64/mldsa/src/sign.c) target_include_directories(ml_dsa_65_x86_64 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-65_x86_64) target_include_directories(ml_dsa_65_x86_64 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) @@ -50,7 +50,7 @@ if(OQS_ENABLE_SIG_ml_dsa_65_x86_64) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_65_aarch64) +if(OQS_ENABLE_SIG_ml_dsa_65_aarch64 OR OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64) add_library(ml_dsa_65_aarch64 OBJECT mldsa-native_ml-dsa-65_aarch64/mldsa/src/ct.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/debug.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/aarch64_zetas.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/intt_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_table.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/native/aarch64/src/rej_uniform_table.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/packing.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/poly.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/poly_kl.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/polyvec.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-65_aarch64/mldsa/src/sign.c) target_include_directories(ml_dsa_65_aarch64 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-65_aarch64) target_include_directories(ml_dsa_65_aarch64 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) @@ -59,7 +59,7 @@ if(OQS_ENABLE_SIG_ml_dsa_65_aarch64) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_87) +if(OQS_ENABLE_SIG_ml_dsa_87 OR OQS_ENABLE_SIG_ml_dsa_87_extmu) add_library(ml_dsa_87_ref OBJECT sig_ml_dsa_87.c mldsa-native_ml-dsa-87_ref/mldsa/src/ct.c mldsa-native_ml-dsa-87_ref/mldsa/src/debug.c mldsa-native_ml-dsa-87_ref/mldsa/src/packing.c mldsa-native_ml-dsa-87_ref/mldsa/src/poly.c mldsa-native_ml-dsa-87_ref/mldsa/src/poly_kl.c mldsa-native_ml-dsa-87_ref/mldsa/src/polyvec.c mldsa-native_ml-dsa-87_ref/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-87_ref/mldsa/src/sign.c) target_compile_options(ml_dsa_87_ref PUBLIC -DMLD_CONFIG_PARAMETER_SET=87 -DMLD_CONFIG_FILE="../../integration/liboqs/config_c.h") target_include_directories(ml_dsa_87_ref PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-87_ref) @@ -68,7 +68,7 @@ if(OQS_ENABLE_SIG_ml_dsa_87) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_87_x86_64) +if(OQS_ENABLE_SIG_ml_dsa_87_x86_64 OR OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64) add_library(ml_dsa_87_x86_64 OBJECT mldsa-native_ml-dsa-87_x86_64/mldsa/src/ct.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/debug.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/consts.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/intt_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/ntt_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/rej_uniform_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/native/x86_64/src/rej_uniform_table.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/packing.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/poly.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/poly_kl.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/polyvec.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-87_x86_64/mldsa/src/sign.c) target_include_directories(ml_dsa_87_x86_64 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-87_x86_64) target_include_directories(ml_dsa_87_x86_64 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) @@ -77,7 +77,7 @@ if(OQS_ENABLE_SIG_ml_dsa_87_x86_64) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() -if(OQS_ENABLE_SIG_ml_dsa_87_aarch64) +if(OQS_ENABLE_SIG_ml_dsa_87_aarch64 OR OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64) add_library(ml_dsa_87_aarch64 OBJECT mldsa-native_ml-dsa-87_aarch64/mldsa/src/ct.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/debug.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/aarch64_zetas.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/intt_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/polyz_unpack_table.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/native/aarch64/src/rej_uniform_table.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/packing.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/poly.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/poly_kl.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/polyvec.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/polyvec_lazy.c mldsa-native_ml-dsa-87_aarch64/mldsa/src/sign.c) target_include_directories(ml_dsa_87_aarch64 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-87_aarch64) target_include_directories(ml_dsa_87_aarch64 PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) @@ -86,4 +86,25 @@ if(OQS_ENABLE_SIG_ml_dsa_87_aarch64) set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) endif() +if(OQS_ENABLE_SIG_ml_dsa_44_extmu) + add_library(ml_dsa_44_extmu OBJECT sig_ml_dsa_44_extmu.c) + target_include_directories(ml_dsa_44_extmu PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-44_ref) + target_include_directories(ml_dsa_44_extmu PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) + set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) +endif() + +if(OQS_ENABLE_SIG_ml_dsa_65_extmu) + add_library(ml_dsa_65_extmu OBJECT sig_ml_dsa_65_extmu.c) + target_include_directories(ml_dsa_65_extmu PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-65_ref) + target_include_directories(ml_dsa_65_extmu PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) + set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) +endif() + +if(OQS_ENABLE_SIG_ml_dsa_87_extmu) + add_library(ml_dsa_87_extmu OBJECT sig_ml_dsa_87_extmu.c) + target_include_directories(ml_dsa_87_extmu PRIVATE ${CMAKE_CURRENT_LIST_DIR}/mldsa-native_ml-dsa-87_ref) + target_include_directories(ml_dsa_87_extmu PRIVATE ${PROJECT_SOURCE_DIR}/src/common/pqclean_shims) + set(_ML_DSA_OBJS ${_ML_DSA_OBJS} $) +endif() + set(ML_DSA_OBJS ${_ML_DSA_OBJS} PARENT_SCOPE) diff --git a/src/sig/ml_dsa/sig_ml_dsa.h b/src/sig/ml_dsa/sig_ml_dsa.h index e5f00f4387..fd64811e9d 100644 --- a/src/sig/ml_dsa/sig_ml_dsa.h +++ b/src/sig/ml_dsa/sig_ml_dsa.h @@ -44,4 +44,46 @@ OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_sign_with_ctx_str(uint8_t *signature, size_ OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *public_key); #endif +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) +#define OQS_SIG_ml_dsa_44_extmu_length_public_key 1312 +#define OQS_SIG_ml_dsa_44_extmu_length_secret_key 2560 +#define OQS_SIG_ml_dsa_44_extmu_length_signature 2420 +#define OQS_SIG_ml_dsa_44_extmu_length_mu 64 + +OQS_SIG *OQS_SIG_ml_dsa_44_extmu_new(void); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_keypair(uint8_t *public_key, uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *public_key); +#endif + +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) +#define OQS_SIG_ml_dsa_65_extmu_length_public_key 1952 +#define OQS_SIG_ml_dsa_65_extmu_length_secret_key 4032 +#define OQS_SIG_ml_dsa_65_extmu_length_signature 3309 +#define OQS_SIG_ml_dsa_65_extmu_length_mu 64 + +OQS_SIG *OQS_SIG_ml_dsa_65_extmu_new(void); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_keypair(uint8_t *public_key, uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *public_key); +#endif + +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) +#define OQS_SIG_ml_dsa_87_extmu_length_public_key 2592 +#define OQS_SIG_ml_dsa_87_extmu_length_secret_key 4896 +#define OQS_SIG_ml_dsa_87_extmu_length_signature 4627 +#define OQS_SIG_ml_dsa_87_extmu_length_mu 64 + +OQS_SIG *OQS_SIG_ml_dsa_87_extmu_new(void); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_keypair(uint8_t *public_key, uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *secret_key); +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx, size_t ctxlen, const uint8_t *public_key); +#endif + #endif diff --git a/src/sig/ml_dsa/sig_ml_dsa_44_extmu.c b/src/sig/ml_dsa/sig_ml_dsa_44_extmu.c new file mode 100644 index 0000000000..a49c9300fa --- /dev/null +++ b/src/sig/ml_dsa/sig_ml_dsa_44_extmu.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: MIT + +#include + +#include + +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) +OQS_SIG *OQS_SIG_ml_dsa_44_extmu_new(void) { + + OQS_SIG *sig = OQS_MEM_calloc(1, sizeof(OQS_SIG)); + if (sig == NULL) { + return NULL; + } + sig->method_name = OQS_SIG_alg_ml_dsa_44_extmu; + sig->alg_version = "FIPS204"; + + sig->claimed_nist_level = 2; + sig->euf_cma = true; + sig->suf_cma = true; + sig->sig_with_ctx_support = false; + + sig->length_public_key = OQS_SIG_ml_dsa_44_extmu_length_public_key; + sig->length_secret_key = OQS_SIG_ml_dsa_44_extmu_length_secret_key; + sig->length_signature = OQS_SIG_ml_dsa_44_extmu_length_signature; + + sig->keypair = OQS_SIG_ml_dsa_44_extmu_keypair; + sig->sign = OQS_SIG_ml_dsa_44_extmu_sign; + sig->verify = OQS_SIG_ml_dsa_44_extmu_verify; + sig->sign_with_ctx_str = OQS_SIG_ml_dsa_44_extmu_sign_with_ctx_str; + sig->verify_with_ctx_str = OQS_SIG_ml_dsa_44_extmu_verify_with_ctx_str; + + return sig; +} + +extern int PQCP_MLDSA_NATIVE_MLDSA44_C_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA44_C_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA44_C_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); + +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64) +extern int PQCP_MLDSA_NATIVE_MLDSA44_X86_64_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA44_X86_64_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA44_X86_64_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); +#endif + +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64) +extern int PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); +#endif + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_keypair(uint8_t *public_key, uint8_t *secret_key) { +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_X86_64_keypair(public_key, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_keypair(public_key, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_keypair(public_key, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_keypair(public_key, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_keypair(public_key, secret_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) { + if (message_len != OQS_SIG_ml_dsa_44_extmu_length_mu) { + return OQS_ERROR; + } +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_X86_64_signature_extmu(signature, signature_len, message, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_signature_extmu(signature, signature_len, message, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_signature_extmu(signature, signature_len, message, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_signature_extmu(signature, signature_len, message, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_signature_extmu(signature, signature_len, message, secret_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) { + if (message_len != OQS_SIG_ml_dsa_44_extmu_length_mu) { + return OQS_ERROR; + } +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_X86_64_verify_extmu(signature, signature_len, message, public_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_verify_extmu(signature, signature_len, message, public_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_44_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_AARCH64_verify_extmu(signature, signature_len, message, public_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_verify_extmu(signature, signature_len, message, public_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA44_C_verify_extmu(signature, signature_len, message, public_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *secret_key) { + if (message_len != OQS_SIG_ml_dsa_44_extmu_length_mu) { + return OQS_ERROR; + } + if (ctx_str == NULL && ctx_str_len == 0) { + return OQS_SIG_ml_dsa_44_extmu_sign(signature, signature_len, message, message_len, secret_key); + } else { + return OQS_ERROR; + } +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_44_extmu_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *public_key) { + if (message_len != OQS_SIG_ml_dsa_44_extmu_length_mu) { + return OQS_ERROR; + } + if (ctx_str == NULL && ctx_str_len == 0) { + return OQS_SIG_ml_dsa_44_extmu_verify(message, message_len, signature, signature_len, public_key); + } else { + return OQS_ERROR; + } +} +#endif diff --git a/src/sig/ml_dsa/sig_ml_dsa_65_extmu.c b/src/sig/ml_dsa/sig_ml_dsa_65_extmu.c new file mode 100644 index 0000000000..81466ae96e --- /dev/null +++ b/src/sig/ml_dsa/sig_ml_dsa_65_extmu.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: MIT + +#include + +#include + +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) +OQS_SIG *OQS_SIG_ml_dsa_65_extmu_new(void) { + + OQS_SIG *sig = OQS_MEM_calloc(1, sizeof(OQS_SIG)); + if (sig == NULL) { + return NULL; + } + sig->method_name = OQS_SIG_alg_ml_dsa_65_extmu; + sig->alg_version = "FIPS204"; + + sig->claimed_nist_level = 3; + sig->euf_cma = true; + sig->suf_cma = true; + sig->sig_with_ctx_support = false; + + sig->length_public_key = OQS_SIG_ml_dsa_65_extmu_length_public_key; + sig->length_secret_key = OQS_SIG_ml_dsa_65_extmu_length_secret_key; + sig->length_signature = OQS_SIG_ml_dsa_65_extmu_length_signature; + + sig->keypair = OQS_SIG_ml_dsa_65_extmu_keypair; + sig->sign = OQS_SIG_ml_dsa_65_extmu_sign; + sig->verify = OQS_SIG_ml_dsa_65_extmu_verify; + sig->sign_with_ctx_str = OQS_SIG_ml_dsa_65_extmu_sign_with_ctx_str; + sig->verify_with_ctx_str = OQS_SIG_ml_dsa_65_extmu_verify_with_ctx_str; + + return sig; +} + +extern int PQCP_MLDSA_NATIVE_MLDSA65_C_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA65_C_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA65_C_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); + +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64) +extern int PQCP_MLDSA_NATIVE_MLDSA65_X86_64_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA65_X86_64_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA65_X86_64_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); +#endif + +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64) +extern int PQCP_MLDSA_NATIVE_MLDSA65_AARCH64_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA65_AARCH64_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA65_AARCH64_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); +#endif + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_keypair(uint8_t *public_key, uint8_t *secret_key) { +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_X86_64_keypair(public_key, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_keypair(public_key, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_AARCH64_keypair(public_key, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_keypair(public_key, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_keypair(public_key, secret_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) { + if (message_len != OQS_SIG_ml_dsa_65_extmu_length_mu) { + return OQS_ERROR; + } +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_X86_64_signature_extmu(signature, signature_len, message, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_signature_extmu(signature, signature_len, message, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_AARCH64_signature_extmu(signature, signature_len, message, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_signature_extmu(signature, signature_len, message, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_signature_extmu(signature, signature_len, message, secret_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) { + if (message_len != OQS_SIG_ml_dsa_65_extmu_length_mu) { + return OQS_ERROR; + } +#if defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_X86_64_verify_extmu(signature, signature_len, message, public_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_verify_extmu(signature, signature_len, message, public_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_65_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_AARCH64_verify_extmu(signature, signature_len, message, public_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_verify_extmu(signature, signature_len, message, public_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA65_C_verify_extmu(signature, signature_len, message, public_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *secret_key) { + if (message_len != OQS_SIG_ml_dsa_65_extmu_length_mu) { + return OQS_ERROR; + } + if (ctx_str == NULL && ctx_str_len == 0) { + return OQS_SIG_ml_dsa_65_extmu_sign(signature, signature_len, message, message_len, secret_key); + } else { + return OQS_ERROR; + } +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_65_extmu_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *public_key) { + if (message_len != OQS_SIG_ml_dsa_65_extmu_length_mu) { + return OQS_ERROR; + } + if (ctx_str == NULL && ctx_str_len == 0) { + return OQS_SIG_ml_dsa_65_extmu_verify(message, message_len, signature, signature_len, public_key); + } else { + return OQS_ERROR; + } +} +#endif diff --git a/src/sig/ml_dsa/sig_ml_dsa_87_extmu.c b/src/sig/ml_dsa/sig_ml_dsa_87_extmu.c new file mode 100644 index 0000000000..bf34f3b5d7 --- /dev/null +++ b/src/sig/ml_dsa/sig_ml_dsa_87_extmu.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: MIT + +#include + +#include + +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) +OQS_SIG *OQS_SIG_ml_dsa_87_extmu_new(void) { + + OQS_SIG *sig = OQS_MEM_calloc(1, sizeof(OQS_SIG)); + if (sig == NULL) { + return NULL; + } + sig->method_name = OQS_SIG_alg_ml_dsa_87_extmu; + sig->alg_version = "FIPS204"; + + sig->claimed_nist_level = 5; + sig->euf_cma = true; + sig->suf_cma = true; + sig->sig_with_ctx_support = false; + + sig->length_public_key = OQS_SIG_ml_dsa_87_extmu_length_public_key; + sig->length_secret_key = OQS_SIG_ml_dsa_87_extmu_length_secret_key; + sig->length_signature = OQS_SIG_ml_dsa_87_extmu_length_signature; + + sig->keypair = OQS_SIG_ml_dsa_87_extmu_keypair; + sig->sign = OQS_SIG_ml_dsa_87_extmu_sign; + sig->verify = OQS_SIG_ml_dsa_87_extmu_verify; + sig->sign_with_ctx_str = OQS_SIG_ml_dsa_87_extmu_sign_with_ctx_str; + sig->verify_with_ctx_str = OQS_SIG_ml_dsa_87_extmu_verify_with_ctx_str; + + return sig; +} + +extern int PQCP_MLDSA_NATIVE_MLDSA87_C_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA87_C_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA87_C_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); + +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64) +extern int PQCP_MLDSA_NATIVE_MLDSA87_X86_64_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA87_X86_64_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA87_X86_64_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); +#endif + +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64) +extern int PQCP_MLDSA_NATIVE_MLDSA87_AARCH64_keypair(uint8_t *pk, uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA87_AARCH64_signature_extmu(uint8_t *sig, size_t *siglen, const uint8_t *m, const uint8_t *sk); +extern int PQCP_MLDSA_NATIVE_MLDSA87_AARCH64_verify_extmu(const uint8_t *sig, size_t siglen, const uint8_t *m, const uint8_t *pk); +#endif + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_keypair(uint8_t *public_key, uint8_t *secret_key) { +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_X86_64_keypair(public_key, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_keypair(public_key, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_AARCH64_keypair(public_key, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_keypair(public_key, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_keypair(public_key, secret_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *secret_key) { + if (message_len != OQS_SIG_ml_dsa_87_extmu_length_mu) { + return OQS_ERROR; + } +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_X86_64_signature_extmu(signature, signature_len, message, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_signature_extmu(signature, signature_len, message, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_AARCH64_signature_extmu(signature, signature_len, message, secret_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_signature_extmu(signature, signature_len, message, secret_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_signature_extmu(signature, signature_len, message, secret_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_verify(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *public_key) { + if (message_len != OQS_SIG_ml_dsa_87_extmu_length_mu) { + return OQS_ERROR; + } +#if defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_x86_64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_AVX2) && OQS_CPU_has_extension(OQS_CPU_EXT_BMI2) && OQS_CPU_has_extension(OQS_CPU_EXT_POPCNT)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_X86_64_verify_extmu(signature, signature_len, message, public_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_verify_extmu(signature, signature_len, message, public_key); + } +#endif /* OQS_DIST_BUILD */ +#elif defined(OQS_ENABLE_SIG_ml_dsa_87_extmu_aarch64) +#if defined(OQS_DIST_BUILD) + if (OQS_CPU_has_extension(OQS_CPU_EXT_ARM_NEON)) { +#endif /* OQS_DIST_BUILD */ + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_AARCH64_verify_extmu(signature, signature_len, message, public_key); +#if defined(OQS_DIST_BUILD) + } else { + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_verify_extmu(signature, signature_len, message, public_key); + } +#endif /* OQS_DIST_BUILD */ +#else + return (OQS_STATUS) PQCP_MLDSA_NATIVE_MLDSA87_C_verify_extmu(signature, signature_len, message, public_key); +#endif +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_sign_with_ctx_str(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *secret_key) { + if (message_len != OQS_SIG_ml_dsa_87_extmu_length_mu) { + return OQS_ERROR; + } + if (ctx_str == NULL && ctx_str_len == 0) { + return OQS_SIG_ml_dsa_87_extmu_sign(signature, signature_len, message, message_len, secret_key); + } else { + return OQS_ERROR; + } +} + +OQS_API OQS_STATUS OQS_SIG_ml_dsa_87_extmu_verify_with_ctx_str(const uint8_t *message, size_t message_len, const uint8_t *signature, size_t signature_len, const uint8_t *ctx_str, size_t ctx_str_len, const uint8_t *public_key) { + if (message_len != OQS_SIG_ml_dsa_87_extmu_length_mu) { + return OQS_ERROR; + } + if (ctx_str == NULL && ctx_str_len == 0) { + return OQS_SIG_ml_dsa_87_extmu_verify(message, message_len, signature, signature_len, public_key); + } else { + return OQS_ERROR; + } +} +#endif diff --git a/src/sig/sig.c b/src/sig/sig.c index 25f51f2a89..3474d14759 100644 --- a/src/sig/sig.c +++ b/src/sig/sig.c @@ -18,6 +18,9 @@ OQS_API const char *OQS_SIG_alg_identifier(size_t i) { OQS_SIG_alg_ml_dsa_44, OQS_SIG_alg_ml_dsa_65, OQS_SIG_alg_ml_dsa_87, + OQS_SIG_alg_ml_dsa_44_extmu, + OQS_SIG_alg_ml_dsa_65_extmu, + OQS_SIG_alg_ml_dsa_87_extmu, OQS_SIG_alg_falcon_512, OQS_SIG_alg_falcon_1024, OQS_SIG_alg_falcon_padded_512, @@ -277,6 +280,27 @@ OQS_API int OQS_SIG_alg_is_enabled(const char *method_name) { return 0; #endif + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_ml_dsa_44_extmu)) { +#ifdef OQS_ENABLE_SIG_ml_dsa_44_extmu + return 1; +#else + return 0; +#endif + + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_ml_dsa_65_extmu)) { +#ifdef OQS_ENABLE_SIG_ml_dsa_65_extmu + return 1; +#else + return 0; +#endif + + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_ml_dsa_87_extmu)) { +#ifdef OQS_ENABLE_SIG_ml_dsa_87_extmu + return 1; +#else + return 0; +#endif + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_falcon_512)) { #ifdef OQS_ENABLE_SIG_falcon_512 return 1; @@ -1681,6 +1705,27 @@ OQS_API OQS_SIG *OQS_SIG_new(const char *method_name) { return NULL; #endif + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_ml_dsa_44_extmu)) { +#ifdef OQS_ENABLE_SIG_ml_dsa_44_extmu + return OQS_SIG_ml_dsa_44_extmu_new(); +#else + return NULL; +#endif + + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_ml_dsa_65_extmu)) { +#ifdef OQS_ENABLE_SIG_ml_dsa_65_extmu + return OQS_SIG_ml_dsa_65_extmu_new(); +#else + return NULL; +#endif + + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_ml_dsa_87_extmu)) { +#ifdef OQS_ENABLE_SIG_ml_dsa_87_extmu + return OQS_SIG_ml_dsa_87_extmu_new(); +#else + return NULL; +#endif + } else if (0 == strcasecmp(method_name, OQS_SIG_alg_falcon_512)) { #ifdef OQS_ENABLE_SIG_falcon_512 return OQS_SIG_falcon_512_new(); diff --git a/src/sig/sig.h b/src/sig/sig.h index 8fc4fb5bb9..83eb9f80ff 100644 --- a/src/sig/sig.h +++ b/src/sig/sig.h @@ -38,6 +38,12 @@ extern "C" { #define OQS_SIG_alg_ml_dsa_65 "ML-DSA-65" /** Algorithm identifier for ML-DSA-87 */ #define OQS_SIG_alg_ml_dsa_87 "ML-DSA-87" +/** Algorithm identifier for ML-DSA-44-extmu */ +#define OQS_SIG_alg_ml_dsa_44_extmu "ML-DSA-44-extmu" +/** Algorithm identifier for ML-DSA-65-extmu */ +#define OQS_SIG_alg_ml_dsa_65_extmu "ML-DSA-65-extmu" +/** Algorithm identifier for ML-DSA-87-extmu */ +#define OQS_SIG_alg_ml_dsa_87_extmu "ML-DSA-87-extmu" /** Algorithm identifier for Falcon-512 */ #define OQS_SIG_alg_falcon_512 "Falcon-512" /** Algorithm identifier for Falcon-1024 */ @@ -486,7 +492,7 @@ extern "C" { ///// OQS_COPY_FROM_UPSTREAM_FRAGMENT_ALGS_LENGTH_START /** Number of algorithm identifiers above. */ -#define OQS_SIG_algs_length 65 + OQS_SIG_SLH_DSA_algs_length +#define OQS_SIG_algs_length 68 + OQS_SIG_SLH_DSA_algs_length ///// OQS_COPY_FROM_UPSTREAM_FRAGMENT_ALGS_LENGTH_END /** diff --git a/tests/kat_sig.c b/tests/kat_sig.c index d979afc2c2..8d836dba54 100644 --- a/tests/kat_sig.c +++ b/tests/kat_sig.c @@ -701,8 +701,7 @@ OQS_STATUS combine_message_signature(uint8_t **signed_msg, size_t *signed_msg_le } memcpy(*signed_msg, msg, msg_len); memcpy(*signed_msg + msg_len, signature, signature_len); - return OQS_SUCCESS; - ///// OQS_COPY_FROM_UPSTREAM_FRAGMENT_COMBINE_MESSAGE_SIGNATURE_END + return OQS_SUCCESS;///// OQS_COPY_FROM_UPSTREAM_FRAGMENT_COMBINE_MESSAGE_SIGNATURE_END } else { return OQS_ERROR; } diff --git a/tests/test_acvp_vectors.py b/tests/test_acvp_vectors.py index 7f17239b58..a3870251e3 100644 --- a/tests/test_acvp_vectors.py +++ b/tests/test_acvp_vectors.py @@ -256,10 +256,8 @@ def test_acvp_vec_ml_dsa_sig_gen(sig_name): if variant["signatureInterface"] == "internal": if variant["externalMu"]: message = testCase["mu"] - extmu = "1" else: message = testCase["message"] - extmu = "0" else: message = testCase["message"] # internal pre-hash API take hash as "message" @@ -271,7 +269,7 @@ def test_acvp_vec_ml_dsa_sig_gen(sig_name): rnd = testCase["rnd"] if not variant["deterministic"] else "0" * 64 build_dir = helpers.get_current_build_dir_name() - if variant["signatureInterface"] == "internal": + if variant["signatureInterface"] == "internal" and not variant["externalMu"]: helpers.run_subprocess( [ f"{build_dir}/tests/vectors_sig", @@ -280,8 +278,19 @@ def test_acvp_vec_ml_dsa_sig_gen(sig_name): sk, message, signature, + rnd + ] + ) + elif variant["signatureInterface"] == "internal" and variant["externalMu"]: + helpers.run_subprocess( + [ + f"{build_dir}/tests/vectors_sig", + sig_name+"-extmu", + "sigGen_extmu", + sk, + message, + signature, rnd, - extmu ] ) elif variant["signatureInterface"] == "external" and variant["preHash"] == "pure": @@ -343,10 +352,8 @@ def test_acvp_vec_ml_dsa_sig_ver(sig_name): if variant["signatureInterface"] == "internal": if variant["externalMu"]: message = testCase["mu"] - extmu = "1" else: message = testCase["message"] - extmu = "0" else: message = testCase["message"] @@ -360,7 +367,7 @@ def test_acvp_vec_ml_dsa_sig_ver(sig_name): testPassed = "1" if testCase["testPassed"] else "0" build_dir = helpers.get_current_build_dir_name() - if variant["signatureInterface"] == "internal": + if variant["signatureInterface"] == "internal" and not variant["externalMu"]: helpers.run_subprocess( [ f"{build_dir}/tests/vectors_sig", @@ -369,8 +376,19 @@ def test_acvp_vec_ml_dsa_sig_ver(sig_name): pk, message, signature, + testPassed + ] + ) + elif variant["signatureInterface"] == "internal" and variant["externalMu"]: + helpers.run_subprocess( + [ + f"{build_dir}/tests/vectors_sig", + sig_name+"-extmu", + "sigVer_extmu", + pk, + message, + signature, testPassed, - extmu ] ) elif variant["signatureInterface"] == "external" and variant["preHash"] == "pure": @@ -525,9 +543,7 @@ def test_acvp_vec_slh_dsa_sig_gen(sig_name): sk, message, signature, - rnd, - "0" - ] + rnd ] ) else: context = testCase["context"] @@ -577,9 +593,7 @@ def test_acvp_vec_slh_dsa_sig_ver(sig_name): pk, message, signature, - testPassed, - "0" - ] + testPassed ] ) else: context = testCase["context"] diff --git a/tests/test_alg_info.py b/tests/test_alg_info.py index 2148772b48..ccbacbc44d 100644 --- a/tests/test_alg_info.py +++ b/tests/test_alg_info.py @@ -43,6 +43,9 @@ def test_alg_info_kem(kem_name): @helpers.filtered_test @pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name()) def test_alg_info_sig(sig_name): + # skip extmu variants as they are not explicitly documented + if "-extmu" in sig_name: + pytest.skip('External Mu variants do not have separate datasheets') if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled') # get the algorithm info from liboqs output = helpers.run_subprocess([helpers.path_to_executable('dump_alg_info')]) diff --git a/tests/test_code_conventions.py b/tests/test_code_conventions.py index 2ed437f119..e4aac06d70 100644 --- a/tests/test_code_conventions.py +++ b/tests/test_code_conventions.py @@ -22,6 +22,9 @@ def test_datasheet_kem(kem_name): @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows") @pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name()) def test_datasheet_sig(sig_name): + # skip extmu variants + if "-extmu" in sig_name: + pytest.skip('extmu variants do not have separate datasheets') helpers.run_subprocess( ['grep', '-r', sig_name, 'docs/algorithms'] ) diff --git a/tests/test_kat.py b/tests/test_kat.py index 8beab07872..0653c3917a 100644 --- a/tests/test_kat.py +++ b/tests/test_kat.py @@ -27,8 +27,9 @@ def test_kem(kem_name): @pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name()) def test_sig(sig_name): kats = helpers.get_kats("sig") - # slh dsa will run ACVP vectors instead - if ("SLH_DSA" in sig_name): pytest.skip('slhdsa not enabled for KATs') + # skip slh-dsa and extmu variants + if ("SLH_DSA" in sig_name or "-extmu" in sig_name): + pytest.skip('Skipping KATs for slh-dsa and extmu variants') if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled') output = helpers.run_subprocess( [helpers.path_to_executable('kat_sig'), sig_name], diff --git a/tests/test_mem.py b/tests/test_mem.py index b9530b036f..a2c4517353 100644 --- a/tests/test_mem.py +++ b/tests/test_mem.py @@ -18,6 +18,9 @@ def test_mem_kem(kem_name): @helpers.filtered_test @pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name()) def test_mem_sig(sig_name): + # skip extmu variants as they require exactly 64-byte inputs + if "-extmu" in sig_name: + pytest.skip('External Mu variants require specific input sizes and are not supported by this benchmark') if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled') diff --git a/tests/test_sig.c b/tests/test_sig.c index 91181b48d4..116e25e524 100644 --- a/tests/test_sig.c +++ b/tests/test_sig.c @@ -27,12 +27,15 @@ static OQS_STATUS sig_test_correctness(const char *method_name, bool bitflips_al uint8_t *public_key = NULL; uint8_t *secret_key = NULL; uint8_t *message = NULL; - size_t message_len = 100; + size_t message_len = 64; uint8_t ctx[257] = { 0 }; uint8_t *signature = NULL; size_t signature_len; OQS_STATUS rc, ret = OQS_ERROR; - + // if it is not an extmu variant, use the standard test length of 100 + if (strstr(method_name, "-extmu") == NULL) { + message_len = 100; + } //The magic numbers are random values. //The length of the magic number was chosen to be 31 to break alignment magic_t magic; @@ -355,7 +358,7 @@ int main(int argc, char **argv) { char no_thread_sig_patterns[][MAX_LEN_SIG_NAME_] = {"MAYO-5", "cross-rsdp-128-small", "cross-rsdp-192-small", "cross-rsdp-256-balanced", "cross-rsdp-256-small", "cross-rsdpg-192-small", "cross-rsdpg-256-small", "SNOVA_37_17_2", "SNOVA_56_25_2", "SNOVA_49_11_3", "SNOVA_37_8_4", "SNOVA_24_5_5", "SNOVA_60_10_4", "SNOVA_29_6_5", "mqom2_cat1_gf16_fast_r3", "mqom2_cat1_gf16_fast_r5", "mqom2_cat1_gf16_short_r3", "mqom2_cat1_gf16_short_r5", "mqom2_cat3_gf16_fast_r3", "mqom2_cat3_gf16_fast_r5", "mqom2_cat3_gf16_short_r3", "mqom2_cat3_gf16_short_r5", "mqom2_cat5_gf16_fast_r3", "mqom2_cat5_gf16_fast_r5", "mqom2_cat5_gf16_short_r3", "mqom2_cat5_gf16_short_r5"}; int test_in_thread = 1; for (size_t i = 0 ; i < sizeof(no_thread_sig_patterns) / MAX_LEN_SIG_NAME_; ++i) { - if ( (strncmp(alg_name, "SLH_DSA", 7) == 0) || (strstr(alg_name, no_thread_sig_patterns[i]) != NULL) ) { + if ((strncmp(alg_name, "SLH_DSA", 7) == 0) || (strstr(alg_name, no_thread_sig_patterns[i]) != NULL)) { test_in_thread = 0; break; } diff --git a/tests/test_wycheproof_vectors.py b/tests/test_wycheproof_vectors.py index ec9078d74a..9a5a5e36a0 100644 --- a/tests/test_wycheproof_vectors.py +++ b/tests/test_wycheproof_vectors.py @@ -100,7 +100,7 @@ def expand_private_key_from_seed(build_dir, sig_name, seed): ] result = subprocess.run(cmd, capture_output=True, text=True) - + for line in result.stdout.splitlines(): if line.startswith("sk: "): return line.split("sk: ")[1].strip() @@ -275,7 +275,7 @@ def test_wycheproof_vec_kem_decaps(kem_name): @helpers.filtered_test @pytest.mark.parametrize("sig_name", helpers.available_sigs_by_name()) def test_wycheproof_vec_sig_verify(sig_name): - if not helpers.is_sig_enabled_by_name(sig_name) or not sig_name.startswith("ML-DSA"): + if not helpers.is_sig_enabled_by_name(sig_name) or sig_name not in ML_DSA_PARAMS: pytest.skip("Not enabled or supported") build_dir = helpers.get_current_build_dir_name() @@ -299,8 +299,8 @@ def test_wycheproof_vec_sig_verify(sig_name): if "Internal" in flags or (mu and not msg): cmd = [ f"{build_dir}/tests/vectors_sig", - sig_name, "sigVer_int", - pk, mu, sig, testPassed, "1" + sig_name, "sigVer_extmu", + pk, mu, sig, testPassed ] else: cmd = [ @@ -314,7 +314,7 @@ def test_wycheproof_vec_sig_verify(sig_name): @helpers.filtered_test @pytest.mark.parametrize("sig_name", helpers.available_sigs_by_name()) def test_wycheproof_vec_sig_sign(sig_name): - if not helpers.is_sig_enabled_by_name(sig_name) or not sig_name.startswith("ML-DSA"): + if not helpers.is_sig_enabled_by_name(sig_name) or sig_name not in ML_DSA_PARAMS: pytest.skip("Not enabled or supported") build_dir = helpers.get_current_build_dir_name() @@ -325,6 +325,7 @@ def test_wycheproof_vec_sig_sign(sig_name): pytest.skip("No sign test cases found.") for group, tc in test_cases: + is_valid = tc.get("result") == "valid" # 1. Try to fetch the fully expanded private key directly (standard for 'noseed' files) sk = tc.get("privateKey") or group.get("privateKey") @@ -336,8 +337,12 @@ def test_wycheproof_vec_sig_sign(sig_name): # Passing None/empty to the subprocess would crash Python or fail the vector_sig arg parser. # Skip and move to next if not sk: - pytest.fail(f"TC {tc['tcId']} FAILED: Could not obtain or expand secret key.") - + if not is_valid: + # Expansion failed as expected for invalid seed tests + continue + else: + pytest.fail(f"TC {tc['tcId']} FAILED: Seed expansion failed for valid input.") + msg = tc.get("msg", "") sig = tc.get("sig", "") ctx = tc.get("ctx", "") @@ -351,8 +356,8 @@ def test_wycheproof_vec_sig_sign(sig_name): if "Internal" in flags or (mu and not msg): cmd = [ f"{build_dir}/tests/vectors_sig", - sig_name, "sigGen_int", - sk, mu, sig, rnd, "1" + sig_name+"-extmu", "sigGen_extmu", + sk, mu, sig, rnd ] else: cmd = [ diff --git a/tests/vectors_sig.c b/tests/vectors_sig.c index 2366be3409..01c315921e 100644 --- a/tests/vectors_sig.c +++ b/tests/vectors_sig.c @@ -18,6 +18,7 @@ #include "../src/sig/slh_dsa/slh_dsa_c/slh_dsa.h" #define MLDSA_RNDBYTES 32 +#define MLDSA_MULEN 64 #define MAXCTXBYTES 255 #ifdef OQS_ENABLE_SIG_ml_dsa_44 @@ -201,6 +202,13 @@ static inline bool is_ml_dsa(const char *method_name) { || (0 == strcmp(method_name, OQS_SIG_alg_ml_dsa_87)); } +/* ML_DSA-specific extmu functions */ +static inline bool is_ml_dsa_extmu(const char *method_name) { + return (0 == strcmp(method_name, OQS_SIG_alg_ml_dsa_44_extmu)) + || (0 == strcmp(method_name, OQS_SIG_alg_ml_dsa_65_extmu)) + || (0 == strcmp(method_name, OQS_SIG_alg_ml_dsa_87_extmu)); +} + static void MLDSA_randombytes_init(const uint8_t *entropy_input, const uint8_t *personalization_string) { (void) personalization_string; prng_state.pos = entropy_input; @@ -392,15 +400,15 @@ static OQS_STATUS sig_kg_vector(const char *method_name, return ret; } -#if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87) || defined(OQS_ENABLE_SIG_SLH_DSA) -static int sig_ver_vector(const char *method_name, - const uint8_t *sigVer_pk_bytes, - const uint8_t *sigVer_msg_bytes, - size_t msgLen, - const uint8_t *sigVer_sig_bytes, - size_t sigLen, - int testPassed, - int extMu) { +#if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87) || defined(OQS_ENABLE_SIG_SLH_DSA) || defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) +/* signature verification internal APIs tests */ +static int sig_ver_vector_int(const char *method_name, + const uint8_t *sigVer_pk_bytes, + const uint8_t *sigVer_msg_bytes, + size_t msgLen, + const uint8_t *sigVer_sig_bytes, + size_t sigLen, + int testPassed) { FILE *fh = NULL; OQS_SIG *sig = NULL; @@ -414,22 +422,22 @@ static int sig_ver_vector(const char *method_name, fh = stdout; - if ((sigVer_pk_bytes == NULL) || (sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL)) { + if ((sigVer_pk_bytes == NULL) || (msgLen && sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL)) { fprintf(stderr, "[vectors_sig] %s ERROR: inputs NULL!\n", method_name); goto err; } if (!strcmp(method_name, "ML-DSA-44")) { #ifdef OQS_ENABLE_SIG_ml_dsa_44 - rc = PQCP_MLDSA_NATIVE_MLDSA44_C_verify_internal(sigVer_sig_bytes, sigLen, sigVer_msg_bytes, msgLen, NULL, 0, sigVer_pk_bytes, extMu); + rc = PQCP_MLDSA_NATIVE_MLDSA44_C_verify_internal(sigVer_sig_bytes, sigLen, sigVer_msg_bytes, msgLen, NULL, 0, sigVer_pk_bytes, 0); #endif } else if (!strcmp(method_name, "ML-DSA-65")) { #ifdef OQS_ENABLE_SIG_ml_dsa_65 - rc = PQCP_MLDSA_NATIVE_MLDSA65_C_verify_internal(sigVer_sig_bytes, sigLen, sigVer_msg_bytes, msgLen, NULL, 0, sigVer_pk_bytes, extMu); + rc = PQCP_MLDSA_NATIVE_MLDSA65_C_verify_internal(sigVer_sig_bytes, sigLen, sigVer_msg_bytes, msgLen, NULL, 0, sigVer_pk_bytes, 0); #endif } else if (!strcmp(method_name, "ML-DSA-87")) { #ifdef OQS_ENABLE_SIG_ml_dsa_87 - rc = PQCP_MLDSA_NATIVE_MLDSA87_C_verify_internal(sigVer_sig_bytes, sigLen, sigVer_msg_bytes, msgLen, NULL, 0, sigVer_pk_bytes, extMu); + rc = PQCP_MLDSA_NATIVE_MLDSA87_C_verify_internal(sigVer_sig_bytes, sigLen, sigVer_msg_bytes, msgLen, NULL, 0, sigVer_pk_bytes, 0); #endif } else if (!strncmp(method_name, "SLH_DSA", 7)) { #ifdef OQS_ENABLE_SIG_SLH_DSA @@ -460,11 +468,11 @@ static int sig_ver_vector(const char *method_name, cleanup: OQS_SIG_free(sig); - (void)extMu; return ret; } #if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87) +/* signature verification external APIs with context tests */ static int sig_ver_vector_ext(const char *method_name, const uint8_t *sigVer_pk_bytes, const uint8_t *sigVer_msg_bytes, @@ -479,7 +487,7 @@ static int sig_ver_vector_ext(const char *method_name, OQS_SIG *sig = NULL; int rc = -1, ret = -1; - if ((sigVer_pk_bytes == NULL) || (sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL) || (sigVer_ctxLen && sigVer_ctx == NULL)) { + if ((sigVer_pk_bytes == NULL) || (msgLen && sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL) || (sigVer_ctxLen && sigVer_ctx == NULL)) { fprintf(stderr, "[vectors_sig] %s ERROR: inputs NULL!\n", method_name); goto err; } @@ -528,10 +536,62 @@ static int sig_ver_vector_ext(const char *method_name, OQS_SIG_free(sig); return ret; - /* __attribute__ doesn't work on windows, so "use" sigLen to make compiler happy */ - (void)sigLen; } +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) +/* signature verification external-MU APIs tests */ +static int sig_ver_vector_extmu(const char *method_name, + const uint8_t *sigVer_pk_bytes, + const uint8_t *sigVer_msg_bytes, + size_t msgLen, + const uint8_t *sigVer_sig_bytes, + size_t sigLen, + int testPassed) { + + FILE *fh = NULL; + OQS_SIG *sig = NULL; + int rc = -1, ret = -1; + + if ((sigVer_pk_bytes == NULL) || (sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL) || (msgLen != MLDSA_MULEN)) { + fprintf(stderr, "[vectors_sig] %s ERROR: inputs NULL or mu length incorrect!\n", method_name); + goto err; + } + + sig = OQS_SIG_new(method_name); + if (sig == NULL) { + printf("[vectors_sig] %s was not enabled at compile-time.\n", method_name); + goto algo_not_enabled; + } + + fh = stdout; + + rc = OQS_SIG_verify(sig, sigVer_msg_bytes, msgLen, sigVer_sig_bytes, sigLen, sigVer_pk_bytes); + + if ((!rc) != testPassed) { + fprintf(stderr, "[vectors_sig] %s ERROR: OQS_SIG_verify failed!\n", method_name); + goto err; + } else { + ret = EXIT_SUCCESS; + } + + fprintBstr(fh, "testPassed: ", (const uint8_t *)&testPassed, 1); + + goto cleanup; + +err: + ret = EXIT_FAILURE; + goto cleanup; + +algo_not_enabled: + ret = EXIT_SUCCESS; + +cleanup: + OQS_SIG_free(sig); + return ret; +} +#endif + +/* signature verification prehash APIs with context tests */ static int sig_ver_prehash_vector_ext(const char *method_name, const uint8_t *sigVer_pk_bytes, const uint8_t *sigVer_msg_bytes, @@ -599,9 +659,10 @@ static int sig_ver_prehash_vector_ext(const char *method_name, } #endif -static int sig_gen_vector(const char *method_name, - uint8_t *prng_output_stream, - const uint8_t *sigGen_sk, const uint8_t *sigGen_msg, size_t sigGen_msgLen, const uint8_t *sigGen_sig, int extMu) { +/* signature generation internal API tests */ +static int sig_gen_vector_int(const char *method_name, + uint8_t *prng_output_stream, + const uint8_t *sigGen_sk, const uint8_t *sigGen_msg, size_t sigGen_msgLen, const uint8_t *sigGen_sig) { FILE *fh = NULL; uint8_t *signature = NULL; @@ -626,22 +687,22 @@ static int sig_gen_vector(const char *method_name, goto err; } - if ((prng_output_stream == NULL) || (sigGen_sk == NULL) || (sigGen_msg == NULL) || (sigGen_sig == NULL)) { + if ((prng_output_stream == NULL) || (sigGen_sk == NULL) || (sigGen_msgLen && sigGen_msg == NULL) || (sigGen_sig == NULL)) { fprintf(stderr, "[vectors_sig] %s ERROR: inputs NULL!\n", method_name); goto err; } if (!strcmp(method_name, "ML-DSA-44")) { #ifdef OQS_ENABLE_SIG_ml_dsa_44 - rc = PQCP_MLDSA_NATIVE_MLDSA44_C_signature_internal(signature, &sigLen, sigGen_msg, sigGen_msgLen, NULL, 0, prng_output_stream, sigGen_sk, extMu); + rc = PQCP_MLDSA_NATIVE_MLDSA44_C_signature_internal(signature, &sigLen, sigGen_msg, sigGen_msgLen, NULL, 0, prng_output_stream, sigGen_sk, 0); #endif } else if (!strcmp(method_name, "ML-DSA-65")) { #ifdef OQS_ENABLE_SIG_ml_dsa_65 - rc = PQCP_MLDSA_NATIVE_MLDSA65_C_signature_internal(signature, &sigLen, sigGen_msg, sigGen_msgLen, NULL, 0, prng_output_stream, sigGen_sk, extMu); + rc = PQCP_MLDSA_NATIVE_MLDSA65_C_signature_internal(signature, &sigLen, sigGen_msg, sigGen_msgLen, NULL, 0, prng_output_stream, sigGen_sk, 0); #endif } else if (!strcmp(method_name, "ML-DSA-87")) { #ifdef OQS_ENABLE_SIG_ml_dsa_87 - rc = PQCP_MLDSA_NATIVE_MLDSA87_C_signature_internal(signature, &sigLen, sigGen_msg, sigGen_msgLen, NULL, 0, prng_output_stream, sigGen_sk, extMu); + rc = PQCP_MLDSA_NATIVE_MLDSA87_C_signature_internal(signature, &sigLen, sigGen_msg, sigGen_msgLen, NULL, 0, prng_output_stream, sigGen_sk, 0); #endif } else if (!strncmp(method_name, "SLH_DSA", 7)) { #ifdef OQS_ENABLE_SIG_SLH_DSA @@ -676,10 +737,10 @@ static int sig_gen_vector(const char *method_name, cleanup: OQS_MEM_insecure_free(signature); OQS_SIG_free(sig); - (void)extMu; return ret; } +/* signature generation external APIs with context tests */ static int sig_gen_vector_ext(const char *method_name, uint8_t *prng_output_stream, const uint8_t *sigGen_sk, @@ -731,7 +792,7 @@ static int sig_gen_vector_ext(const char *method_name, goto err; } - if ((prng_output_stream == NULL) || (sigGen_sk == NULL) || (sigGen_msg == NULL) || (sigGen_sig == NULL) || (sigGen_ctxLen && sigGen_ctx == NULL)) { + if ((prng_output_stream == NULL) || (sigGen_sk == NULL) || (sigGen_msgLen && sigGen_msg == NULL) || (sigGen_sig == NULL) || (sigGen_ctxLen && sigGen_ctx == NULL)) { fprintf(stderr, "[vectors_sig] %s ERROR: inputs NULL!\n", method_name); goto err; } @@ -748,7 +809,7 @@ static int sig_gen_vector_ext(const char *method_name, ret = EXIT_SUCCESS; } else { ret = EXIT_FAILURE; - fprintf(stderr, "[vectors_sig] %s ERROR: OQS_SIG_sign_with_ctx_str doesn't match!\n", method_name); + fprintf(stderr, "[vectors_sig] %s ERROR: signature doesn't match!\n", method_name); } // NOTE: OQS_SIG_sign should be equivalent to OQS_SIG_sign_with_ctx_str(ctx=NULL, ctxlen=0) @@ -785,7 +846,93 @@ static int sig_gen_vector_ext(const char *method_name, return ret; } +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) +/* signature generation external-MU APIs tests */ +static int sig_gen_vector_extmu(const char *method_name, + uint8_t *prng_output_stream, + const uint8_t *sigGen_sk, + const uint8_t *sigGen_msg, size_t sigGen_msgLen, + const uint8_t *sigGen_sig) { + + uint8_t *entropy_input; + FILE *fh = NULL; + uint8_t *signature = NULL; + OQS_SIG *sig = NULL; + int rc = -1, ret = -1; + size_t sigLen; + + void (*randombytes_init)(const uint8_t *, const uint8_t *) = NULL; + void (*randombytes_free)(void) = NULL; + + sig = OQS_SIG_new(method_name); + if (sig == NULL) { + printf("[vectors_sig] %s was not enabled at compile-time.\n", method_name); + goto algo_not_enabled; + } + + if (is_ml_dsa_extmu(method_name)) { + OQS_randombytes_custom_algorithm(&MLDSA_randombytes); + randombytes_init = &MLDSA_randombytes_init; + randombytes_free = &MLDSA_randombytes_free; + entropy_input = (uint8_t *) prng_output_stream; + } else { + // Only ML-DSA-Extmu supported + goto err; + } + + randombytes_init(entropy_input, NULL); + + sigLen = sig->length_signature; + + fh = stdout; + + signature = OQS_MEM_malloc(sigLen); + + if (signature == NULL) { + fprintf(stderr, "[vectors_sig] %s ERROR: OQS_MEM_malloc failed!\n", method_name); + goto err; + } + + if ((prng_output_stream == NULL) || (sigGen_sk == NULL) || (sigGen_msg == NULL) || (sigGen_sig == NULL) || (sigGen_msgLen != MLDSA_MULEN)) { + fprintf(stderr, "[vectors_sig] %s ERROR: inputs NULL or mu length incorrect !\n", method_name); + goto err; + } + + rc = OQS_SIG_sign(sig, signature, &sigLen, sigGen_msg, sigGen_msgLen, sigGen_sk); + + if (rc) { + fprintf(stderr, "[vectors_sig] %s ERROR: OQS_SIG_sign failed!\n", method_name); + goto err; + } + fprintBstr(fh, "signature: ", signature, sig->length_signature); + + if (!memcmp(signature, sigGen_sig, sigLen)) { + ret = EXIT_SUCCESS; + } else { + ret = EXIT_FAILURE; + fprintf(stderr, "[vectors_sig] %s ERROR: signature doesn't match!\n", method_name); + } + goto cleanup; + +err: + ret = EXIT_FAILURE; + goto cleanup; + +algo_not_enabled: + ret = EXIT_SUCCESS; + +cleanup: + OQS_MEM_insecure_free(signature); + if (randombytes_free != NULL) { + randombytes_free(); + } + OQS_SIG_free(sig); + return ret; +} +#endif + #if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87) +/* signature generation pre-hash external APIs with context tests */ static int sig_gen_prehash_vector_ext(const char *method_name, uint8_t *prng_output_stream, const uint8_t *sigGen_sk, @@ -990,12 +1137,11 @@ int main(int argc, char **argv) { hexStringToByteArray(kg_pk, kg_pk_bytes); hexStringToByteArray(kg_sk, kg_sk_bytes); - rc = sig_kg_vector(alg_name, prng_output_stream_bytes, kg_pk_bytes, kg_sk_bytes); } else if (!strcmp(test_name, "sigGen_int")) { - /* vectors_sig alg_name sigGen_int sk message signature rnd extmu ---> (argc 8) */ - if (argc != 8) { + /* vectors_sig alg_name sigGen_int sk message signature rnd ---> (argc 8) */ + if (argc != 7) { valid_args = false; goto err; } @@ -1003,16 +1149,13 @@ int main(int argc, char **argv) { sigGen_msg = argv[4]; sigGen_sig = argv[5]; prng_output_stream = argv[6]; - int extMu = atoi(argv[7]); /* still need to deal with prehash FIX */ - if (is_ml_dsa(alg_name)) { if ( strlen(sigGen_msg) % 2 != 0 || strlen(prng_output_stream) != 2 * MLDSA_RNDBYTES || strlen(sigGen_sig) != 2 * sig->length_signature || - strlen(sigGen_sk) != 2 * sig->length_secret_key || - (extMu != 0 && extMu != 1)) { - printf("lengths bad or external mu value incorrect\n"); + strlen(sigGen_sk) != 2 * sig->length_secret_key) { + printf("lengths bad\n"); goto err; } } else if (is_slh_dsa(alg_name)) { @@ -1038,22 +1181,24 @@ int main(int argc, char **argv) { msgLen = strlen(sigGen_msg) / 2; sigGen_sk_bytes = OQS_MEM_malloc(sig->length_secret_key); - sigGen_msg_bytes = OQS_MEM_malloc(msgLen); + sigGen_msg_bytes = (msgLen > 0) ? OQS_MEM_malloc(msgLen) : NULL; sigGen_sig_bytes = OQS_MEM_malloc(sig->length_signature); prng_output_stream_bytes = OQS_MEM_malloc(strlen(prng_output_stream) / 2); - if ((sigGen_sk_bytes == NULL) || (sigGen_msg_bytes == NULL) || (sigGen_sig_bytes == NULL) || (prng_output_stream_bytes == NULL)) { + if ((sigGen_sk_bytes == NULL) || (msgLen && sigGen_msg_bytes == NULL) || (sigGen_sig_bytes == NULL) || (prng_output_stream_bytes == NULL)) { fprintf(stderr, "[vectors_sig] ERROR: OQS_MEM_malloc failed!\n"); goto err; } hexStringToByteArray(sigGen_sk, sigGen_sk_bytes); - hexStringToByteArray(sigGen_msg, sigGen_msg_bytes); + if (msgLen) { + hexStringToByteArray(sigGen_msg, sigGen_msg_bytes); + } hexStringToByteArray(sigGen_sig, sigGen_sig_bytes); hexStringToByteArray(prng_output_stream, prng_output_stream_bytes); #if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87) || defined(OQS_ENABLE_SIG_SLH_DSA) - rc = sig_gen_vector(alg_name, prng_output_stream_bytes, sigGen_sk_bytes, sigGen_msg_bytes, msgLen, sigGen_sig_bytes, extMu); + rc = sig_gen_vector_int(alg_name, prng_output_stream_bytes, sigGen_sk_bytes, sigGen_msg_bytes, msgLen, sigGen_sig_bytes); #else rc = EXIT_SUCCESS; goto cleanup; @@ -1106,7 +1251,7 @@ int main(int argc, char **argv) { ctxlen = strlen(sigGen_ctx) / 2; sigGen_sk_bytes = OQS_MEM_malloc(sig->length_secret_key); - sigGen_msg_bytes = OQS_MEM_malloc(msgLen); + sigGen_msg_bytes = (msgLen > 0) ? OQS_MEM_malloc(msgLen) : NULL; sigGen_sig_bytes = OQS_MEM_malloc(sig->length_signature); prng_output_stream_bytes = OQS_MEM_malloc(strlen(prng_output_stream) / 2); /* allocate memory if required */ @@ -1114,15 +1259,17 @@ int main(int argc, char **argv) { sigGen_ctx_bytes = OQS_MEM_malloc(ctxlen); } - if ((sigGen_sk_bytes == NULL) || (sigGen_msg_bytes == NULL) || (sigGen_sig_bytes == NULL) || (ctxlen && sigGen_ctx_bytes == NULL) || (prng_output_stream_bytes == NULL)) { + if ((sigGen_sk_bytes == NULL) || (msgLen && sigGen_msg_bytes == NULL) || (sigGen_sig_bytes == NULL) || (ctxlen && sigGen_ctx_bytes == NULL) || (prng_output_stream_bytes == NULL)) { fprintf(stderr, "[vectors_sig] ERROR: OQS_MEM_malloc failed!\n"); goto err; } hexStringToByteArray(prng_output_stream, prng_output_stream_bytes); - hexStringToByteArray(sigGen_sk, sigGen_sk_bytes); - hexStringToByteArray(sigGen_msg, sigGen_msg_bytes); hexStringToByteArray(sigGen_sig, sigGen_sig_bytes); + hexStringToByteArray(sigGen_sk, sigGen_sk_bytes); + if (msgLen) { + hexStringToByteArray(sigGen_msg, sigGen_msg_bytes); + } if (ctxlen) { hexStringToByteArray(sigGen_ctx, sigGen_ctx_bytes); } @@ -1134,6 +1281,47 @@ int main(int argc, char **argv) { goto cleanup; #endif + } else if (!strcmp(test_name, "sigGen_extmu")) { + /* vectors_sig alg_name sigGen_extmu sk message signature rnd ---> (argc 7) */ + if (argc != 7) { + valid_args = false; + goto err; + } + sigGen_sk = argv[3]; + sigGen_msg = argv[4]; + sigGen_sig = argv[5]; + prng_output_stream = argv[6]; + + if ( strlen(sigGen_msg) != 2 * MLDSA_MULEN || + strlen(sigGen_sig) != 2 * sig->length_signature || + strlen(prng_output_stream) != 2 * MLDSA_RNDBYTES || + strlen(sigGen_sk) != 2 * sig->length_secret_key) { + printf("lengths bad\n"); + goto err; + } + msgLen = strlen(sigGen_msg) / 2; + + sigGen_sk_bytes = OQS_MEM_malloc(sig->length_secret_key); + sigGen_msg_bytes = OQS_MEM_malloc(msgLen); + sigGen_sig_bytes = OQS_MEM_malloc(sig->length_signature); + prng_output_stream_bytes = OQS_MEM_malloc(strlen(prng_output_stream) / 2); + + if ((sigGen_sk_bytes == NULL) || (sigGen_msg_bytes == NULL) || (sigGen_sig_bytes == NULL) || (prng_output_stream_bytes == NULL)) { + fprintf(stderr, "[vectors_sig] ERROR: OQS_MEM_malloc failed!\n"); + goto err; + } + + hexStringToByteArray(prng_output_stream, prng_output_stream_bytes); + hexStringToByteArray(sigGen_sk, sigGen_sk_bytes); + hexStringToByteArray(sigGen_msg, sigGen_msg_bytes); + hexStringToByteArray(sigGen_sig, sigGen_sig_bytes); +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) + rc = sig_gen_vector_extmu(alg_name, prng_output_stream_bytes, sigGen_sk_bytes, sigGen_msg_bytes, msgLen, sigGen_sig_bytes); +#else + rc = EXIT_SUCCESS; + goto cleanup; +#endif + } else if (!strcmp(test_name, "sigGen_prehash_ext")) { /* vectors_sig alg_name sigGen_ext sk message signature context rnd algname ---> (argc 9) */ if (argc != 9) { @@ -1191,15 +1379,14 @@ int main(int argc, char **argv) { #endif } else if (!strcmp(test_name, "sigVer_int")) { - /* vectors_sig alg_name sigVer_int pk message signature testPassed extmu ---> (argc 8) */ - if (argc != 8) { + /* vectors_sig alg_name sigVer_int pk message signature testPassed ---> (argc 7) */ + if (argc != 7) { valid_args = false; goto err; } sigVer_pk = argv[3]; sigVer_msg = argv[4]; sigVer_sig = argv[5]; - int extMu = atoi(argv[7]); int sigVerPassed = atoi(argv[6]); @@ -1207,8 +1394,7 @@ int main(int argc, char **argv) { if (strlen(sigVer_msg) % 2 != 0 || strlen(sigVer_sig) != 2 * sig->length_signature || strlen(sigVer_pk) != 2 * sig->length_public_key || - (sigVerPassed != 0 && sigVerPassed != 1) || - (extMu != 0 && extMu != 1)) { + (sigVerPassed != 0 && sigVerPassed != 1)) { printf("lengths bad or incorrect verification status \n"); goto err; } @@ -1226,20 +1412,22 @@ int main(int argc, char **argv) { msgLen = strlen(sigVer_msg) / 2; sigVer_pk_bytes = OQS_MEM_malloc(sig->length_public_key); - sigVer_msg_bytes = OQS_MEM_malloc(msgLen); + sigVer_msg_bytes = (msgLen > 0) ? OQS_MEM_malloc(msgLen) : NULL; sigVer_sig_bytes = OQS_MEM_malloc(strlen(sigVer_sig) / 2); - if ((sigVer_pk_bytes == NULL) || (sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL)) { + if ((sigVer_pk_bytes == NULL) || (msgLen && sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL)) { fprintf(stderr, "[vectors_sig] ERROR: OQS_MEM_malloc failed!\n"); goto err; } hexStringToByteArray(sigVer_pk, sigVer_pk_bytes); - hexStringToByteArray(sigVer_msg, sigVer_msg_bytes); + if (msgLen) { + hexStringToByteArray(sigVer_msg, sigVer_msg_bytes); + } hexStringToByteArray(sigVer_sig, sigVer_sig_bytes); #if defined(OQS_ENABLE_SIG_ml_dsa_44) || defined(OQS_ENABLE_SIG_ml_dsa_65) || defined(OQS_ENABLE_SIG_ml_dsa_87) || defined(OQS_ENABLE_SIG_SLH_DSA) - rc = sig_ver_vector(alg_name, sigVer_pk_bytes, sigVer_msg_bytes, msgLen, sigVer_sig_bytes, strlen(sigVer_sig) / 2, sigVerPassed, extMu); + rc = sig_ver_vector_int(alg_name, sigVer_pk_bytes, sigVer_msg_bytes, msgLen, sigVer_sig_bytes, strlen(sigVer_sig) / 2, sigVerPassed); #else rc = EXIT_SUCCESS; goto cleanup; @@ -1284,21 +1472,23 @@ int main(int argc, char **argv) { ctxlen = strlen(sigVer_ctx) / 2; sigVer_pk_bytes = OQS_MEM_malloc(sig->length_public_key); - sigVer_msg_bytes = OQS_MEM_malloc(msgLen); + sigVer_msg_bytes = (msgLen > 0) ? OQS_MEM_malloc(msgLen) : NULL; sigVer_sig_bytes = OQS_MEM_malloc(strlen(sigVer_sig) / 2); /* allocate memory if required */ if (ctxlen) { sigVer_ctx_bytes = OQS_MEM_malloc(ctxlen); } - if ((sigVer_pk_bytes == NULL) || (sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL) || (ctxlen && sigVer_ctx_bytes == NULL)) { + if ((sigVer_pk_bytes == NULL) || (msgLen && sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL) || (ctxlen && sigVer_ctx_bytes == NULL)) { fprintf(stderr, "[vectors_sig] ERROR: OQS_MEM_malloc failed!\n"); goto err; } hexStringToByteArray(sigVer_pk, sigVer_pk_bytes); - hexStringToByteArray(sigVer_msg, sigVer_msg_bytes); hexStringToByteArray(sigVer_sig, sigVer_sig_bytes); + if (msgLen) { + hexStringToByteArray(sigVer_msg, sigVer_msg_bytes); + } if (ctxlen) { hexStringToByteArray(sigVer_ctx, sigVer_ctx_bytes); } @@ -1310,6 +1500,46 @@ int main(int argc, char **argv) { goto cleanup; #endif + } else if (!strcmp(test_name, "sigVer_extmu")) { + /* vectors_sig alg_name sigVer_extmu pk message signature testPassed ---> (argc 7) */ + if (argc != 7) { + valid_args = false; + goto err; + } + sigVer_pk = argv[3]; + sigVer_msg = argv[4]; + sigVer_sig = argv[5]; + int sigVerPassed = atoi(argv[6]); + + if (strlen(sigVer_msg) % 2 != 0 || + strlen(sigVer_sig) != 2 * sig->length_signature || + strlen(sigVer_pk) != 2 * sig->length_public_key || + (sigVerPassed != 0 && sigVerPassed != 1)) { + printf("lengths bad or incorrect verification status \n"); + goto err; + } + + msgLen = strlen(sigVer_msg) / 2; + sigVer_pk_bytes = OQS_MEM_malloc(sig->length_public_key); + sigVer_msg_bytes = OQS_MEM_malloc(msgLen); + sigVer_sig_bytes = OQS_MEM_malloc(strlen(sigVer_sig) / 2); + + if ((sigVer_pk_bytes == NULL) || (sigVer_msg_bytes == NULL) || (sigVer_sig_bytes == NULL)) { + fprintf(stderr, "[vectors_sig] ERROR: OQS_MEM_malloc failed!\n"); + goto err; + } + + hexStringToByteArray(sigVer_pk, sigVer_pk_bytes); + hexStringToByteArray(sigVer_msg, sigVer_msg_bytes); + hexStringToByteArray(sigVer_sig, sigVer_sig_bytes); + +#if defined(OQS_ENABLE_SIG_ml_dsa_44_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_65_extmu) || defined(OQS_ENABLE_SIG_ml_dsa_87_extmu) + rc = sig_ver_vector_extmu(alg_name, sigVer_pk_bytes, sigVer_msg_bytes, msgLen, sigVer_sig_bytes, strlen(sigVer_sig) / 2, sigVerPassed); +#else + rc = EXIT_SUCCESS; + goto cleanup; +#endif + } else if (!strcmp(test_name, "sigVer_prehash_ext")) { /* vectors_sig alg_name sigVer_int pk message signature context testPassed algname---> (argc 9) */ if (argc != 9) { diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index a1a53c91e0..6abbe0736c 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -106,6 +106,12 @@ if(CONFIG_LIBOQS) set(OQS_ENABLE_SIG_ML_DSA OFF) endif() + if(CONFIG_LIBOQS_ENABLE_SIG_ML_DSA_EXTMU) + set(OQS_ENABLE_SIG_ML_DSA_EXTMU ON) + else() + set(OQS_ENABLE_SIG_ML_DSA_EXTMU OFF) + endif() + if(CONFIG_LIBOQS_ENABLE_SIG_FALCON) set(OQS_ENABLE_SIG_FALCON ON) else() diff --git a/zephyr/samples/Signatures/src/main.c b/zephyr/samples/Signatures/src/main.c index 54bd0eb367..8b607a632b 100644 --- a/zephyr/samples/Signatures/src/main.c +++ b/zephyr/samples/Signatures/src/main.c @@ -35,11 +35,14 @@ static OQS_STATUS sig_test_correctness(const char *method_name) { uint8_t *public_key = NULL; uint8_t *secret_key = NULL; uint8_t *message = NULL; - size_t message_len = 100; + size_t message_len = 64; uint8_t *signature = NULL; size_t signature_len; OQS_STATUS rc, ret = OQS_ERROR; - + // if it is not an extmu variant, use the standard test length of 100 + if (strstr(method_name, "-extmu") == NULL) { + message_len = 100; + } //The magic numbers are random values. //The length of the magic number was chosen to be 31 to break alignment magic_t magic;