Skip to content

Commit 34b0b7e

Browse files
committed
apply clang-format
1 parent f8286f9 commit 34b0b7e

16 files changed

Lines changed: 126 additions & 102 deletions

src/lib/crypto/dilithium.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,19 @@ rnp_dilithium_param_to_botan_dimension(dilithium_parameter_e mode)
4646

4747
Botan::Dilithium_PublicKey
4848
dilithium_pubkey_from_bytes(const std::vector<uint8_t> &key_encoded,
49-
dilithium_parameter_e param)
49+
dilithium_parameter_e param)
5050
{
5151
return Botan::Dilithium_PublicKey(key_encoded,
5252
rnp_dilithium_param_to_botan_dimension(param));
5353
}
5454

5555
Botan::Dilithium_PrivateKey
5656
dilithium_privkey_from_bytes(const uint8_t * key_data,
57-
size_t key_size,
58-
dilithium_parameter_e param)
57+
size_t key_size,
58+
dilithium_parameter_e param)
5959
{
6060
Botan::secure_vector<uint8_t> priv_sv(key_data, key_data + key_size);
61-
return Botan::Dilithium_PrivateKey(priv_sv,
62-
rnp_dilithium_param_to_botan_dimension(param));
61+
return Botan::Dilithium_PrivateKey(priv_sv, rnp_dilithium_param_to_botan_dimension(param));
6362
}
6463

6564
} // namespace
@@ -68,7 +67,8 @@ std::vector<uint8_t>
6867
pgp_dilithium_private_key_t::sign(rnp::RNG *rng, const uint8_t *msg, size_t msg_len) const
6968
{
7069
assert(is_initialized_);
71-
auto priv_key = dilithium_privkey_from_bytes(key_encoded_.data(), key_encoded_.size(), dilithium_param_);
70+
auto priv_key =
71+
dilithium_privkey_from_bytes(key_encoded_.data(), key_encoded_.size(), dilithium_param_);
7272

7373
auto signer = Botan::PK_Signer(priv_key, *rng->obj(), "");
7474
std::vector<uint8_t> signature = signer.sign_message(msg, msg_len, *rng->obj());
@@ -120,6 +120,7 @@ pgp_dilithium_private_key_t::is_valid(rnp::RNG *rng) const
120120
return false;
121121
}
122122

123-
auto key = dilithium_privkey_from_bytes(key_encoded_.data(), key_encoded_.size(), dilithium_param_);
123+
auto key =
124+
dilithium_privkey_from_bytes(key_encoded_.data(), key_encoded_.size(), dilithium_param_);
124125
return key.check_key(*(rng->obj()), false);
125126
}

