Skip to content

Commit

Permalink
set or check ciphertext length
Browse files Browse the repository at this point in the history
  • Loading branch information
Gidon Gershinsky authored and ggershinsky committed May 28, 2019
1 parent 03ede65 commit 8e7fe90
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cpp/src/parquet/util/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ int gcm_decrypt(const uint8_t* ciphertext, int ciphertext_len, uint8_t* key, int
memset(tag, 0, gcmTagLen);
uint8_t iv[nonceLen];
memset(iv, 0, nonceLen);

// Extract ciphertext length
int ciphertext_length =
((ciphertext[3] & 0xff) << 24) |
((ciphertext[2] & 0xff) << 16) |
((ciphertext[1] & 0xff) << 8) |
((ciphertext[0] & 0xff));

if (ciphertext_len > 0 && ciphertext_len != ciphertext_length) {
throw ParquetException("Wrong ciphertext length");
}
ciphertext_len = ciphertext_length;

// Extracting IV and tag
std::copy(ciphertext + bufferSizeLen, ciphertext + bufferSizeLen + nonceLen, iv);
Expand Down Expand Up @@ -333,6 +345,18 @@ int ctr_decrypt(const uint8_t* ciphertext, int ciphertext_len, uint8_t* key, int

uint8_t iv[ctrIvLen];
memset(iv, 0, ctrIvLen);

// Extract ciphertext length
int ciphertext_length =
((ciphertext[3] & 0xff) << 24) |
((ciphertext[2] & 0xff) << 16) |
((ciphertext[1] & 0xff) << 8) |
((ciphertext[0] & 0xff));

if (ciphertext_len > 0 && ciphertext_len != ciphertext_length) {
throw ParquetException("Wrong ciphertext length");
}
ciphertext_len = ciphertext_length;

// Extracting IV and tag
std::copy(ciphertext + bufferSizeLen, ciphertext + bufferSizeLen + ctrIvLen, iv);
Expand Down

0 comments on commit 8e7fe90

Please sign in to comment.