Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Import ML-KEM from mlkem-native/PQ code package #2041

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 27 additions & 3 deletions .CMake/alg_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,43 @@ 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_KEM_ml_kem_512_avx2 "" ON "OQS_ENABLE_KEM_ml_kem_512" OFF)
cmake_dependent_option(OQS_ENABLE_KEM_ml_kem_512_x86_64 "" ON "OQS_ENABLE_KEM_ml_kem_512" OFF)
SWilson4 marked this conversation as resolved.
Show resolved Hide resolved
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_KEM_ml_kem_512_aarch64 "" ON "OQS_ENABLE_KEM_ml_kem_512" 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_KEM_ml_kem_768_avx2 "" ON "OQS_ENABLE_KEM_ml_kem_768" OFF)
cmake_dependent_option(OQS_ENABLE_KEM_ml_kem_768_x86_64 "" ON "OQS_ENABLE_KEM_ml_kem_768" 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_KEM_ml_kem_768_aarch64 "" ON "OQS_ENABLE_KEM_ml_kem_768" 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_KEM_ml_kem_1024_avx2 "" ON "OQS_ENABLE_KEM_ml_kem_1024" OFF)
cmake_dependent_option(OQS_ENABLE_KEM_ml_kem_1024_x86_64 "" ON "OQS_ENABLE_KEM_ml_kem_1024" 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_KEM_ml_kem_1024_aarch64 "" ON "OQS_ENABLE_KEM_ml_kem_1024" OFF)

endif()
endif()

Expand Down
5 changes: 1 addition & 4 deletions docs/algorithms/kem/ml_kem.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- **Authors' website**: https://pq-crystals.org/kyber/ and https://csrc.nist.gov/pubs/fips/203
- **Specification version**: ML-KEM.
- **Primary Source**<a name="primary-source"></a>:
- **Source**: https://github.com/pq-crystals/kyber/commit/10b478fc3cc4ff6215eb0b6a11bd758bf0929cbd with copy_from_upstream patches
- **Source**: https://github.com/bhess/mlkem-native/commit/86cc8d0cd3af1dff13228296cbadbbfc6928890c
- **Implementation license (SPDX-Identifier)**: CC0-1.0 or Apache-2.0


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

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

