Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.o
cryptofuzz
/cryptofuzz
generate_corpus
generate_dict
modules/*/*.a
Expand Down
4 changes: 4 additions & 0 deletions include/cryptofuzz/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ class KDF_SRTP : public Operation {
key.Serialize(ds);
salt.Serialize(ds);
ds.Put<>(kdr);
ds.Put<>(index);
ds.Put<>(key1Size);
ds.Put<>(key2Size);
ds.Put<>(key3Size);
Expand Down Expand Up @@ -931,6 +932,7 @@ class KDF_SRTCP : public Operation {
key.Serialize(ds);
salt.Serialize(ds);
ds.Put<>(kdr);
ds.Put<>(index);
ds.Put<>(key1Size);
ds.Put<>(key2Size);
ds.Put<>(key3Size);
Expand Down Expand Up @@ -1644,6 +1646,8 @@ class DSA_PrivateToPublic : public Operation {
(modifier == rhs.modifier);
}
void Serialize(Datasource& ds) const {
g.Serialize(ds);
p.Serialize(ds);
priv.Serialize(ds);
}
};
Expand Down
40 changes: 24 additions & 16 deletions modules/openssl/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3967,32 +3967,40 @@ std::optional<component::Bignum> OpenSSL::OpDSA_PrivateToPublic(operation::DSA_P
std::optional<component::Bignum> ret = std::nullopt;
Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());

global_ds = &ds;
OpenSSL_bignum::Bignum priv(ds);
DSA* dsa = nullptr;
char* str;
const BIGNUM* pub = nullptr;
/* OpenSSL DSA_generate_key needs p/q/g; we only have p/g/priv, so compute pub = g^priv mod p manually */
BIGNUM *p_bn = nullptr, *g_bn = nullptr, *priv_bn = nullptr, *pub_bn = nullptr;
BN_CTX* ctx = nullptr;
char* str = nullptr;
std::string pub_str;

CF_CHECK_EQ(priv.Set(op.priv.ToString(ds)), true);
/* Parse decimal strings into BIGNUMs */
const std::string p_str = op.p.ToString(ds);
const std::string g_str = op.g.ToString(ds);
const std::string priv_str = op.priv.ToString(ds);

CF_CHECK_NE(dsa = DSA_new(), nullptr);
CF_CHECK_NE(DSA_set0_key(dsa, nullptr, priv.GetDestPtr()), 0);
priv.ReleaseOwnership();
CF_CHECK_NE(p_bn = BN_new(), nullptr);
CF_CHECK_NE(g_bn = BN_new(), nullptr);
CF_CHECK_NE(priv_bn = BN_new(), nullptr);
CF_CHECK_GT(BN_dec2bn(&p_bn, p_str.c_str()), 0);
CF_CHECK_GT(BN_dec2bn(&g_bn, g_str.c_str()), 0);
CF_CHECK_GT(BN_dec2bn(&priv_bn, priv_str.c_str()), 0);

CF_CHECK_NE(DSA_generate_key(dsa), 0);
CF_NORET(DSA_get0_key(dsa, &pub, nullptr));
CF_CHECK_NE(str = BN_bn2dec(pub), nullptr);
CF_CHECK_NE(ctx = BN_CTX_new(), nullptr);
CF_CHECK_NE(pub_bn = BN_new(), nullptr);
CF_CHECK_NE(BN_mod_exp(pub_bn, g_bn, priv_bn, p_bn, ctx), 0);

CF_CHECK_NE(str = BN_bn2dec(pub_bn), nullptr);
pub_str = str;
OPENSSL_free(str);

ret = pub_str;

end:

CF_NORET(DSA_free(dsa));

global_ds = nullptr;
if (ctx != nullptr) BN_CTX_free(ctx);
if (pub_bn != nullptr) BN_free(pub_bn);
if (priv_bn != nullptr) BN_free(priv_bn);
if (g_bn != nullptr) BN_free(g_bn);
if (p_bn != nullptr) BN_free(p_bn);

return ret;
}
Expand Down