CBMC: Add proofs for native backend functions#768
Conversation
mkannwischer
left a comment
There was a problem hiding this comment.
Thanks @willieyz for this PR.
Since the CBMC proof for polymat_permute_bitrev_to_custom_native is blowing up for ML-DSA-44, could you move just that to a new PR so we can investigate there?
Then we can already review+merge all the other commits.
mkannwischer
left a comment
There was a problem hiding this comment.
Thanks @willieyz. Looking fairly good. Here are some comments what still needs to be adjusted. The decompose contracts are wrong and are a serious soundness issue - the other comments are minor.
The contract for mld_poly_chknorm_native is rather ugly - we should consider simplifying that vastly, but that can be a follow up.
Please remove the TODOs also for mld_poly_use_hint_88_native and mld_poly_use_hint_32_native.
1c2f04d to
5a99425
Compare
Hello, @mkannwischer , thank you for your review! |
mkannwischer
left a comment
There was a problem hiding this comment.
Thanks for the changes @willieyz - I just rechecked everything. LGTM now.
@hanno-becker, could you also take a look please?
|
News: CBMC team have proposed a fix for CBMC that helps with this issue. This is currently on a branch of the CBMC repo awaiting review. For mldsa-native, I still have to re-structure the code of polymat_permite_bitrev_to_custom() to use a nested loop, so that the code structure matches the data structure. With that change, AND the new CBMC, the proofs looks OK. I have the code change - shall I commit and push it here? |
Awesome news. Thanks @rod-chapman for following up. |
|
I have pushed the refactored polymat_permute_bitrev_to_custom() on the cbmc-native2 branch on PR#770. With the new wavefront of CBMC, proofs go through OK. I will push CBMC team to prioritize review and a new tagged release. |
This commit adds CBMC proofs for the native function `mld_ntt_native`,
called `poly_ntt_native`
The following changes are included:
- Add `dummy_backend.h` as a mock backend for `poly_ntt_native`.
- Apply the same harness file and construct function contract
reference from `poly_ntt`.
- Use the following function contracts:
- `mld_ntt_native`
- `mld_poly_ntt_c`
- Introduce a new CBMC contract pattern `array_unchanged` in `cbmc.h`,
which is used to verify the fallback behavior inside `mld_ntt_native`.
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for the native function `mld_intt_native`,
called `poly_invntt_tomont_native`
- This following changes are include:
- Apply the same harness file and construct function contract,
reference from `poly_invntt_tomnot`.
- Use the following function contracts:
- `mld_intt_native`
- `mld_poly_invntt_tomont_c`
- Add MLD_INTT_BOUND in api.h
- Add `MLD_USE_NATIVE_INTT` in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for the native function `mld_rej_uniform_native`,
called `rej_uniform_native`
- This following changes are include:
- Apply the same harness file and construct function contract reference
from `rej_uniform`.
- Use the following function contracts:
- `mld_rej_uniform_native`
- `mld_rej_uniform_c`
- Add `MLD_USE_NATIVE_REJ_UNIFORM` in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
`mld_rej_uniform_eta2_native` and `mld_rej_uniform_eta4_native`,
called `rej_eta_native`.
- This following changes are include:
- Apply the same harness file and construct function contract reference
from rej_eta.
- Use the following function contracts:
- mld_rej_eta_c
- mld_rej_uniform_eta2_native
- mld_rej_uniform_eta4_native
- Add `MLD_USE_NATIVE_REJ_UNIFORM_ETA2`,
`MLD_USE_NATIVE_REJ_UNIFORM_ETA4` in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function:
`mld_poly_decompose_32_native`, `mld_poly_decompose_88_native`.
called `poly_decompose_native`.
- This following changes are include:
- Apply the same harness file and construct function contract reference
from `poly_decompose`.
- Use the following function contracts:
- mld_poly_decompose_c
- mld_poly_decompose_32_native
- mld_poly_decompose_88_native
- Add `MLD_USE_NATIVE_POLY_DECOMPOSE_32`,
`MLD_USE_NATIVE_POLY_DECOMPOSE_88` in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for the native function
`mld_poly_caddq_native`, called `poly_caddq_native`
- This following changes are include:
- Apply the same harness file and construct function contract
reference from `poly_caddq`.
- Use the following function contracts:
- `mld_poly_caddq_c`
- `mld_poly_caddq_native`
- Add `MLD_USE_NATIVE_POLY_CADDQ` in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function: `mld_poly_use_hint_32_native`, `mld_poly_use_hint_88_native`. called `poly_use_hint_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `poly_use_hint`. - Use the following function contracts: - mld_poly_use_hint_c - mld_poly_use_hint_32_native - mld_poly_use_hint_88_native - Add `MLD_USE_NATIVE_POLY_USE_HINT_32`, `MLD_USE_NATIVE_POLY_USE_HINT_88` in dummy_backend.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function: `mld_poly_chknorm_native`, called `poly_chknorm_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `poly_chknorm_native`. - Use the following function contracts: - `mld_poly_chknorm_c` - `mld_poly_chknorm_native` - Add `MLD_USE_NATIVE_POLY_CHKNORM` in dummy_backend.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function: `mld_polyz_unpack_17_native` and `mld_polyz_unpack_19_native`. called `polyz_unpack_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `polyz_unpack`. - Use the following function contracts: - `mld_polyz_unpack_c` - `mld_polyz_unpack_17_native` - `mld_polyz_unpack_17_native` - Add `MLD_USE_NATIVE_POLYZ_UNPACK_17`, `MLD_USE_NATIVE_POLYZ_UNPACK_19` in dummy_backend.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
…omery_native)
- This commit adds CBMC proofs for the native function
`mld_poly_pointwise_montgomery_native`,
called `poly_pointwise_montgomery_native`
- This following changes are include:
- Apply the same harness file and construct function contract,
reference from `poly_pointwise_montgomery`.
- Use the following function contracts:
- `mld_poly_pointwise_montgomery_native`
- `mld_poly_pointwise_montgomery_c`
- Add `MLD_USE_NATIVE_POINTWISE_MONTGOMERY` in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
…ntgomery_native)
- This commit adds CBMC proofs for following the native function:
`mld_polyvecl_pointwise_acc_montgomery_l4_native`,
`mld_polyvecl_pointwise_acc_montgomery_l5_native` and
`mld_polyvecl_pointwise_acc_montgomery_l7_native`
called `polyvecl_pointwise_acc_montgomery_native`.
- This following changes are include:
- Apply the same harness file and construct function contract reference
from `polyvecl_pointwise_acc_montgomery`.
- Use the following function contracts:
- `mld_polyvecl_pointwise_acc_montgomery_l4_native`
- `mld_polyvecl_pointwise_acc_montgomery_l5_native`
- `mld_polyvecl_pointwise_acc_montgomery_l7_native`
- Add `MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L4`,
`MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L5`,
`MLD_USE_NATIVE_POLYVECL_POINTWISE_ACC_MONTGOMERY_L7`
in dummy_backend.h
Signed-off-by: willieyz <willie.zhao@chelpis.com>
- This commit adds CBMC proofs for following the native function: `mld_keccak_f1600_x1_native`, called `keccakf1600_permute_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `keccakf1600_permute`. - Use the following function contracts: - `mld_keccak_f1600_x1_native` - Add `MLD_USE_FIPS202_X1_NATIVE` in dummy_backend_fips202_x1.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
…tive) - This commit adds CBMC proofs for following the native function: `mld_keccak_f1600_x4_native`, called `keccakf1600x4_permute_native`. - This following changes are include: - Apply the same harness file and construct function contract reference from `keccakf1600x4_permute`. - Use the following function contracts: - `mld_keccak_f1600_x4_native` - Add `MLD_USE_FIPS202_X4_NATIVE` in dummy_backend_fips202_x4.h Signed-off-by: willieyz <willie.zhao@chelpis.com>
5a99425 to
6c5e234
Compare
Related CBMC: Add proofs atop of native functions #350
This commit adds CBMC proofs for 14 native backend functions across arithmetic and FIPS-202 operations:
Arithmetic Backend:
poly_ntt_nativemld_ntt_nativepoly_invntt_tomont_nativemld_intt_nativemld_poly_permute_bitrev_to_customrej_uniform_nativemld_rej_uniform_nativerej_eta_nativemld_rej_uniform_eta2_nativemld_rej_uniform_eta4_nativepoly_decompose_nativemld_poly_decompose_32_nativemld_poly_decompose_88_nativepoly_caddq_nativemld_poly_caddq_nativepoly_use_hint_nativemld_poly_use_hint_32_nativemld_poly_use_hint_88_nativepoly_chknorm_nativemld_poly_chknorm_nativepolyz_unpack_nativemld_polyz_unpack_17_nativemld_polyz_unpack_19_nativepoly_pointwise_montgomery_nativemld_poly_pointwise_montgomery_nativepolyvecl_pointwise_acc_montgomery_nativemld_polyvecl_pointwise_acc_montgomery_l4_nativemld_polyvecl_pointwise_acc_montgomery_l5_nativemld_polyvecl_pointwise_acc_montgomery_l7_nativekeccakf1600_permute_nativemld_keccak_f1600_x1_nativekeccakf1600x4_permute_nativemld_keccak_f1600_x4_nativeThis PR adds CBMC proofs for all native backend functions except one. We temporarily skip mld_poly_permute_bitrev_to_custom because its proof times out during CBMC ML-DSA-44 checking. Have already asked for help from @mkannwischer and @rod-chapman, and we will open a separate pull request: #770 , to address this issue.
Each proof reuses the harness and add contracts that reference from the corresponding C implementation, verifying that native backends satisfy the same specifications. Proofs use a corresponding mock backend (
dummy_backend.h,dummy_backend_fips202_x1,dummy_backend_fips202_x4).This PR made follwoing changes
mld_polymat_permute_bitrev_to_customfrom double to single loop for proof tractabilityTest steps:
make clean & MLD_CONFIG_PARAMETER_SET=44/65/87 make resultchecking the contract itself.tests cbmc -p "parrent_proof", this will check the parrent proof, for examples:tests cbmc -p poly_nttwill checkpoly_ntt,poly_ntt_c,poly_ntt_nativewith 3 security level.