Expand All @@ -35,7 +34,6 @@ Are implementations chosen based on runtime CPU feature detection? **Yes**.
| Implementation source | Identifier in upstream | Supported architecture(s) | Supported operating system(s) | CPU extension(s) used | No branching-on-secrets claimed? | No branching-on-secrets checked by valgrind? | Large stack usage? |
|:---------------------------------:|:-------------------------|:----------------------------|:--------------------------------|:------------------------|:-----------------------------------|:-----------------------------------------------|:---------------------|
| [Primary Source](#primary-source) | ref | All | All | None | True | True | False |
| [Primary Source](#primary-source) | avx2 | x86\_64 | Linux,Darwin | AVX2,BMI2,POPCNT | True | True | False |

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

Expand All @@ -44,7 +42,6 @@ Are implementations chosen based on runtime CPU feature detection? **Yes**.
| Implementation source | Identifier in upstream | Supported architecture(s) | Supported operating system(s) | CPU extension(s) used | No branching-on-secrets claimed? | No branching-on-secrets checked by valgrind? | Large stack usage? |
|:---------------------------------:|:-------------------------|:----------------------------|:--------------------------------|:------------------------|:-----------------------------------|:-----------------------------------------------|:---------------------|
| [Primary Source](#primary-source) | ref | All | All | None | True | True | False |
| [Primary Source](#primary-source) | avx2 | x86\_64 | Linux,Darwin | AVX2,BMI2,POPCNT | True | True | False |

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

Expand Down
51 changes: 1 addition & 50 deletions docs/algorithms/kem/ml_kem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ website: https://pq-crystals.org/kyber/ and https://csrc.nist.gov/pubs/fips/203
nist-round: FIPS203
spec-version: ML-KEM
primary-upstream:
source: https://github.com/pq-crystals/kyber/commit/10b478fc3cc4ff6215eb0b6a11bd758bf0929cbd
with copy_from_upstream patches
source: https://github.com/bhess/mlkem-native/commit/86cc8d0cd3af1dff13228296cbadbbfc6928890c
spdx-license-identifier: CC0-1.0 or Apache-2.0
parameter-sets:
- name: ML-KEM-512
Expand All @@ -38,22 +37,6 @@ parameter-sets:
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- upstream: primary-upstream
upstream-id: avx2
supported-platforms:
- architecture: x86_64
operating_systems:
- Linux
- Darwin
required_flags:
- avx2
- bmi2
- popcnt
common-crypto:
- SHA3: liboqs
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- name: ML-KEM-768
claimed-nist-level: 3
claimed-security: IND-CCA2
Expand All @@ -71,22 +54,6 @@ parameter-sets:
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- upstream: primary-upstream
upstream-id: avx2
supported-platforms:
- architecture: x86_64
operating_systems:
- Linux
- Darwin
required_flags:
- avx2
- bmi2
- popcnt
common-crypto:
- SHA3: liboqs
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- name: ML-KEM-1024
claimed-nist-level: 5
claimed-security: IND-CCA2
Expand All @@ -104,19 +71,3 @@ parameter-sets:
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
- upstream: primary-upstream
upstream-id: avx2
supported-platforms:
- architecture: x86_64
operating_systems:
- Linux
- Darwin
required_flags:
- avx2
- bmi2
- popcnt
common-crypto:
- SHA3: liboqs
no-secret-dependent-branching-claimed: true
no-secret-dependent-branching-checked-by-valgrind: true
large-stack-usage: false
95 changes: 7 additions & 88 deletions docs/cbom.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
"$schema": "https://raw.githubusercontent.com/CycloneDX/specification/1.6/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:de1355bb-9681-4a7e-8aa9-0ccc414ebe3b",
"serialNumber": "urn:uuid:d66add05-17dd-4986-8894-ed47d1e910b6",
"version": 1,
"metadata": {
"timestamp": "2024-11-05T12:25:53.012740+00:00",
"timestamp": "2024-12-09T14:24:28.343759+00:00",
"component": {
"type": "library",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@69a80f8a66988521d51e94d716cff8c936c07b8d",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@d0d0413dc9fff538296ab86bac492cb4bf54dedb",
"name": "liboqs",
"version": "69a80f8a66988521d51e94d716cff8c936c07b8d"
"version": "d0d0413dc9fff538296ab86bac492cb4bf54dedb"
}
},
"components": [
{
"type": "library",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@69a80f8a66988521d51e94d716cff8c936c07b8d",
"bom-ref": "pkg:github/open-quantum-safe/liboqs@d0d0413dc9fff538296ab86bac492cb4bf54dedb",
baentsch marked this conversation as resolved.
Show resolved Hide resolved
"name": "liboqs",
"version": "69a80f8a66988521d51e94d716cff8c936c07b8d"
"version": "d0d0413dc9fff538296ab86bac492cb4bf54dedb"
},
{
"type": "cryptographic-asset",
Expand Down Expand Up @@ -1060,26 +1060,6 @@
}
}
},
{
"type": "cryptographic-asset",
"bom-ref": "alg:ML-KEM-512:x86_64",
"name": "ML-KEM",
"cryptoProperties": {
"assetType": "algorithm",
"algorithmProperties": {
"parameterSetIdentifier": "ML-KEM-512",
"primitive": "kem",
"executionEnvironment": "software-plain-ram",
"cryptoFunctions": [
"keygen",
"encapsulate",
"decapsulate"
],
"nistQuantumSecurityLevel": 1,
"implementationPlatform": "x86_64"
}
}
},
{
"type": "cryptographic-asset",
"bom-ref": "alg:ML-KEM-768:generic",
Expand All @@ -1100,26 +1080,6 @@
}
}
},
{
"type": "cryptographic-asset",
"bom-ref": "alg:ML-KEM-768:x86_64",
"name": "ML-KEM",
"cryptoProperties": {
"assetType": "algorithm",
"algorithmProperties": {
"parameterSetIdentifier": "ML-KEM-768",
"primitive": "kem",
"executionEnvironment": "software-plain-ram",
"cryptoFunctions": [
"keygen",
"encapsulate",
"decapsulate"
],
"nistQuantumSecurityLevel": 3,
"implementationPlatform": "x86_64"
}
}
},
{
"type": "cryptographic-asset",
"bom-ref": "alg:ML-KEM-1024:generic",
Expand All @@ -1140,26 +1100,6 @@
}
}
},
{
"type": "cryptographic-asset",
"bom-ref": "alg:ML-KEM-1024:x86_64",
"name": "ML-KEM",
"cryptoProperties": {
"assetType": "algorithm",
"algorithmProperties": {
"parameterSetIdentifier": "ML-KEM-1024",
"primitive": "kem",
"executionEnvironment": "software-plain-ram",
"cryptoFunctions": [
"keygen",
"encapsulate",
"decapsulate"
],
"nistQuantumSecurityLevel": 5,
"implementationPlatform": "x86_64"
}
}
},
{
"type": "cryptographic-asset",
"bom-ref": "alg:sntrup761:generic",
Expand Down Expand Up @@ -3127,7 +3067,7 @@
],
"dependencies": [
{
"ref": "pkg:github/open-quantum-safe/liboqs@69a80f8a66988521d51e94d716cff8c936c07b8d",
"ref": "pkg:github/open-quantum-safe/liboqs@d0d0413dc9fff538296ab86bac492cb4bf54dedb",
"provides": [
"alg:BIKE-L1:x86_64",
"alg:BIKE-L3:x86_64",
Expand Down Expand Up @@ -3181,11 +3121,8 @@
"alg:Kyber1024:x86_64",
"alg:Kyber1024:armv8-a",
"alg:ML-KEM-512:generic",
"alg:ML-KEM-512:x86_64",
"alg:ML-KEM-768:generic",
"alg:ML-KEM-768:x86_64",
"alg:ML-KEM-1024:generic",
"alg:ML-KEM-1024:x86_64",
"alg:sntrup761:generic",
"alg:sntrup761:x86_64",
"alg:cross-rsdp-128-balanced:generic",
Expand Down Expand Up @@ -3605,36 +3542,18 @@
"alg:sha3"
]
},
{
"ref": "alg:ML-KEM-512:x86_64",
"dependsOn": [
"alg:sha3"
]
},
{
"ref": "alg:ML-KEM-768:generic",
"dependsOn": [
"alg:sha3"
]
},
{
"ref": "alg:ML-KEM-768:x86_64",
"dependsOn": [
"alg:sha3"
]
},
{
"ref": "alg:ML-KEM-1024:generic",
"dependsOn": [
"alg:sha3"
]
},
{
"ref": "alg:ML-KEM-1024:x86_64",
"dependsOn": [
"alg:sha3"
]
},
{
"ref": "alg:sntrup761:generic",
"dependsOn": [
Expand Down
11 changes: 5 additions & 6 deletions scripts/copy_from_upstream/copy_from_upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ upstreams:
kem_scheme_path: '.'
patches: [pqcrystals-kyber-yml.patch, pqcrystals-kyber-ref-shake-aes.patch, pqcrystals-kyber-avx2-shake-aes.patch]
-
name: pqcrystals-kyber-standard
git_url: https://github.com/pq-crystals/kyber.git
git_branch: main
git_commit: 10b478fc3cc4ff6215eb0b6a11bd758bf0929cbd
name: mlkem-native
git_url: https://github.com/bhess/mlkem-native.git
git_branch: updates-5
git_commit: 86cc8d0cd3af1dff13228296cbadbbfc6928890c
kem_meta_path: '{pretty_name_full}_META.yml'
kem_scheme_path: '.'
patches: [pqcrystals-ml_kem.patch]
-
name: pqcrystals-dilithium
git_url: https://github.com/pq-crystals/dilithium.git
Expand Down Expand Up @@ -166,7 +165,7 @@ kems:
-
name: ml_kem
default_implementation: ref
upstream_location: pqcrystals-kyber-standard
upstream_location: mlkem-native
schemes:
-
scheme: "512"
Expand Down
5 changes: 5 additions & 0 deletions src/common/pqclean_shims/fips202x4.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ void OQS_SHA3_shake256_x4_absorb_once(shake256x4incctx *state, const uint8_t *in
#define shake256x4_squeezeblocks(OUT0, OUT1, OUT2, OUT3, NBLOCKS, STATE) \
OQS_SHA3_shake256_x4_inc_squeeze(OUT0, OUT1, OUT2, OUT3, (NBLOCKS)*OQS_SHA3_SHAKE256_RATE, STATE)

#define shake128x4ctx shake128x4incctx
#define shake128x4_release shake128x4_inc_ctx_release
#define shake128ctx shake128incctx
#define shake128_release shake128_inc_ctx_release

#endif
Loading
Loading