encryption size delta

This commit is contained in:
Gidon Gershinsky committed 2019-05-28 08:31:57 +03:00
1 parent 4d832d66b8
commit 9f68cab27b
2 files changed
+20 -2

No files matched your search

+7 -1
View File
@@ -54,8 +54,10 @@ AesEncryptor::AesEncryptor(ParquetCipher::type alg_id, int key_len, bool metadat
throw ParquetException(ss.str());
}
ciphertext_size_delta_ = BufferSizeLength + NonceLength;
if (metadata || (ParquetCipher::AES_GCM_V1 == alg_id)) {
aes_mode_ = GCM_MODE;
ciphertext_size_delta_ += GCMTagLength;
} else {
aes_mode_ = CTR_MODE;
}
@@ -94,6 +96,10 @@ AesEncryptor::AesEncryptor(ParquetCipher::type alg_id, int key_len, bool metadat
}
}
int AesEncryptor::CiphertextSizeDelta() {
return ciphertext_size_delta_;
}
int AesEncryptor::gcm_encrypt(const uint8_t* plaintext, int plaintext_len,
uint8_t* key, int key_len, uint8_t* nonce, uint8_t* aad,
int aad_len, uint8_t* ciphertext) {
@@ -242,7 +248,7 @@ AesDecryptor::AesDecryptor(ParquetCipher::type alg_id, int key_len, bool metadat
ciphertext_size_delta_ = BufferSizeLength + NonceLength;
if (metadata || (ParquetCipher::AES_GCM_V1 == alg_id)) {
aes_mode_ = GCM_MODE;
aes_mode_ = GCM_MODE;
ciphertext_size_delta_ += GCMTagLength;
} else {
aes_mode_ = CTR_MODE;
+13 -1
View File
@@ -44,13 +44,19 @@ const int8_t OffsetIndex = 7;
class AesEncryptor {
public:
// Can serve one key length only. Possible values: 16, 24, 32 bytes.
AesEncryptor(ParquetCipher::type alg_id, int key_len, bool metadata);
// Size different between plaintext and ciphertext, for this cipher.
int CiphertextSizeDelta();
// Key length is passed only for validation. If different from value in
// constructor, exception will be thrown.
int Encrypt(const uint8_t* plaintext, int plaintext_len, uint8_t* key, int key_len,
uint8_t* aad, int aad_len, uint8_t* ciphertext);
int SignedFooterEncrypt(const uint8_t* footer, int footer_len, uint8_t* key, int key_len,
uint8_t* aad, int aad_len, uint8_t* nonce, uint8_t* encrypted_footer);
uint8_t* aad, int aad_len, uint8_t* nonce, uint8_t* encrypted_footer);
~AesEncryptor() {
if (nullptr != ctx_) {
@@ -62,6 +68,7 @@ class AesEncryptor {
EVP_CIPHER_CTX* ctx_;
int aes_mode_;
int key_length_;
int ciphertext_size_delta_;
int gcm_encrypt(const uint8_t* plaintext, int plaintext_len, uint8_t* key, int key_len,
uint8_t* nonce, uint8_t* aad, int aad_len, uint8_t* ciphertext);
@@ -72,10 +79,14 @@ class AesEncryptor {
class AesDecryptor {
public:
// Can serve one key length only. Possible values: 16, 24, 32 bytes.
AesDecryptor(ParquetCipher::type alg_id, int key_len, bool metadata);
// Size different between plaintext and ciphertext, for this cipher.
int CiphertextSizeDelta();
// Key length is passed only for validation. If different from value in
// constructor, exception will be thrown.
int Decrypt(const uint8_t* ciphertext, int ciphertext_len, uint8_t* key, int key_len,
uint8_t* aad, int aad_len, uint8_t* plaintext);
@@ -105,6 +116,7 @@ std::string createModuleAAD(const std::string& fileAAD, int8_t module_type,
std::string createFooterAAD(const std::string& aad_prefix_bytes);
// Update last two bytes of page (or page header) module AAD
void quickUpdatePageAAD(const std::string &AAD, int16_t new_page_ordinal);
} // namespace parquet_encryption