Skip to content

Commit

Permalink
removed deterministic mode, edit pqdsa test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemas committed Nov 20, 2024
1 parent dc471ec commit aada875
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 61 deletions.
27 changes: 16 additions & 11 deletions crypto/dilithium/p_pqdsa_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ TEST_P(PQDSAParameterTest, KAT) {
size_t pk_len = GetParam().public_key_len;
size_t sk_len = GetParam().private_key_len;
size_t sig_len = GetParam().signature_len;
std::string name = GetParam().name;

std::vector<uint8_t> pub(pk_len);
std::vector<uint8_t> priv(sk_len);
Expand All @@ -398,7 +399,9 @@ TEST_P(PQDSAParameterTest, KAT) {

// Generate key pair from seed xi and assert that public and private keys
// are equal to expected values from KAT
ASSERT_TRUE(ml_dsa_65_keypair_internal(pub.data(),priv.data(),xi.data()));
if (name == "MLDSA65") {
ASSERT_TRUE(ml_dsa_65_keypair_internal(pub.data(),priv.data(),xi.data()));
}
EXPECT_EQ(Bytes(pub), Bytes(pk));
EXPECT_EQ(Bytes(priv), Bytes(sk));

Expand All @@ -411,16 +414,18 @@ TEST_P(PQDSAParameterTest, KAT) {

// Generate signature by signing |msg|, assert that signature is equal
// to expected value from KAT, then verify signature.
ASSERT_TRUE(ml_dsa_65_sign_internal(priv.data(),
signature.data(), &sig_len,
msg.data(), mlen_int,
m_prime,m_prime_len,
rng.data()));
ASSERT_EQ(Bytes(signature), Bytes(sm));
ASSERT_TRUE(ml_dsa_65_verify_internal(pub.data(),
signature.data(), sig_len,
msg.data(), mlen_int,
m_prime, m_prime_len));
if (name == "MLDSA65") {
ASSERT_TRUE(ml_dsa_65_sign_internal(priv.data(),
signature.data(), &sig_len,
msg.data(), mlen_int,
m_prime,m_prime_len,
rng.data()));
ASSERT_EQ(Bytes(signature), Bytes(sm));
ASSERT_TRUE(ml_dsa_65_verify_internal(pub.data(),
signature.data(), sig_len,
msg.data(), mlen_int,
m_prime, m_prime_len));
}
});
}

Expand Down
44 changes: 0 additions & 44 deletions crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,50 +267,6 @@ int crypto_sign_signature(ml_dsa_params *params,
return 0;
}

/*************************************************
* Name: crypto_sign_signature_deterministic
*
* Description: FIPS 204: Algorithm 2 ML-DSA.Sign.
* Computes signature in determinsitic mode.
*
* Arguments: - uint8_t *sig: pointer to output signature (of length CRYPTO_BYTES)
* - size_t *siglen: pointer to output length of signature
* - uint8_t *m: pointer to message to be signed
* - size_t mlen: length of message
* - uint8_t *ctx: pointer to contex string
* - size_t ctxlen: length of contex string
* - uint8_t *sk: pointer to bit-packed secret key
*
* Returns 0 (success) or -1 (context string too long)
**************************************************/
int crypto_sign_signature_deterministic(ml_dsa_params *params,
uint8_t *sig,
size_t *siglen,
const uint8_t *m,
size_t mlen,
const uint8_t *ctx,
size_t ctxlen,
const uint8_t *sk)
{
uint8_t pre[257];
uint8_t rnd[RNDBYTES];

if(ctxlen > 255) {
return -1;
}
/* Prepare pre = (0, ctxlen, ctx) */
pre[0] = 0;
pre[1] = ctxlen;
OPENSSL_memcpy(pre + 2 , ctx, ctxlen);

// For deterministic modes, |rnd| is all zeros
for(size_t i = 0; i < RNDBYTES; i++) {
rnd[i] = 0;
}
crypto_sign_signature_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk);
return 0;
}

/*************************************************
* Name: crypto_sign
*
Expand Down
6 changes: 0 additions & 6 deletions crypto/dilithium/pqcrystals_dilithium_ref_common/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ int crypto_sign_signature(ml_dsa_params *params,
const uint8_t *ctx, size_t ctxlen,
const uint8_t *sk);

int crypto_sign_signature_deterministic(ml_dsa_params *params,
uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
const uint8_t *ctx, size_t ctxlen,
const uint8_t *sk);

int crypto_sign_signature_internal(ml_dsa_params *params,
uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
Expand Down

0 comments on commit aada875

Please sign in to comment.