Skip to content

Commit

Permalink
cleanse fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemas committed Dec 2, 2024
1 parent f4c32a4 commit 0f43f79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crypto/dilithium/pqcrystals_dilithium_ref_common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ that initialize a given structure with values corresponding to a parameter set.
- `reduce.c`: a small fix to documentation has been made on the bounds of `reduce32`.
- `poly.c`: a small fix to documentation has been made on the bounds of `poly_reduce`.
- `polyvec.c`: a small fix to documentation has been made on the bounds of `polyveck_reduce`.
- Documentation has been added to `ntt.c`, `packing.c`, `poly.c`, `polyvec.c`, and `reduce.c` that outlines the algorithm specification (including algorithm number) in FIPS 204.
- Documentation has been added to `ntt.c`, `packing.c`, `poly.c`, `polyvec.c`, and `rounding.c` that outlines the algorithm specification (including algorithm number) in FIPS 204.
- `poly.c` and `sign.c` have been modified to cleanse intermediate data as soon as it is no longer needed as defined in FIPS 204 Section 3.6.3.

**Testing**
Expand Down
4 changes: 4 additions & 0 deletions crypto/dilithium/pqcrystals_dilithium_ref_common/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ void poly_uniform(poly *a,
}
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(&state, sizeof(state));
}

/*************************************************
Expand Down Expand Up @@ -406,6 +407,7 @@ void poly_uniform_eta(ml_dsa_params *params,
}
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(&state, sizeof(state));
}

/*************************************************
Expand Down Expand Up @@ -434,6 +436,7 @@ void poly_uniform_gamma1(ml_dsa_params *params,
polyz_unpack(params, a, buf);
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(&state, sizeof(state));
}

/*************************************************
Expand Down Expand Up @@ -483,6 +486,7 @@ void poly_challenge(ml_dsa_params *params, poly *c, const uint8_t *seed) {
}
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(&state, sizeof(state));
}

/*************************************************
Expand Down
18 changes: 10 additions & 8 deletions crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ int crypto_sign_keypair_internal(ml_dsa_params *params,
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(seedbuf, sizeof(seedbuf));
OPENSSL_cleanse(tr, sizeof(tr));
OPENSSL_cleanse(&rho, sizeof(rho));
OPENSSL_cleanse(&rhoprime, sizeof(rhoprime));
OPENSSL_cleanse(&key, sizeof(key));
OPENSSL_cleanse(&rho, SEEDBYTES);
OPENSSL_cleanse(&rhoprime, CRHBYTES);
OPENSSL_cleanse(&key, SEEDBYTES);
OPENSSL_cleanse(mat, sizeof(mat));
OPENSSL_cleanse(&s1, sizeof(s1));
OPENSSL_cleanse(&s1hat, sizeof(s1hat));
Expand Down Expand Up @@ -240,12 +240,13 @@ int crypto_sign_signature_internal(ml_dsa_params *params,
*siglen = params->bytes;

/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(&n, sizeof(n));
OPENSSL_cleanse(seedbuf, sizeof(seedbuf));
OPENSSL_cleanse(rho, sizeof(rho));
OPENSSL_cleanse(tr, sizeof(tr));
OPENSSL_cleanse(key, sizeof(key));
OPENSSL_cleanse(mu, sizeof(mu));
OPENSSL_cleanse(rhoprime, sizeof(rhoprime));
OPENSSL_cleanse(rho, SEEDBYTES);
OPENSSL_cleanse(tr, TRBYTES);
OPENSSL_cleanse(key, SEEDBYTES);
OPENSSL_cleanse(mu, CRHBYTES);
OPENSSL_cleanse(rhoprime, CRHBYTES);
OPENSSL_cleanse(&nonce, sizeof(nonce));
OPENSSL_cleanse(mat, sizeof(mat));
OPENSSL_cleanse(&s1, sizeof(s1));
Expand Down Expand Up @@ -443,6 +444,7 @@ int crypto_sign_verify_internal(ml_dsa_params *params,
}
}
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(&i, sizeof(i));
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(rho, sizeof(rho));
OPENSSL_cleanse(mu, sizeof(mu));
Expand Down

0 comments on commit 0f43f79

Please sign in to comment.