src/lib/crypto/dilithium_exdsa_composite.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,13 @@ pgp_dilithium_exdsa_composite_private_key_t::operator=(
231231
pgp_dilithium_exdsa_composite_key_t::operator=(other);
232232
pk_alg_ = other.pk_alg_;
233233
if (other.is_initialized() && other.dilithium_key_) {
234-
dilithium_key_ = std::unique_ptr<pgp_dilithium_private_key_t>(
235-
new pgp_dilithium_private_key_t(other.dilithium_key_->get_encoded(),
236-
other.dilithium_key_->param()));
234+
dilithium_key_ =
235+
std::unique_ptr<pgp_dilithium_private_key_t>(new pgp_dilithium_private_key_t(
236+
other.dilithium_key_->get_encoded(), other.dilithium_key_->param()));
237237
}
238238
if (other.is_initialized() && other.exdsa_key_) {
239-
exdsa_key_ = std::unique_ptr<exdsa_private_key_t>(
240-
new exdsa_private_key_t(other.exdsa_key_->get_encoded(),
241-
other.exdsa_key_->get_curve()));
239+
exdsa_key_ = std::unique_ptr<exdsa_private_key_t>(new exdsa_private_key_t(
240+
other.exdsa_key_->get_encoded(), other.exdsa_key_->get_curve()));
242241
}
243242

244243
return *this;
@@ -289,9 +288,9 @@ pgp_dilithium_exdsa_composite_private_key_t::parse_component_keys(
289288
pgp_curve_t curve = pk_alg_to_curve_id(pk_alg_);
290289
size_t split_at = exdsa_curve_privkey_size(pk_alg_to_curve_id(pk_alg_));
291290

292-
dilithium_key_ = std::unique_ptr<pgp_dilithium_private_key_t>(
293-
new pgp_dilithium_private_key_t(key_encoded.data() + split_at,
294-
key_encoded.size() - split_at, dilithium_param));
291+
dilithium_key_ =
292+
std::unique_ptr<pgp_dilithium_private_key_t>(new pgp_dilithium_private_key_t(
293+
key_encoded.data() + split_at, key_encoded.size() - split_at, dilithium_param));
295294
exdsa_key_ = std::unique_ptr<exdsa_private_key_t>(
296295
new exdsa_private_key_t(key_encoded.data(), split_at, curve));
297296

src/lib/crypto/dilithium_ossl.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ load_dilithium_pubkey(const std::vector<uint8_t> &pub, dilithium_parameter_e par
5454
return nullptr;
5555
}
5656
rnp::ossl::ParamBld bld(OSSL_PARAM_BLD_new());
57-
if (!bld ||
58-
!OSSL_PARAM_BLD_push_octet_string(bld.get(), OSSL_PKEY_PARAM_PUB_KEY, pub.data(),
59-
pub.size())) {
57+
if (!bld || !OSSL_PARAM_BLD_push_octet_string(
58+
bld.get(), OSSL_PKEY_PARAM_PUB_KEY, pub.data(), pub.size())) {
6059
return nullptr;
6160
}
6261
rnp::ossl::Param params(OSSL_PARAM_BLD_to_param(bld.get()));
@@ -80,9 +79,8 @@ load_dilithium_privkey(const rnp::SecureBytes &seed, dilithium_parameter_e param
8079
return nullptr;
8180
}
8281
rnp::ossl::ParamBld bld(OSSL_PARAM_BLD_new());
83-
if (!bld ||
84-
!OSSL_PARAM_BLD_push_octet_string(bld.get(), OSSL_PKEY_PARAM_ML_DSA_SEED, seed.data(),
85-
seed.size())) {
82+
if (!bld || !OSSL_PARAM_BLD_push_octet_string(
83+
bld.get(), OSSL_PKEY_PARAM_ML_DSA_SEED, seed.data(), seed.size())) {
8684
return nullptr;
8785
}
8886
rnp::ossl::Param params(OSSL_PARAM_BLD_to_param(bld.get()));
@@ -124,18 +122,18 @@ dilithium_generate_keypair(rnp::RNG *rng, dilithium_parameter_e dilithium_param)
124122
}
125123

126124
uint8_t seed_buf[32];
127-
OSSL_PARAM sparams[] = {
128-
OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_ML_DSA_SEED, seed_buf,
129-
sizeof(seed_buf)),
130-
OSSL_PARAM_END};
125+
OSSL_PARAM sparams[] = {OSSL_PARAM_construct_octet_string(
126+
OSSL_PKEY_PARAM_ML_DSA_SEED, seed_buf, sizeof(seed_buf)),
127+
OSSL_PARAM_END};
131128
if (EVP_PKEY_get_params(pkey.get(), sparams) <= 0) {
132129
RNP_LOG("failed to get ML-DSA seed: %s", rnp::ossl::latest_err());
133130
throw rnp::rnp_exception(RNP_ERROR_GENERIC);
134131
}
135132
size_t seed_len = sparams[0].return_size;
136133

137-
auto result = std::make_pair(pgp_dilithium_public_key_t(pub, dilithium_param),
138-
pgp_dilithium_private_key_t(seed_buf, seed_len, dilithium_param));
134+
auto result =
135+
std::make_pair(pgp_dilithium_public_key_t(pub, dilithium_param),
136+
pgp_dilithium_private_key_t(seed_buf, seed_len, dilithium_param));
139137
rnp::secure_wipe(seed_buf, sizeof(seed_buf));
140138
return result;
141139
}

src/lib/crypto/ed25519_ed448_ossl.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
#include <cassert>
3434

3535
static rnp_result_t
36-
ed_generate_native(rnp::RNG * rng,
37-
std::vector<uint8_t> & privkey,
38-
std::vector<uint8_t> & pubkey,
39-
int nid,
40-
size_t keylen)
36+
ed_generate_native(rnp::RNG * rng,
37+
std::vector<uint8_t> &privkey,
38+
std::vector<uint8_t> &pubkey,
39+
int nid,
40+
size_t keylen)
4141
{
4242
rnp::ossl::evp::PKeyCtx ctx(EVP_PKEY_CTX_new_id(nid, NULL));
4343
if (!ctx || EVP_PKEY_keygen_init(ctx.get()) <= 0) {
@@ -73,8 +73,7 @@ ed_sign_native(std::vector<uint8_t> & sig_out,
7373
int nid,
7474
size_t siglen)
7575
{
76-
rnp::ossl::evp::PKey pkey(
77-
EVP_PKEY_new_raw_private_key(nid, NULL, key.data(), key.size()));
76+
rnp::ossl::evp::PKey pkey(EVP_PKEY_new_raw_private_key(nid, NULL, key.data(), key.size()));
7877
if (!pkey) {
7978
RNP_LOG("Failed to load private key: %lu", ERR_peek_last_error());
8079
return RNP_ERROR_GENERIC;
@@ -101,8 +100,7 @@ ed_verify_native(const std::vector<uint8_t> &sig,
101100
size_t hash_len,
102101
int nid)
103102
{
104-
rnp::ossl::evp::PKey pkey(
105-
EVP_PKEY_new_raw_public_key(nid, NULL, key.data(), key.size()));
103+
rnp::ossl::evp::PKey pkey(EVP_PKEY_new_raw_public_key(nid, NULL, key.data(), key.size()));
106104
if (!pkey) {
107105
RNP_LOG("Failed to load public key: %lu", ERR_peek_last_error());
108106
return RNP_ERROR_VERIFICATION_FAILED;

src/lib/crypto/exdsa_ecdhkem.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ecdh_kem_private_key_t::ecdh_kem_private_key_t(std::vector<uint8_t> key, pgp_cur
7777
}
7878

7979
static Botan::ECDH_PrivateKey
80-
ecdh_kem_privkey_from_bytes(rnp::RNG * rng,
80+
ecdh_kem_privkey_from_bytes(rnp::RNG * rng,
8181
const uint8_t *key_data,
8282
size_t key_size,
8383
pgp_curve_t curve)
@@ -90,9 +90,7 @@ ecdh_kem_privkey_from_bytes(rnp::RNG * rng,
9090
}
9191

9292
static Botan::ECDH_PublicKey
93-
ecdh_kem_pubkey_from_bytes(rnp::RNG * rng,
94-
const std::vector<uint8_t> &key,
95-
pgp_curve_t curve)
93+
ecdh_kem_pubkey_from_bytes(rnp::RNG *rng, const std::vector<uint8_t> &key, pgp_curve_t curve)
9694
{
9795
assert(curve >= PGP_CURVE_NIST_P_256 && curve <= PGP_CURVE_P256K1);
9896
auto ec_desc = pgp::ec::Curve::get(curve);
@@ -133,7 +131,8 @@ ecdh_kem_private_key_t::get_pubkey_encoded(rnp::RNG *rng) const
133131
{
134132
switch (curve_) {
135133
case PGP_CURVE_25519: {
136-
Botan::X25519_PrivateKey botan_key = x25519_privkey_from_bytes(key_.data(), key_.size());
134+
Botan::X25519_PrivateKey botan_key =
135+
x25519_privkey_from_bytes(key_.data(), key_.size());
137136
return botan_key.public_value();
138137
}
139138
#if defined(ENABLE_CRYPTO_REFRESH)
@@ -143,7 +142,8 @@ ecdh_kem_private_key_t::get_pubkey_encoded(rnp::RNG *rng) const
143142
}
144143
#endif
145144
default: {
146-
Botan::ECDH_PrivateKey botan_key = ecdh_kem_privkey_from_bytes(rng, key_.data(), key_.size(), curve_);
145+
Botan::ECDH_PrivateKey botan_key =
146+
ecdh_kem_privkey_from_bytes(rng, key_.data(), key_.size(), curve_);
147147
return botan_key.public_value();
148148
}
149149
}
@@ -196,8 +196,9 @@ ecdh_kem_private_key_t::decapsulate(rnp::RNG * rng,
196196
{
197197
switch (curve_) {
198198
case PGP_CURVE_25519: {
199-
Botan::X25519_PrivateKey priv_key = x25519_privkey_from_bytes(key_.data(), key_.size());
200-
Botan::PK_Key_Agreement key_agreement(priv_key, *(rng->obj()), "Raw");
199+
Botan::X25519_PrivateKey priv_key =
200+
x25519_privkey_from_bytes(key_.data(), key_.size());
201+
Botan::PK_Key_Agreement key_agreement(priv_key, *(rng->obj()), "Raw");
201202
plaintext = Botan::unlock(key_agreement.derive_key(0, ciphertext).bits_of());
202203
break;
203204
}
@@ -210,7 +211,8 @@ ecdh_kem_private_key_t::decapsulate(rnp::RNG * rng,
210211
}
211212
#endif
212213
default: {
213-
Botan::ECDH_PrivateKey priv_key = ecdh_kem_privkey_from_bytes(rng, key_.data(), key_.size(), curve_);
214+
Botan::ECDH_PrivateKey priv_key =
215+
ecdh_kem_privkey_from_bytes(rng, key_.data(), key_.size(), curve_);
214216
Botan::PK_Key_Agreement key_agreement(priv_key, *(rng->obj()), "Raw");
215217
plaintext = Botan::unlock(key_agreement.derive_key(0, ciphertext).bits_of());
216218
break;
@@ -309,8 +311,9 @@ exdsa_private_key_t::sign(rnp::RNG * rng,
309311
return ed448_sign_native(rng, sig_out, key_.unlock(), hash, hash_len);
310312
}
311313
default: {
312-
Botan::ECDSA_PrivateKey priv_key = exdsa_privkey_from_bytes(rng, key_.data(), key_.size(), curve_);
313-
auto signer =
314+
Botan::ECDSA_PrivateKey priv_key =
315+
exdsa_privkey_from_bytes(rng, key_.data(), key_.size(), curve_);
316+
auto signer =
314317
Botan::PK_Signer(priv_key, *(rng->obj()), pgp::ecdsa::padding_str_for(hash_alg));
315318
sig_out = signer.sign_message(hash, hash_len, *(rng->obj()));
316319
return RNP_SUCCESS;

src/lib/crypto/exdsa_ecdhkem_ossl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ exdsa_public_key_t::verify(const std::vector<uint8_t> &sig,
573573
}
574574
size_t field_size = curve_desc->bytes();
575575
if (sig.size() != 2 * field_size) {
576-
RNP_LOG("Invalid P1363 signature size: %zu (expected %zu)", sig.size(),
577-
2 * field_size);
576+
RNP_LOG(
577+
"Invalid P1363 signature size: %zu (expected %zu)", sig.size(), 2 * field_size);
578578
return RNP_ERROR_VERIFICATION_FAILED;
579579
}
580580
/* decode P1363 and encode as DER for EVP_PKEY_verify */

src/lib/crypto/hkdf_ossl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ Hkdf_OpenSSL::create(pgp_hash_alg_t alg)
4949

5050
void
5151
Hkdf_OpenSSL::extract_expand(const uint8_t *salt,
52-
size_t salt_len,
53-
const uint8_t *ikm,
54-
size_t ikm_len,
55-
const uint8_t *info,
56-
size_t info_len,
57-
uint8_t * output_buf,
58-
size_t output_length)
52+
size_t salt_len,
53+
const uint8_t *ikm,
54+
size_t ikm_len,
55+
const uint8_t *info,
56+
size_t info_len,
57+
uint8_t * output_buf,
58+
size_t output_length)
5959
{
6060
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
6161
if (!kdf) {

src/lib/crypto/kyber.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ kyber_pubkey_from_bytes(const std::vector<uint8_t> &key_encoded, kyber_parameter
5757
}
5858

5959
Botan::Kyber_PrivateKey
60-
kyber_privkey_from_bytes(const uint8_t *key_data, size_t key_size, kyber_parameter_e kyber_mode)
60+
kyber_privkey_from_bytes(const uint8_t * key_data,
61+
size_t key_size,
62+
kyber_parameter_e kyber_mode)
6163
{
6264
Botan::secure_vector<uint8_t> key_sv(key_data, key_data + key_size);
6365
return Botan::Kyber_PrivateKey(key_sv, rnp_kyber_param_to_botan_kyber_mode(kyber_mode));
@@ -107,7 +109,8 @@ pgp_kyber_private_key_t::decapsulate(rnp::RNG * rng,
107109
size_t ciphertext_len)
108110
{
109111
assert(is_initialized_);
110-
auto decoded_kyber_priv = kyber_privkey_from_bytes(key_encoded_.data(), key_encoded_.size(), kyber_mode_);
112+
auto decoded_kyber_priv =
113+
kyber_privkey_from_bytes(key_encoded_.data(), key_encoded_.size(), kyber_mode_);
111114
Botan::PK_KEM_Decryptor kem_dec(decoded_kyber_priv, *rng->obj(), "Raw", "base");
112115
Botan::secure_vector<uint8_t> dec_shared_key =
113116
kem_dec.decrypt(ciphertext, ciphertext_len, kyber_key_share_size());

src/lib/crypto/kyber.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class pgp_kyber_private_key_t {
7070
private:
7171
rnp::SecureBytes key_encoded_;
7272
kyber_parameter_e kyber_mode_;
73-
bool is_initialized_ = false;
73+
bool is_initialized_ = false;
7474
};
7575

7676
class pgp_kyber_public_key_t {

src/lib/crypto/kyber_ecdh_composite.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,16 @@ pgp_kyber_ecdh_composite_private_key_t::decrypt(
390390
return RNP_ERROR_DECRYPT_FAILED;
391391
}
392392
EVP_CIPHER_CTX_set_flags(wctx.get(), EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
393-
if (EVP_DecryptInit_ex(wctx.get(), EVP_aes_256_wrap(), NULL, kek_vec.data(), NULL) <= 0) {
393+
if (EVP_DecryptInit_ex(wctx.get(), EVP_aes_256_wrap(), NULL, kek_vec.data(), NULL) <=
394+
0) {
394395
return RNP_ERROR_DECRYPT_FAILED;
395396
}
396-
size_t unwrapped_size = enc->wrapped_sesskey.size() - 8;
397+
size_t unwrapped_size = enc->wrapped_sesskey.size() - 8;
397398
std::vector<uint8_t> tmp_out(unwrapped_size);
398-
int unwrap_len = 0, unwrap_final = 0;
399-
if (EVP_DecryptUpdate(wctx.get(), tmp_out.data(), &unwrap_len,
399+
int unwrap_len = 0, unwrap_final = 0;
400+
if (EVP_DecryptUpdate(wctx.get(),
401+
tmp_out.data(),
402+
&unwrap_len,
400403
enc->wrapped_sesskey.data(),
401404
(int) enc->wrapped_sesskey.size()) <= 0 ||
402405
EVP_DecryptFinal_ex(wctx.get(), tmp_out.data() + unwrap_len, &unwrap_final) <= 0) {
@@ -547,15 +550,19 @@ pgp_kyber_ecdh_composite_public_key_t::encrypt(rnp::RNG * rng,
547550
return RNP_ERROR_ENCRYPT_FAILED;
548551
}
549552
EVP_CIPHER_CTX_set_flags(wctx.get(), EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
550-
if (EVP_EncryptInit_ex(wctx.get(), EVP_aes_256_wrap(), NULL, kek_vec.data(), NULL) <= 0) {
553+
if (EVP_EncryptInit_ex(wctx.get(), EVP_aes_256_wrap(), NULL, kek_vec.data(), NULL) <=
554+
0) {
551555
return RNP_ERROR_ENCRYPT_FAILED;
552556
}
553557
out->wrapped_sesskey.resize(session_key_len + 8);
554558
int wrap_len = 0, wrap_final = 0;
555-
if (EVP_EncryptUpdate(wctx.get(), out->wrapped_sesskey.data(), &wrap_len, session_key,
559+
if (EVP_EncryptUpdate(wctx.get(),
560+
out->wrapped_sesskey.data(),
561+
&wrap_len,
562+
session_key,
556563
(int) session_key_len) <= 0 ||
557-
EVP_EncryptFinal_ex(wctx.get(), out->wrapped_sesskey.data() + wrap_len,
558-
&wrap_final) <= 0) {
564+
EVP_EncryptFinal_ex(
565+
wctx.get(), out->wrapped_sesskey.data() + wrap_len, &wrap_final) <= 0) {
559566
RNP_LOG("Keywrap failed");
560567
return RNP_ERROR_ENCRYPT_FAILED;
561568
}

0 commit comments

Comments
 (0)