Skip to content

Commit

Permalink
Remove redundant pgp:: namespace reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Dec 25, 2024
1 parent 7187325 commit 990ca6c
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 88 deletions.
14 changes: 7 additions & 7 deletions src/lib/crypto/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ namespace dsa {

class Signature {
public:
pgp::mpi r;
pgp::mpi s;
mpi r;
mpi s;
};

class Key {
public:
pgp::mpi p{};
pgp::mpi q{};
pgp::mpi g{};
pgp::mpi y{};
mpi p{};
mpi q{};
mpi g{};
mpi y{};
/* secret mpi */
pgp::mpi x{};
mpi x{};

void
clear_secret()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/dsa_ossl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Key::verify(const Signature &sig, const rnp::secure_bytes &hash) const
RNP_LOG("Failed to initialize verify: %lu", ERR_peek_last_error());
return RNP_ERROR_GENERIC;
}
pgp::mpi sigbuf;
mpi sigbuf;
if (!encode_sig(sigbuf.mpi, &sigbuf.len, sig)) {
return RNP_ERROR_GENERIC;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/crypto/ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ class Curve {

class Signature {
public:
pgp::mpi r;
pgp::mpi s;
mpi r;
mpi s;
};

class Key {
public:
pgp_curve_t curve;
pgp::mpi p;
mpi p;
/* secret mpi */
pgp::mpi x;
mpi x;
/* ecdh params */
pgp_hash_alg_t kdf_hash_alg; /* Hash used by kdf */
pgp_symm_alg_t key_wrap_alg; /* Symmetric algorithm used to wrap KEK*/
Expand Down
14 changes: 7 additions & 7 deletions src/lib/crypto/ec_ossl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ generate_pkey(const pgp_pubkey_alg_t alg_id, const pgp_curve_t curve)
}

static bool
write_raw_seckey(const rnp::ossl::evp::PKey &pkey, pgp::ec::Key &key)
write_raw_seckey(const rnp::ossl::evp::PKey &pkey, ec::Key &key)
{
/* EdDSA and X25519 keys are saved in a different way */
static_assert(sizeof(key.x.mpi) > 32, "mpi is too small.");
Expand All @@ -123,7 +123,7 @@ write_raw_seckey(const rnp::ossl::evp::PKey &pkey, pgp::ec::Key &key)
}

static bool
write_seckey(rnp::ossl::evp::PKey &pkey, pgp::mpi &key)
write_seckey(rnp::ossl::evp::PKey &pkey, mpi &key)
{
#if defined(CRYPTO_BACKEND_OPENSSL3)
rnp::bn x;
Expand Down Expand Up @@ -173,7 +173,7 @@ Key::generate(rnp::RNG &rng, const pgp_pubkey_alg_t alg_id, const pgp_curve_t cu
}

static rnp::ossl::evp::PKey
load_raw_key(const pgp::mpi &keyp, const pgp::mpi *keyx, int nid)
load_raw_key(const mpi &keyp, const mpi *keyx, int nid)
{
if (!keyx) {
/* as per RFC, EdDSA & 25519 keys must use 0x40 byte for encoding */
Expand Down Expand Up @@ -219,7 +219,7 @@ load_raw_key(const pgp::mpi &keyp, const pgp::mpi *keyx, int nid)

#if defined(CRYPTO_BACKEND_OPENSSL3)
static rnp::ossl::Param
build_params(const pgp::mpi &p, const pgp::mpi *x, const char *curve)
build_params(const mpi &p, const mpi *x, const char *curve)
{
rnp::ossl::ParamBld bld(OSSL_PARAM_BLD_new());
if (!bld) {
Expand All @@ -235,7 +235,7 @@ build_params(const pgp::mpi &p, const pgp::mpi *x, const char *curve)
}

static rnp::ossl::evp::PKey
load_key_openssl3(const pgp::mpi &keyp, const pgp::mpi *keyx, const Curve &curv_desc)
load_key_openssl3(const mpi &keyp, const mpi *keyx, const Curve &curv_desc)
{
auto params = build_params(keyp, keyx, curv_desc.openssl_name);
if (!params) {
Expand Down Expand Up @@ -266,7 +266,7 @@ load_key_openssl3(const pgp::mpi &keyp, const pgp::mpi *keyx, const Curve &curv_
#endif

rnp::ossl::evp::PKey
load_key(const pgp::mpi &keyp, const pgp::mpi *keyx, pgp_curve_t curve)
load_key(const mpi &keyp, const mpi *keyx, pgp_curve_t curve)
{
auto curv_desc = Curve::get(curve);
if (!curv_desc) {
Expand Down Expand Up @@ -394,7 +394,7 @@ validate_key(const Key &key, bool secret)
}

bool
write_pubkey(const rnp::ossl::evp::PKey &pkey, pgp::mpi &mpi, pgp_curve_t curve)
write_pubkey(const rnp::ossl::evp::PKey &pkey, mpi &mpi, pgp_curve_t curve)
{
if (is_raw_key(curve)) {
/* EdDSA and X25519 keys are saved in a different way */
Expand Down
6 changes: 3 additions & 3 deletions src/lib/crypto/ec_ossl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
namespace pgp {
namespace ec {

rnp::ossl::evp::PKey load_key(const pgp::mpi &keyp, const pgp::mpi *keyx, pgp_curve_t curve);
rnp::ossl::evp::PKey load_key(const mpi &keyp, const mpi *keyx, pgp_curve_t curve);

rnp_result_t validate_key(const pgp::ec::Key &key, bool secret);
rnp_result_t validate_key(const ec::Key &key, bool secret);

rnp::ossl::evp::PKey generate_pkey(const pgp_pubkey_alg_t alg_id, const pgp_curve_t curve);

bool write_pubkey(const rnp::ossl::evp::PKey &key, pgp::mpi &mpi, pgp_curve_t curve);
bool write_pubkey(const rnp::ossl::evp::PKey &key, mpi &mpi, pgp_curve_t curve);

} // namespace ec
} // namespace pgp
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/ecdh_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static const struct ecdh_params_t {

// returns size of data written to other_info
std::vector<uint8_t>
kdf_other_info_serialize(const pgp::ec::Curve & curve,
kdf_other_info_serialize(const ec::Curve & curve,
const std::vector<uint8_t> &fp,
const pgp_hash_alg_t kdf_hash,
const pgp_symm_alg_t wrap_alg)
Expand Down Expand Up @@ -117,7 +117,7 @@ unpad_pkcs7(rnp::secure_bytes &buf)
}

bool
set_params(pgp::ec::Key &key, pgp_curve_t curve_id)
set_params(ec::Key &key, pgp_curve_t curve_id)
{
for (size_t i = 0; i < ARRAY_SIZE(ecdh_params); i++) {
if (ecdh_params[i].curve == curve_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/ecdh_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

namespace pgp {
namespace ecdh {
std::vector<uint8_t> kdf_other_info_serialize(const pgp::ec::Curve & curve,
std::vector<uint8_t> kdf_other_info_serialize(const ec::Curve & curve,
const std::vector<uint8_t> &fp,
const pgp_hash_alg_t kdf_hash,
const pgp_symm_alg_t wrap_alg);
Expand Down
26 changes: 13 additions & 13 deletions src/lib/crypto/ecdsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ namespace pgp {
namespace ecdsa {

static bool
load_public_key(rnp::botan::Pubkey &pubkey, const pgp::ec::Key &keydata)
load_public_key(rnp::botan::Pubkey &pubkey, const ec::Key &keydata)
{
auto curve = pgp::ec::Curve::get(keydata.curve);
auto curve = ec::Curve::get(keydata.curve);
if (!curve) {
RNP_LOG("unknown curve");
return false;
Expand All @@ -62,9 +62,9 @@ load_public_key(rnp::botan::Pubkey &pubkey, const pgp::ec::Key &keydata)
}

static bool
load_secret_key(rnp::botan::Privkey &seckey, const pgp::ec::Key &keydata)
load_secret_key(rnp::botan::Privkey &seckey, const ec::Key &keydata)
{
auto curve = pgp::ec::Curve::get(keydata.curve);
auto curve = ec::Curve::get(keydata.curve);
if (!curve) {
return false;
}
Expand All @@ -82,7 +82,7 @@ load_secret_key(rnp::botan::Privkey &seckey, const pgp::ec::Key &keydata)
}

rnp_result_t
validate_key(rnp::RNG &rng, const pgp::ec::Key &key, bool secret)
validate_key(rnp::RNG &rng, const ec::Key &key, bool secret)
{
rnp::botan::Pubkey bpkey;
if (!load_public_key(bpkey, key) || botan_pubkey_check_key(bpkey.get(), rng.handle(), 0)) {
Expand Down Expand Up @@ -131,12 +131,12 @@ padding_str_for(pgp_hash_alg_t hash_alg)

rnp_result_t
sign(rnp::RNG & rng,
pgp::ec::Signature & sig,
ec::Signature & sig,
pgp_hash_alg_t hash_alg,
const rnp::secure_bytes &hash,
const pgp::ec::Key & key)
const ec::Key & key)
{
auto curve = pgp::ec::Curve::get(key.curve);
auto curve = ec::Curve::get(key.curve);
if (!curve) {
return RNP_ERROR_BAD_PARAMETERS;
}
Expand Down Expand Up @@ -172,12 +172,12 @@ sign(rnp::RNG & rng,
}

rnp_result_t
verify(const pgp::ec::Signature &sig,
pgp_hash_alg_t hash_alg,
const rnp::secure_bytes & hash,
const pgp::ec::Key & key)
verify(const ec::Signature & sig,
pgp_hash_alg_t hash_alg,
const rnp::secure_bytes &hash,
const ec::Key & key)
{
auto curve = pgp::ec::Curve::get(key.curve);
auto curve = ec::Curve::get(key.curve);
if (!curve) {
RNP_LOG("unknown curve");
return RNP_ERROR_BAD_PARAMETERS;
Expand Down
15 changes: 6 additions & 9 deletions src/lib/crypto/eddsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace pgp {
namespace eddsa {

static bool
load_public_key(rnp::botan::Pubkey &pubkey, const pgp::ec::Key &keydata)
load_public_key(rnp::botan::Pubkey &pubkey, const ec::Key &keydata)
{
if (keydata.curve != PGP_CURVE_ED25519) {
return false;
Expand All @@ -53,7 +53,7 @@ load_public_key(rnp::botan::Pubkey &pubkey, const pgp::ec::Key &keydata)
}

static bool
load_secret_key(rnp::botan::Privkey &seckey, const pgp::ec::Key &keydata)
load_secret_key(rnp::botan::Privkey &seckey, const ec::Key &keydata)
{
if (keydata.curve != PGP_CURVE_ED25519) {
return false;
Expand All @@ -72,7 +72,7 @@ load_secret_key(rnp::botan::Privkey &seckey, const pgp::ec::Key &keydata)
}

rnp_result_t
validate_key(rnp::RNG &rng, const pgp::ec::Key &key, bool secret)
validate_key(rnp::RNG &rng, const ec::Key &key, bool secret)
{
rnp::botan::Pubkey bpkey;
if (!load_public_key(bpkey, key) || botan_pubkey_check_key(bpkey.get(), rng.handle(), 0)) {
Expand All @@ -92,7 +92,7 @@ validate_key(rnp::RNG &rng, const pgp::ec::Key &key, bool secret)
}

rnp_result_t
generate(rnp::RNG &rng, pgp::ec::Key &key)
generate(rnp::RNG &rng, ec::Key &key)
{
rnp::botan::Privkey eddsa;
if (botan_privkey_create(&eddsa.get(), "Ed25519", NULL, rng.handle())) {
Expand All @@ -115,7 +115,7 @@ generate(rnp::RNG &rng, pgp::ec::Key &key)
}

rnp_result_t
verify(const pgp::ec::Signature &sig, const rnp::secure_bytes &hash, const pgp::ec::Key &key)
verify(const ec::Signature &sig, const rnp::secure_bytes &hash, const ec::Key &key)
{
// Unexpected size for Ed25519 signature
if ((sig.r.bytes() > 32) || (sig.s.bytes() > 32)) {
Expand Down Expand Up @@ -144,10 +144,7 @@ verify(const pgp::ec::Signature &sig, const rnp::secure_bytes &hash, const pgp::
}

rnp_result_t
sign(rnp::RNG & rng,
pgp::ec::Signature & sig,
const rnp::secure_bytes &hash,
const pgp::ec::Key & key)
sign(rnp::RNG &rng, ec::Signature &sig, const rnp::secure_bytes &hash, const ec::Key &key)
{
rnp::botan::Privkey eddsa;
if (!load_secret_key(eddsa, key)) {
Expand Down
15 changes: 6 additions & 9 deletions src/lib/crypto/eddsa_ossl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace pgp {
namespace eddsa {

rnp_result_t
validate_key(rnp::RNG &rng, const pgp::ec::Key &key, bool secret)
validate_key(rnp::RNG &rng, const ec::Key &key, bool secret)
{
/* Not implemented in the OpenSSL, so just do basic size checks. */
if ((key.p.bytes() != 33) || (key.p.mpi[0] != 0x40)) {
Expand All @@ -53,7 +53,7 @@ validate_key(rnp::RNG &rng, const pgp::ec::Key &key, bool secret)
}

rnp_result_t
generate(rnp::RNG &rng, pgp::ec::Key &key)
generate(rnp::RNG &rng, ec::Key &key)
{
rnp_result_t ret = key.generate(rng, PGP_PKA_EDDSA, PGP_CURVE_ED25519);
if (!ret) {
Expand All @@ -63,7 +63,7 @@ generate(rnp::RNG &rng, pgp::ec::Key &key)
}

rnp_result_t
verify(const pgp::ec::Signature &sig, const rnp::secure_bytes &hash, const pgp::ec::Key &key)
verify(const ec::Signature &sig, const rnp::secure_bytes &hash, const ec::Key &key)
{
if ((sig.r.bytes() > 32) || (sig.s.bytes() > 32)) {
RNP_LOG("Invalid EdDSA signature.");
Expand All @@ -74,7 +74,7 @@ verify(const pgp::ec::Signature &sig, const rnp::secure_bytes &hash, const pgp::
return RNP_ERROR_BAD_PARAMETERS;
}

auto evpkey = pgp::ec::load_key(key.p, NULL, PGP_CURVE_ED25519);
auto evpkey = ec::load_key(key.p, NULL, PGP_CURVE_ED25519);
if (!evpkey) {
RNP_LOG("Failed to load key");
return RNP_ERROR_BAD_PARAMETERS;
Expand Down Expand Up @@ -103,16 +103,13 @@ verify(const pgp::ec::Signature &sig, const rnp::secure_bytes &hash, const pgp::
}

rnp_result_t
sign(rnp::RNG & rng,
pgp::ec::Signature & sig,
const rnp::secure_bytes &hash,
const pgp::ec::Key & key)
sign(rnp::RNG &rng, ec::Signature &sig, const rnp::secure_bytes &hash, const ec::Key &key)
{
if (!key.x.bytes()) {
RNP_LOG("private key not set");
return RNP_ERROR_BAD_PARAMETERS;
}
auto evpkey = pgp::ec::load_key(key.p, &key.x, PGP_CURVE_ED25519);
auto evpkey = ec::load_key(key.p, &key.x, PGP_CURVE_ED25519);
if (!evpkey) {
RNP_LOG("Failed to load private key: %lu", ERR_peek_last_error());
return RNP_ERROR_BAD_PARAMETERS;
Expand Down
16 changes: 8 additions & 8 deletions src/lib/crypto/elgamal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ class Signature {
public:
/* This is kept only for packet reading. Implementation MUST
* not create elgamal signatures */
pgp::mpi r;
pgp::mpi s;
mpi r;
mpi s;
};

class Encrypted {
public:
pgp::mpi g;
pgp::mpi m;
mpi g;
mpi m;
};

class Key {
public:
pgp::mpi p;
pgp::mpi g;
pgp::mpi y;
mpi p;
mpi g;
mpi y;
/* secret mpi */
pgp::mpi x;
mpi x;

void
clear_secret()
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/elgamal_ossl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ Key::decrypt_pkcs1(rnp::RNG &rng, rnp::secure_bytes &out, const Encrypted &in) c
return RNP_ERROR_GENERIC;
/* LCOV_EXCL_END */
}
pgp::mpi mm = {};
bool res = m.mpi(mm);
mpi mm = {};
bool res = m.mpi(mm);
assert(res);
if (!res) {
return RNP_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
Expand Down
Loading

0 comments on commit 990ca6c

Please sign in to comment.