-
Notifications
You must be signed in to change notification settings - Fork 41
mlkem_native.h: Introduce MLK_TOTAL_ALLOC constants
#1468
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
Conversation
|
I have included the extension as a separate commit. |
2f4200d to
920f9dd
Compare
c37874d to
a1aac27
Compare
hanno-becker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is slightly confusing to expose MLK_MAX_TOTAL_ALLOC as the maximum across all security levels, even in a single-level build. I'd prefer to only export constants explicitly labeled by a security level.
For consumers implementing custom allocations (in cases where the stack is
not large enough), it may be important to know how much space has to be
reserved for allocations of large structures.
This commit adds per-operation allocation constants:
- MLK_TOTAL_ALLOC_{512,768,1024}_{KEYPAIR,ENCAPS,DECAPS} for each parameter
set and operation, indicating peak memory consumption.
- MLK_MAX_TOTAL_ALLOC_{KEYPAIR,ENCAPS,DECAPS} for maximum across parameter
sets per operation.
- MLK_TOTAL_ALLOC_{512,768,1024} for maximum across operations per parameter
set.
- MLK_MAX_TOTAL_ALLOC for maximum across all parameter sets and operations.
The alloc_test is extended to check that the constants indeed match the peak
memory consumption of the corresponding functions.
- Ported from pq-code-package/mldsa-native#850
- Resolves #1442
Signed-off-by: Matthias J. Kannwischer <[email protected]>
Multilevel builds require MLK_CONFIG_NO_SUPERCOP since the SUPERCOP naming convention (crypto_kem_xxx) does not disambiguate between parameter sets. Add MLK_CONFIG_NO_SUPERCOP to all multilevel build configs and propagate it to the API layer in the legacy config path. This also fixes problem with mlkem_native.h: On multiple inclusions of mlkem_native.h without NO_SUPERCOP set, mlkem_native.h would not undef the API_CONFIG macros in the end of the file causing the second inclusion of mlkem_native.h to set the LEGACY_CONFIG option. - Ported from pq-code-package/mldsa-native#869 Signed-off-by: Matthias J. Kannwischer <[email protected]>
Split KEYPAIR allocation constants into _NO_PCT and _PCT variants to accurately reflect memory usage with and without pairwise consistency testing (PCT). MLK_TOTAL_ALLOC_*_KEYPAIR now automatically selects the appropriate value based on MLK_CONFIG_KEYGEN_PCT. For legacy configs, assume PCT is enabled (conservative). The default alloc test config no longer enables PCT; PCT is tested via config-variations. - Ported from pq-code-package/mldsa-native#869 Signed-off-by: Matthias J. Kannwischer <[email protected]>
Remove MLK_MAX_TOTAL_ALLOC and MLK_MAX_TOTAL_ALLOC_{KEYPAIR,ENCAPS,DECAPS}
constants. These exposed the maximum allocation across all security
levels even in single-level builds, which was confusing. Users should
instead use the explicitly security-level-labeled constants such as
MLK_TOTAL_ALLOC_1024_KEYPAIR.
The per-level MLK_TOTAL_ALLOC_{512,768,1024}_{KEYPAIR,ENCAPS,DECAPS} and
aggregate MLK_TOTAL_ALLOC_{512,768,1024} constants remain available.
Signed-off-by: Matthias J. Kannwischer <[email protected]>
a1aac27 to
26cdf45
Compare
Okay, yes, makes sense. I have removed the macros. Also removed it in mldsa-native in pq-code-package/mldsa-native#869. |
For consumers implementing custom allocations (in cases where the stack is not large enough), it may be important to know how much space has to be reserved for allocations of large structures.
This commit adds per-operation allocation constants:
The alloc_test is extended to check that the constants indeed match the peak memory consumption of the corresponding functions.
I included the extension from #869 that differentiates between keygen w/ and w/o PCT. The commits are kept separate though to follow the same structure as in mldsa-native.
MLD_TOTAL_ALLOCconstants mldsa-native#850