Skip to content

Commit 36e8b7b

Browse files
committed
autogen: Regenerate configs for the signing hooks
Rerun scripts/autogen after the preceding commits, updating various files. Done separately to ease reviewing of the core of the changes. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent f08a717 commit 36e8b7b

33 files changed

Lines changed: 3331 additions & 192 deletions

File tree

BIBLIOGRAPHY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ source code and documentation.
8282
- [examples/monolithic_build_native/mldsa_native/mldsa_native_config.h](examples/monolithic_build_native/mldsa_native/mldsa_native_config.h)
8383
- [examples/multilevel_build/mldsa_native/mldsa_native_config.h](examples/multilevel_build/mldsa_native/mldsa_native_config.h)
8484
- [examples/multilevel_build_native/mldsa_native/mldsa_native_config.h](examples/multilevel_build_native/mldsa_native/mldsa_native_config.h)
85+
- [examples/restartable_sign/mldsa_native/mldsa_native_config.h](examples/restartable_sign/mldsa_native/mldsa_native_config.h)
8586
- [integration/liboqs/config_aarch64.h](integration/liboqs/config_aarch64.h)
8687
- [integration/liboqs/config_c.h](integration/liboqs/config_c.h)
8788
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
@@ -103,6 +104,7 @@ source code and documentation.
103104
- [test/configs/no_asm_config.h](test/configs/no_asm_config.h)
104105
- [test/configs/serial_fips202_config.h](test/configs/serial_fips202_config.h)
105106
- [test/configs/test_alloc_config.h](test/configs/test_alloc_config.h)
107+
- [test/configs/test_sign_hook_config.h](test/configs/test_sign_hook_config.h)
106108

107109
### `FIPS202`
108110

@@ -133,6 +135,7 @@ source code and documentation.
133135
- [examples/monolithic_build_native/mldsa_native/mldsa_native_config.h](examples/monolithic_build_native/mldsa_native/mldsa_native_config.h)
134136
- [examples/multilevel_build/mldsa_native/mldsa_native_config.h](examples/multilevel_build/mldsa_native/mldsa_native_config.h)
135137
- [examples/multilevel_build_native/mldsa_native/mldsa_native_config.h](examples/multilevel_build_native/mldsa_native/mldsa_native_config.h)
138+
- [examples/restartable_sign/mldsa_native/mldsa_native_config.h](examples/restartable_sign/mldsa_native/mldsa_native_config.h)
136139
- [mldsa/mldsa_native.h](mldsa/mldsa_native.h)
137140
- [mldsa/mldsa_native_config.h](mldsa/mldsa_native_config.h)
138141
- [mldsa/src/ct.h](mldsa/src/ct.h)
@@ -166,6 +169,8 @@ source code and documentation.
166169
- [test/configs/no_asm_config.h](test/configs/no_asm_config.h)
167170
- [test/configs/serial_fips202_config.h](test/configs/serial_fips202_config.h)
168171
- [test/configs/test_alloc_config.h](test/configs/test_alloc_config.h)
172+
- [test/configs/test_sign_hook_config.h](test/configs/test_sign_hook_config.h)
173+
- [test/src/test_sign_hook.c](test/src/test_sign_hook.c)
169174

170175
### `HYBRID`
171176

examples/basic_deterministic/mldsa_native/mldsa_native_config.h

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,24 +700,108 @@
700700
/**
701701
* MLD_CONFIG_CONTEXT_PARAMETER
702702
*
703-
* Set this to add a context parameter that is provided to public
704-
* API functions and is then available in custom callbacks.
703+
* Set this to add a caller-supplied context parameter to the public API
704+
* functions, which is then forwarded unchanged to the custom callbacks
705+
* (allocation, and signing hooks below).
705706
*
706-
* The type of the context parameter is configured via
707-
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
707+
* When this option is set, every public API function gains a trailing
708+
* parameter
709+
*
710+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
711+
*
712+
* as its last argument; its type is configured via
713+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE (see below). mldsa-native treats this
714+
* value as opaque: it never dereferences it and only passes it on to the
715+
* configurable hook macros. It is meant to carry per-caller state -- e.g. a
716+
* pointer to a memory pool for the allocation hooks, or the resume state for
717+
* the signing hooks -- into those hooks.
718+
*
719+
* When this option is unset (the default), no extra parameter is added and
720+
* the hook macros never receive a context argument.
721+
*
722+
* The hooks that receive the context are the allocation hooks (see
723+
* MLD_CONFIG_CUSTOM_ALLOC_FREE) and the signing hooks (see
724+
* MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH); each is documented with
725+
* its own option below.
708726
*/
709727
/* #define MLD_CONFIG_CONTEXT_PARAMETER */
710728

