Skip to content

Commit d39fd75

Browse files
authored
Merge pull request #112 from Tmonster/bump_submodule_and_apply_patch
Bump submodule and apply patch
2 parents 577a55d + 15cadd9 commit d39fd75

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

duckdb

Submodule duckdb updated 51 files

extension/httpfs/crypto.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#define CPPHTTPLIB_OPENSSL_SUPPORT
99

10+
#include "include/crypto.hpp"
11+
12+
#include "re2/re2.h"
13+
1014
#include <openssl/err.h>
1115
#include <openssl/evp.h>
1216
#include <openssl/ssl.h>
@@ -19,7 +23,7 @@
1923

2024
namespace duckdb {
2125

22-
AESStateSSL::AESStateSSL(const std::string *key) : context(EVP_CIPHER_CTX_new()) {
26+
AESStateSSL::AESStateSSL(EncryptionTypes::CipherType cipher_p, const std::string *key) : EncryptionState(cipher_p), context(EVP_CIPHER_CTX_new()), cipher(cipher_p) {
2327
if (!(context)) {
2428
throw InternalException("AES GCM failed with initializing context");
2529
}
@@ -33,7 +37,7 @@ AESStateSSL::~AESStateSSL() {
3337
const EVP_CIPHER *AESStateSSL::GetCipher(idx_t key_len) {
3438

3539
switch (cipher) {
36-
case GCM:
40+
case EncryptionTypes::GCM: {
3741
switch (key_len) {
3842
case 16:
3943
return EVP_aes_128_gcm();
@@ -44,7 +48,8 @@ const EVP_CIPHER *AESStateSSL::GetCipher(idx_t key_len) {
4448
default:
4549
throw InternalException("Invalid AES key length");
4650
}
47-
case CTR:
51+
}
52+
case EncryptionTypes::CTR: {
4853
switch (key_len) {
4954
case 16:
5055
return EVP_aes_128_ctr();
@@ -55,7 +60,19 @@ const EVP_CIPHER *AESStateSSL::GetCipher(idx_t key_len) {
5560
default:
5661
throw InternalException("Invalid AES key length");
5762
}
58-
63+
}
64+
case EncryptionTypes::CBC: {
65+
switch (key_len) {
66+
case 16:
67+
return EVP_aes_128_cbc();
68+
case 24:
69+
return EVP_aes_192_cbc();
70+
case 32:
71+
return EVP_aes_256_cbc();
72+
default:
73+
throw InternalException("Invalid AES key length");
74+
}
75+
}
5976
default:
6077
throw duckdb::InternalException("Invalid Encryption/Decryption Cipher: %d", static_cast<int>(cipher));
6178
}
@@ -67,7 +84,7 @@ void AESStateSSL::GenerateRandomData(data_ptr_t data, idx_t len) {
6784
}
6885

6986
void AESStateSSL::InitializeEncryption(const_data_ptr_t iv, idx_t iv_len, const_data_ptr_t key, idx_t key_len, const_data_ptr_t aad, idx_t aad_len) {
70-
mode = ENCRYPT;
87+
mode = EncryptionTypes::ENCRYPT;
7188

7289
if (1 != EVP_EncryptInit_ex(context, GetCipher(key_len), NULL, key, iv)) {
7390
throw InternalException("EncryptInit failed");
@@ -82,7 +99,7 @@ void AESStateSSL::InitializeEncryption(const_data_ptr_t iv, idx_t iv_len, const_
8299
}
83100

84101
void AESStateSSL::InitializeDecryption(const_data_ptr_t iv, idx_t iv_len, const_data_ptr_t key, idx_t key_len, const_data_ptr_t aad, idx_t aad_len) {
85-
mode = DECRYPT;
102+
mode = EncryptionTypes::DECRYPT;
86103

87104
if (1 != EVP_DecryptInit_ex(context, GetCipher(key_len), NULL, key, iv)) {
88105
throw InternalException("DecryptInit failed");
@@ -99,14 +116,14 @@ void AESStateSSL::InitializeDecryption(const_data_ptr_t iv, idx_t iv_len, const_
99116
size_t AESStateSSL::Process(const_data_ptr_t in, idx_t in_len, data_ptr_t out, idx_t out_len) {
100117

101118
switch (mode) {
102-
case ENCRYPT:
119+
case EncryptionTypes::ENCRYPT:
103120
if (1 != EVP_EncryptUpdate(context, data_ptr_cast(out), reinterpret_cast<int *>(&out_len),
104121
const_data_ptr_cast(in), (int)in_len)) {
105122
throw InternalException("EncryptUpdate failed");
106123
}
107124
break;
108125

109-
case DECRYPT:
126+
case EncryptionTypes::DECRYPT:
110127
if (1 != EVP_DecryptUpdate(context, data_ptr_cast(out), reinterpret_cast<int *>(&out_len),
111128
const_data_ptr_cast(in), (int)in_len)) {
112129

@@ -126,7 +143,7 @@ size_t AESStateSSL::FinalizeGCM(data_ptr_t out, idx_t out_len, data_ptr_t tag, i
126143
auto text_len = out_len;
127144

128145
switch (mode) {
129-
case ENCRYPT: {
146+
case EncryptionTypes::ENCRYPT: {
130147
if (1 != EVP_EncryptFinal_ex(context, data_ptr_cast(out) + out_len, reinterpret_cast<int *>(&out_len))) {
131148
throw InternalException("EncryptFinal failed");
132149
}
@@ -138,7 +155,7 @@ size_t AESStateSSL::FinalizeGCM(data_ptr_t out, idx_t out_len, data_ptr_t tag, i
138155
}
139156
return text_len;
140157
}
141-
case DECRYPT: {
158+
case EncryptionTypes::DECRYPT: {
142159
// Set expected tag value
143160
if (!EVP_CIPHER_CTX_ctrl(context, EVP_CTRL_GCM_SET_TAG, tag_len, tag)) {
144161
throw InternalException("Finalizing tag failed");
@@ -161,22 +178,22 @@ size_t AESStateSSL::FinalizeGCM(data_ptr_t out, idx_t out_len, data_ptr_t tag, i
161178

162179
size_t AESStateSSL::Finalize(data_ptr_t out, idx_t out_len, data_ptr_t tag, idx_t tag_len) {
163180

164-
if (cipher == GCM) {
181+
if (cipher == EncryptionTypes::GCM) {
165182
return FinalizeGCM(out, out_len, tag, tag_len);
166183
}
167184

168185
auto text_len = out_len;
169186
switch (mode) {
170187

171-
case ENCRYPT: {
188+
case EncryptionTypes::ENCRYPT: {
172189
if (1 != EVP_EncryptFinal_ex(context, data_ptr_cast(out) + out_len, reinterpret_cast<int *>(&out_len))) {
173190
throw InternalException("EncryptFinal failed");
174191
}
175192

176193
return text_len += out_len;
177194
}
178195

179-
case DECRYPT: {
196+
case EncryptionTypes::DECRYPT: {
180197
// EVP_DecryptFinal() will return an error code if final block is not correctly formatted.
181198
int ret = EVP_DecryptFinal_ex(context, data_ptr_cast(out) + out_len, reinterpret_cast<int *>(&out_len));
182199
text_len += out_len;

extension/httpfs/include/crypto.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void hex256(hash_bytes &in, hash_str &out);
2525
class DUCKDB_EXTENSION_API AESStateSSL : public duckdb::EncryptionState {
2626

2727
public:
28-
explicit AESStateSSL(const std::string *key = nullptr);
28+
explicit AESStateSSL(duckdb::EncryptionTypes::CipherType cipher_p, const std::string *key = nullptr);
2929
~AESStateSSL() override;
3030

3131
public:
@@ -40,8 +40,8 @@ class DUCKDB_EXTENSION_API AESStateSSL : public duckdb::EncryptionState {
4040

4141
private:
4242
EVP_CIPHER_CTX *context;
43-
Mode mode;
44-
Cipher cipher = GCM;
43+
duckdb::EncryptionTypes::Mode mode;
44+
duckdb::EncryptionTypes::CipherType cipher;
4545
};
4646

4747
} // namespace duckdb
@@ -53,8 +53,8 @@ class DUCKDB_EXTENSION_API AESStateSSLFactory : public duckdb::EncryptionUtil {
5353
explicit AESStateSSLFactory() {
5454
}
5555

56-
duckdb::shared_ptr<duckdb::EncryptionState> CreateEncryptionState(duckdb::const_data_ptr_t key = nullptr, duckdb::idx_t key_len = 0) const override {
57-
return duckdb::make_shared_ptr<duckdb::AESStateSSL>();
56+
duckdb::shared_ptr<duckdb::EncryptionState> CreateEncryptionState(duckdb::EncryptionTypes::CipherType cipher_p, duckdb::const_data_ptr_t key = nullptr, duckdb::idx_t key_len = 0) const override {
57+
return duckdb::make_shared_ptr<duckdb::AESStateSSL>(cipher_p);
5858
}
5959

6060
~AESStateSSLFactory() override {

0 commit comments

Comments
 (0)