in src/parquet/util/crypto.cc [54:123]
explicit EvpCipher(int cipher, int key_len, int type) {
ctx_ = nullptr;
if (aesGcm != cipher && aesCtr != cipher) {
std::stringstream ss;
ss << "Wrong cipher: " << cipher;
throw ParquetException(ss.str());
}
if (16 != key_len && 24 != key_len && 32 != key_len) {
std::stringstream ss;
ss << "Wrong key length: " << key_len;
throw ParquetException(ss.str());
}
if (encryptType != type && decryptType != type) {
std::stringstream ss;
ss << "Wrong cipher type: " << type;
throw ParquetException(ss.str());
}
ctx_ = EVP_CIPHER_CTX_new();
if (nullptr == ctx_) {
throw ParquetException("Couldn't init cipher context");
}
if (aesGcm == cipher) {
// Init AES-GCM with specified key length
if (16 == key_len) {
if (encryptType == type) {
ENCRYPT_INIT(ctx_, EVP_aes_128_gcm());
} else {
DECRYPT_INIT(ctx_, EVP_aes_128_gcm());
}
} else if (24 == key_len) {
if (encryptType == type) {
ENCRYPT_INIT(ctx_, EVP_aes_192_gcm());
} else {
DECRYPT_INIT(ctx_, EVP_aes_192_gcm());
}
} else if (32 == key_len) {
if (encryptType == type) {
ENCRYPT_INIT(ctx_, EVP_aes_256_gcm());
} else {
DECRYPT_INIT(ctx_, EVP_aes_256_gcm());
}
}
} else {
// Init AES-CTR with specified key length
if (16 == key_len) {
if (encryptType == type) {
ENCRYPT_INIT(ctx_, EVP_aes_128_ctr());
} else {
DECRYPT_INIT(ctx_, EVP_aes_128_ctr());
}
} else if (24 == key_len) {
if (encryptType == type) {
ENCRYPT_INIT(ctx_, EVP_aes_192_ctr());
} else {
DECRYPT_INIT(ctx_, EVP_aes_192_ctr());
}
} else if (32 == key_len) {
if (encryptType == type) {
ENCRYPT_INIT(ctx_, EVP_aes_256_ctr());
} else {
DECRYPT_INIT(ctx_, EVP_aes_256_ctr());
}
}
}
}