711729
/**
712730
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE
713731
*
714-
* Set this to define the type for the context parameter used by
715-
* MLD_CONFIG_CONTEXT_PARAMETER.
732+
* Set this to define the type of the context parameter added by
733+
* MLD_CONFIG_CONTEXT_PARAMETER. It can be any C type usable as a function
734+
* parameter, e.g. `void *` or a pointer to a caller-defined struct such as
735+
* `struct my_ctx *`.
716736
*
717-
* This is only relevant if MLD_CONFIG_CONTEXT_PARAMETER is set.
737+
* This option must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is
738+
* defined; defining one without the other is a compile-time error.
718739
*/
719740
/* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
720741

742+
/**
743+
* Signing hooks: MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH
744+
*
745+
* Three optional, independent hooks into the ML-DSA signing rejection-sampling
746+
* loop. Each is enabled by defining the matching option, in which case the
747+
* integration MUST provide the corresponding function. If a hook needs
748+
* per-operation state, enable MLD_CONFIG_CONTEXT_PARAMETER; the context is then
749+
* appended as the last argument.
750+
*
751+
* @warning This feature is experimental. Its scope, configuration and
752+
* function signatures may change at any time, including after v1.
753+
*
754+
* - MLD_CONFIG_SIGN_HOOK_RESUME: uint16_t mld_sign_hook_resume([ctxt])
755+
* Returns the attempt to resume from (0 for a fresh operation), i.e. the one
756+
* recorded when a previous call paused. Re-invoking signing with the same
757+
* message, sk and rnd then reproduces the signature of an uninterrupted run.
758+
* Correct only if the randomness is fixed across calls, so this requires
759+
* MLD_CONFIG_NO_RANDOMIZED_API (deterministic mld_sign_signature_internal /
760+
* _extmu), which in turn rules out MLD_CONFIG_KEYGEN_PCT.
761+
*
762+
* - MLD_CONFIG_SIGN_HOOK_ATTEMPT: int mld_sign_hook_attempt(attempt[, ctxt])
763+
* Called before each attempt. Returns 0 to proceed, or non-zero to pause:
764+
* signing then returns MLD_ERR_SIGNING_PAUSED with `attempt` as the resume
765+
* point (needs MLD_CONFIG_SIGN_HOOK_RESUME to resume; otherwise just aborts).
766+
* Always returning 0 makes it a logging/benchmarking hook. Incompatible with
767+
* MLD_CONFIG_KEYGEN_PCT: the PCT signs a single internal signature that
768+
* mldsa-native cannot re-enter, so a paused PCT could not be resumed.
769+
*
770+
* - MLD_CONFIG_SIGN_HOOK_FINISH: void mld_sign_hook_finish(attempt[, ctxt])
771+
* Called on success with the succeeding attempt. Observe-only.
772+
*
773+
* When an option is unset, the hook is a no-op (resume to 0, attempt proceeds),
774+
* i.e. ordinary one-shot signing.
775+
*
776+
* Independent of MLD_CONFIG_MAX_SIGNING_ATTEMPTS (the hard attempt bound, >=
777+
* 814 for FIPS 204, returning MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED): do not lower
778+
* that to pause/restart -- use the attempt hook (MLD_ERR_SIGNING_PAUSED)
779+
* instead.
780+
*
781+
* See test/src/test_sign_hook.c for a worked example using all three.
782+
*/
783+
/* #define MLD_CONFIG_SIGN_HOOK_RESUME
784+
#define MLD_CONFIG_SIGN_HOOK_ATTEMPT
785+
#define MLD_CONFIG_SIGN_HOOK_FINISH
786+
#if !defined(__ASSEMBLER__)
787+
#include <stdint.h>
788+
#include "src/sys.h"
789+
static MLD_INLINE uint16_t mld_sign_hook_resume(void)
790+
{
791+
... return the attempt to resume from ...
792+
}
793+
static MLD_INLINE int mld_sign_hook_attempt(uint16_t attempt)
794+
{
795+
... return non-zero to pause here; for resume, store attempt ...
796+
return 0;
797+
}
798+
static MLD_INLINE void mld_sign_hook_finish(uint16_t attempt)
799+
{
800+
... mark the operation complete (attempt = successful attempt) ...
801+
}
802+
#endif
803+
*/
804+
721805
/**
722806
* MLD_CONFIG_REDUCE_RAM
723807
*

examples/basic_lowram/mldsa_native/mldsa_native_config.h

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,24 +699,108 @@
699699
/**
700700
* MLD_CONFIG_CONTEXT_PARAMETER
701701
*
702-
* Set this to add a context parameter that is provided to public
703-
* API functions and is then available in custom callbacks.
702+
* Set this to add a caller-supplied context parameter to the public API
703+
* functions, which is then forwarded unchanged to the custom callbacks
704+
* (allocation, and signing hooks below).
704705
*
705-
* The type of the context parameter is configured via
706-
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
706+
* When this option is set, every public API function gains a trailing
707+
* parameter
708+
*
709+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
710+
*
711+
* as its last argument; its type is configured via
712+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE (see below). mldsa-native treats this
713+
* value as opaque: it never dereferences it and only passes it on to the
714+
* configurable hook macros. It is meant to carry per-caller state -- e.g. a
715+
* pointer to a memory pool for the allocation hooks, or the resume state for
716+
* the signing hooks -- into those hooks.
717+
*
718+
* When this option is unset (the default), no extra parameter is added and
719+
* the hook macros never receive a context argument.
720+
*
721+
* The hooks that receive the context are the allocation hooks (see
722+
* MLD_CONFIG_CUSTOM_ALLOC_FREE) and the signing hooks (see
723+
* MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH); each is documented with
724+
* its own option below.
707725
*/
708726
/* #define MLD_CONFIG_CONTEXT_PARAMETER */
709727

