aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFCrypto_openssl.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-02 23:14:10 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-04 14:10:40 +0200
commit12f1eb15ca3fed6310402847559a7c99d3c77847 (patch)
tree8935675b623c6f3b4914b8b44f7fa5f2816a9241 /libqpdf/QPDFCrypto_openssl.cc
parentf20fa61eb4c323eb1642c69c236b3d9a1f8b2cdb (diff)
downloadqpdf-12f1eb15ca3fed6310402847559a7c99d3c77847.tar.zst
Programmatically apply new formatting to code
Run this: for i in **/*.cc **/*.c **/*.h **/*.hh; do clang-format < $i >| $i.new && mv $i.new $i done
Diffstat (limited to 'libqpdf/QPDFCrypto_openssl.cc')
-rw-r--r--libqpdf/QPDFCrypto_openssl.cc68
1 files changed, 29 insertions, 39 deletions
diff --git a/libqpdf/QPDFCrypto_openssl.cc b/libqpdf/QPDFCrypto_openssl.cc
index 427ce5bb..a281bf79 100644
--- a/libqpdf/QPDFCrypto_openssl.cc
+++ b/libqpdf/QPDFCrypto_openssl.cc
@@ -28,8 +28,7 @@ bad_bits(int bits)
static void
check_openssl(int status)
{
- if (status != 1)
- {
+ if (status != 1) {
// OpenSSL creates a "queue" of errors; copy the first (innermost)
// error to the exception message.
char buf[256] = "";
@@ -50,21 +49,18 @@ QPDFCrypto_openssl::QPDFCrypto_openssl() :
{
#ifndef QPDF_OPENSSL_1
libctx = OSSL_LIB_CTX_new();
- if (libctx == nullptr)
- {
+ if (libctx == nullptr) {
throw std::runtime_error("unable to create openssl library context");
return;
}
legacy = OSSL_PROVIDER_load(libctx, "legacy");
- if (legacy == nullptr)
- {
+ if (legacy == nullptr) {
OSSL_LIB_CTX_free(libctx);
throw std::runtime_error("unable to load openssl legacy provider");
return;
}
rc4 = EVP_CIPHER_fetch(libctx, "RC4", nullptr);
- if (rc4 == nullptr)
- {
+ if (rc4 == nullptr) {
OSSL_PROVIDER_unload(legacy);
OSSL_LIB_CTX_free(libctx);
throw std::runtime_error("unable to load openssl rc4 algorithm");
@@ -106,18 +102,17 @@ void
QPDFCrypto_openssl::SHA2_init(int bits)
{
const EVP_MD* md = EVP_sha512();
- switch (bits)
- {
- case 256:
+ switch (bits) {
+ case 256:
md = EVP_sha256();
break;
- case 384:
+ case 384:
md = EVP_sha384();
break;
- case 512:
+ case 512:
md = EVP_sha512();
break;
- default:
+ default:
bad_bits(bits);
return;
}
@@ -146,8 +141,7 @@ QPDFCrypto_openssl::MD5_finalize()
#else
auto md = EVP_MD_CTX_get0_md(md_ctx);
#endif
- if (md)
- {
+ if (md) {
check_openssl(EVP_DigestFinal(md_ctx, md_out + 0, nullptr));
}
}
@@ -160,9 +154,8 @@ QPDFCrypto_openssl::SHA2_finalize()
#else
auto md = EVP_MD_CTX_get0_md(md_ctx);
#endif
- if (md)
- {
- check_openssl(EVP_DigestFinal(md_ctx, md_out + 0, nullptr));
+ if (md) {
+ check_openssl(EVP_DigestFinal(md_ctx, md_out + 0, nullptr));
}
}
@@ -182,10 +175,9 @@ void
QPDFCrypto_openssl::RC4_init(unsigned char const* key_data, int key_len)
{
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
- if (key_len == -1)
- {
- key_len = QIntC::to_int(
- strlen(reinterpret_cast<const char*>(key_data)));
+ if (key_len == -1) {
+ key_len =
+ QIntC::to_int(strlen(reinterpret_cast<const char*>(key_data)));
}
check_openssl(
EVP_EncryptInit_ex(cipher_ctx, rc4, nullptr, nullptr, nullptr));
@@ -196,27 +188,28 @@ QPDFCrypto_openssl::RC4_init(unsigned char const* key_data, int key_len)
void
QPDFCrypto_openssl::rijndael_init(
- bool encrypt, unsigned char const* key_data, size_t key_len,
- bool cbc_mode, unsigned char* cbc_block)
+ bool encrypt,
+ unsigned char const* key_data,
+ size_t key_len,
+ bool cbc_mode,
+ unsigned char* cbc_block)
{
const EVP_CIPHER* cipher = nullptr;
- switch (key_len)
- {
- case 32:
+ switch (key_len) {
+ case 32:
cipher = cbc_mode ? EVP_aes_256_cbc() : EVP_aes_256_ecb();
break;
- case 24:
+ case 24:
cipher = cbc_mode ? EVP_aes_192_cbc() : EVP_aes_192_ecb();
break;
- default:
+ default:
cipher = cbc_mode ? EVP_aes_128_cbc() : EVP_aes_128_ecb();
break;
}
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
- check_openssl(
- EVP_CipherInit_ex(cipher_ctx, cipher, nullptr,
- key_data, cbc_block, encrypt));
+ check_openssl(EVP_CipherInit_ex(
+ cipher_ctx, cipher, nullptr, key_data, cbc_block, encrypt));
check_openssl(EVP_CIPHER_CTX_set_padding(cipher_ctx, 0));
}
@@ -224,8 +217,7 @@ void
QPDFCrypto_openssl::RC4_process(
unsigned char* in_data, size_t len, unsigned char* out_data)
{
- if (nullptr == out_data)
- {
+ if (nullptr == out_data) {
out_data = in_data;
}
int out_len = static_cast<int>(len);
@@ -244,8 +236,7 @@ QPDFCrypto_openssl::rijndael_process(
void
QPDFCrypto_openssl::RC4_finalize()
{
- if (EVP_CIPHER_CTX_cipher(cipher_ctx))
- {
+ if (EVP_CIPHER_CTX_cipher(cipher_ctx)) {
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
}
}
@@ -253,8 +244,7 @@ QPDFCrypto_openssl::RC4_finalize()
void
QPDFCrypto_openssl::rijndael_finalize()
{
- if (EVP_CIPHER_CTX_cipher(cipher_ctx))
- {
+ if (EVP_CIPHER_CTX_cipher(cipher_ctx)) {
check_openssl(EVP_CIPHER_CTX_reset(cipher_ctx));
}
}