Skip to content
Merged
19 changes: 14 additions & 5 deletions crypto/fipsmodule/ml_dsa/ml_dsa_ref/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int ml_dsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk, uint8_t *see
* - uint8_t *sk: pointer to bit-packed secret key
* - int external_mu: indicates input message m is to be processed as mu
*
* Returns 0 (success) or -1 (context string too long)
* Returns 0 (success) or -1 (context string too long or incorrect mlen in external mu)
**************************************************/
int ml_dsa_sign_internal(ml_dsa_params *params,
uint8_t *sig,
Expand All @@ -184,6 +184,10 @@ int ml_dsa_sign_internal(ml_dsa_params *params,
ml_dsa_poly cp;
KECCAK1600_CTX state;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'KECCAK1600_CTX' [clang-diagnostic-error]

  KECCAK1600_CTX state;
  ^


if (external_mu && mlen != ML_DSA_CRHBYTES) {
return -1;
}

rho = seedbuf;
tr = rho + ML_DSA_SEEDBYTES;
key = tr + ML_DSA_TRBYTES;
Expand Down Expand Up @@ -346,12 +350,12 @@ int ml_dsa_sign(ml_dsa_params *params,
if (!RAND_bytes(rnd, ML_DSA_RNDBYTES)) {
return -1;
}
ml_dsa_sign_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk, 0);
int ret = ml_dsa_sign_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk, 0);

/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(pre, sizeof(pre));
OPENSSL_cleanse(rnd, sizeof(rnd));
return 0;
return ret;
}

/*************************************************
Expand Down Expand Up @@ -380,11 +384,11 @@ int ml_dsa_extmu_sign(ml_dsa_params *params,
if (!RAND_bytes(rnd, ML_DSA_RNDBYTES)) {
return -1;
}
ml_dsa_sign_internal(params, sig, siglen, mu, mulen, NULL, 0, rnd, sk, 1);
int ret = ml_dsa_sign_internal(params, sig, siglen, mu, mulen, NULL, 0, rnd, sk, 1);

/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(rnd, sizeof(rnd));
return 0;
return ret;
}

/*************************************************
Expand Down Expand Up @@ -469,6 +473,11 @@ int ml_dsa_verify_internal(ml_dsa_params *params,
if(siglen != params->bytes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add space here if <space> ( ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a mix of if's with and without -- for now I can live with this

return -1;
}

if (external_mu && mlen != ML_DSA_CRHBYTES) {
return -1;
}

/* FIPS 204: line 1 */
ml_dsa_unpack_pk(params, rho, &t1, pk);
/* FIPS 204: line 2 */
Expand Down
Loading