710728
/**
711729
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE
712730
*
713-
* Set this to define the type for the context parameter used by
714-
* MLD_CONFIG_CONTEXT_PARAMETER.
731+
* Set this to define the type of the context parameter added by
732+
* MLD_CONFIG_CONTEXT_PARAMETER. It can be any C type usable as a function
733+
* parameter, e.g. `void *` or a pointer to a caller-defined struct such as
734+
* `struct my_ctx *`.
715735
*
716-
* This is only relevant if MLD_CONFIG_CONTEXT_PARAMETER is set.
736+
* This option must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is
737+
* defined; defining one without the other is a compile-time error.
717738
*/
718739
/* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
719740

741+
/**
742+
* Signing hooks: MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH
743+
*
744+
* Three optional, independent hooks into the ML-DSA signing rejection-sampling
745+
* loop. Each is enabled by defining the matching option, in which case the
746+
* integration MUST provide the corresponding function. If a hook needs
747+
* per-operation state, enable MLD_CONFIG_CONTEXT_PARAMETER; the context is then
748+
* appended as the last argument.
749+
*
750+
* @warning This feature is experimental. Its scope, configuration and
751+
* function signatures may change at any time, including after v1.
752+
*
753+
* - MLD_CONFIG_SIGN_HOOK_RESUME: uint16_t mld_sign_hook_resume([ctxt])
754+
* Returns the attempt to resume from (0 for a fresh operation), i.e. the one
755+
* recorded when a previous call paused. Re-invoking signing with the same
756+
* message, sk and rnd then reproduces the signature of an uninterrupted run.
757+
* Correct only if the randomness is fixed across calls, so this requires
758+
* MLD_CONFIG_NO_RANDOMIZED_API (deterministic mld_sign_signature_internal /
759+
* _extmu), which in turn rules out MLD_CONFIG_KEYGEN_PCT.
760+
*
761+
* - MLD_CONFIG_SIGN_HOOK_ATTEMPT: int mld_sign_hook_attempt(attempt[, ctxt])
762+
* Called before each attempt. Returns 0 to proceed, or non-zero to pause:
763+
* signing then returns MLD_ERR_SIGNING_PAUSED with `attempt` as the resume
764+
* point (needs MLD_CONFIG_SIGN_HOOK_RESUME to resume; otherwise just aborts).
765+
* Always returning 0 makes it a logging/benchmarking hook. Incompatible with
766+
* MLD_CONFIG_KEYGEN_PCT: the PCT signs a single internal signature that
767+
* mldsa-native cannot re-enter, so a paused PCT could not be resumed.
768+
*
769+
* - MLD_CONFIG_SIGN_HOOK_FINISH: void mld_sign_hook_finish(attempt[, ctxt])
770+
* Called on success with the succeeding attempt. Observe-only.
771+
*
772+
* When an option is unset, the hook is a no-op (resume to 0, attempt proceeds),
773+
* i.e. ordinary one-shot signing.
774+
*
775+
* Independent of MLD_CONFIG_MAX_SIGNING_ATTEMPTS (the hard attempt bound, >=
776+
* 814 for FIPS 204, returning MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED): do not lower
777+
* that to pause/restart -- use the attempt hook (MLD_ERR_SIGNING_PAUSED)
778+
* instead.
779+
*
780+
* See test/src/test_sign_hook.c for a worked example using all three.
781+
*/
782+
/* #define MLD_CONFIG_SIGN_HOOK_RESUME
783+
#define MLD_CONFIG_SIGN_HOOK_ATTEMPT
784+
#define MLD_CONFIG_SIGN_HOOK_FINISH
785+
#if !defined(__ASSEMBLER__)
786+
#include <stdint.h>
787+
#include "src/sys.h"
788+
static MLD_INLINE uint16_t mld_sign_hook_resume(void)
789+
{
790+
... return the attempt to resume from ...
791+
}
792+
static MLD_INLINE int mld_sign_hook_attempt(uint16_t attempt)
793+
{
794+
... return non-zero to pause here; for resume, store attempt ...
795+
return 0;
796+
}
797+
static MLD_INLINE void mld_sign_hook_finish(uint16_t attempt)
798+
{
799+
... mark the operation complete (attempt = successful attempt) ...
800+
}
801+
#endif
802+
*/
803+
720804
/**
721805
* MLD_CONFIG_REDUCE_RAM
722806
*

examples/bring_your_own_fips202/mldsa_native/mldsa_native_config.h

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,24 +700,108 @@
700700
/**
701701
* MLD_CONFIG_CONTEXT_PARAMETER
702702
*
703-
* Set this to add a context parameter that is provided to public
704-
* API functions and is then available in custom callbacks.
703+
* Set this to add a caller-supplied context parameter to the public API
704+
* functions, which is then forwarded unchanged to the custom callbacks
705+
* (allocation, and signing hooks below).
705706
*
706-
* The type of the context parameter is configured via
707-
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE.
707+
* When this option is set, every public API function gains a trailing
708+
* parameter
709+
*
710+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE context
711+
*
712+
* as its last argument; its type is configured via
713+
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE (see below). mldsa-native treats this
714+
* value as opaque: it never dereferences it and only passes it on to the
715+
* configurable hook macros. It is meant to carry per-caller state -- e.g. a
716+
* pointer to a memory pool for the allocation hooks, or the resume state for
717+
* the signing hooks -- into those hooks.
718+
*
719+
* When this option is unset (the default), no extra parameter is added and
720+
* the hook macros never receive a context argument.
721+
*
722+
* The hooks that receive the context are the allocation hooks (see
723+
* MLD_CONFIG_CUSTOM_ALLOC_FREE) and the signing hooks (see
724+
* MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH); each is documented with
725+
* its own option below.
708726
*/
709727
/* #define MLD_CONFIG_CONTEXT_PARAMETER */
710728

711729
/**
712730
* MLD_CONFIG_CONTEXT_PARAMETER_TYPE
713731
*
714-
* Set this to define the type for the context parameter used by
715-
* MLD_CONFIG_CONTEXT_PARAMETER.
732+
* Set this to define the type of the context parameter added by
733+
* MLD_CONFIG_CONTEXT_PARAMETER. It can be any C type usable as a function
734+
* parameter, e.g. `void *` or a pointer to a caller-defined struct such as
735+
* `struct my_ctx *`.
716736
*
717-
* This is only relevant if MLD_CONFIG_CONTEXT_PARAMETER is set.
737+
* This option must be defined if and only if MLD_CONFIG_CONTEXT_PARAMETER is
738+
* defined; defining one without the other is a compile-time error.
718739
*/
719740
/* #define MLD_CONFIG_CONTEXT_PARAMETER_TYPE void* */
720741

742+
/**
743+
* Signing hooks: MLD_CONFIG_SIGN_HOOK_RESUME / _ATTEMPT / _FINISH
744+
*
745+
* Three optional, independent hooks into the ML-DSA signing rejection-sampling
746+
* loop. Each is enabled by defining the matching option, in which case the
747+
* integration MUST provide the corresponding function. If a hook needs
748+
* per-operation state, enable MLD_CONFIG_CONTEXT_PARAMETER; the context is then
749+
* appended as the last argument.
750+
*
751+
* @warning This feature is experimental. Its scope, configuration and
752+
* function signatures may change at any time, including after v1.
753+
*
754+
* - MLD_CONFIG_SIGN_HOOK_RESUME: uint16_t mld_sign_hook_resume([ctxt])
755+
* Returns the attempt to resume from (0 for a fresh operation), i.e. the one
756+
* recorded when a previous call paused. Re-invoking signing with the same
757+
* message, sk and rnd then reproduces the signature of an uninterrupted run.
758+
* Correct only if the randomness is fixed across calls, so this requires
759+
* MLD_CONFIG_NO_RANDOMIZED_API (deterministic mld_sign_signature_internal /
760+
* _extmu), which in turn rules out MLD_CONFIG_KEYGEN_PCT.
761+
*
762+
* - MLD_CONFIG_SIGN_HOOK_ATTEMPT: int mld_sign_hook_attempt(attempt[, ctxt])
763+
* Called before each attempt. Returns 0 to proceed, or non-zero to pause:
764+
* signing then returns MLD_ERR_SIGNING_PAUSED with `attempt` as the resume
765+
* point (needs MLD_CONFIG_SIGN_HOOK_RESUME to resume; otherwise just aborts).
766+
* Always returning 0 makes it a logging/benchmarking hook. Incompatible with
767+
* MLD_CONFIG_KEYGEN_PCT: the PCT signs a single internal signature that
768+
* mldsa-native cannot re-enter, so a paused PCT could not be resumed.
769+
*
770+
* - MLD_CONFIG_SIGN_HOOK_FINISH: void mld_sign_hook_finish(attempt[, ctxt])
771+
* Called on success with the succeeding attempt. Observe-only.
772+
*
773+
* When an option is unset, the hook is a no-op (resume to 0, attempt proceeds),
774+
* i.e. ordinary one-shot signing.
775+
*
776+
* Independent of MLD_CONFIG_MAX_SIGNING_ATTEMPTS (the hard attempt bound, >=
777+
* 814 for FIPS 204, returning MLD_ERR_SIGN_ATTEMPTS_EXHAUSTED): do not lower
778+
* that to pause/restart -- use the attempt hook (MLD_ERR_SIGNING_PAUSED)
779+
* instead.
780+
*
781+
* See test/src/test_sign_hook.c for a worked example using all three.
782+
*/
783+
/* #define MLD_CONFIG_SIGN_HOOK_RESUME
784+
#define MLD_CONFIG_SIGN_HOOK_ATTEMPT
785+
#define MLD_CONFIG_SIGN_HOOK_FINISH
786+
#if !defined(__ASSEMBLER__)
787+
#include <stdint.h>
788+
#include "src/sys.h"
789+
static MLD_INLINE uint16_t mld_sign_hook_resume(void)
790+
{
791+
... return the attempt to resume from ...
792+
}
793+
static MLD_INLINE int mld_sign_hook_attempt(uint16_t attempt)
794+
{
795+
... return non-zero to pause here; for resume, store attempt ...
796+
return 0;
797+
}
798+
static MLD_INLINE void mld_sign_hook_finish(uint16_t attempt)
799+
{
800+
... mark the operation complete (attempt = successful attempt) ...
801+
}
802+
#endif
803+
*/
804+
721805
/**
722806
* MLD_CONFIG_REDUCE_RAM
723807
*

0 commit comments

Comments
 (0)