MCPcopy Create free account
hub / github.com/apache/impala / ReadEncryptionHeader

Function ReadEncryptionHeader

be/src/kudu/util/env_posix.cc:838–870  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

836}
837
838Status ReadEncryptionHeader(int fd, const string& filename, const EncryptionHeader& server_key,
839 EncryptionHeader* eh) {
840 char magic[7];
841 uint8_t algorithm[1];
842 char file_key[32];
843 vector<Slice> headerv({ Slice(magic, 7), Slice(algorithm, 1), Slice(file_key, 32) });
844 RETURN_NOT_OK(DoReadV(fd, filename, 0, headerv, nullptr));
845 if (strncmp(magic, kEncryptionHeaderMagic, 7) != 0) {
846 return Status::Corruption(Substitute("Invalid encryption header: $0", magic));
847 }
848 uint16_t key_size;
849 eh->algorithm = EncryptionAlgorithm(algorithm[0]);
850 switch (eh->algorithm) {
851 case EncryptionAlgorithm::AES128CTR:
852 key_size = 16;
853 break;
854 case EncryptionAlgorithm::AES192CTR:
855 key_size = 24;
856 break;
857 case EncryptionAlgorithm::AES256CTR:
858 key_size = 32;
859 break;
860 default:
861 return Status::Corruption(Substitute("Unknown encryption algorithm: $0", algorithm));
862 }
863 // Round up to the nearest multiple of 16 bytes when reading and decrypting
864 // the file. The actual key size can be used when storing the key in memory.
865 // See WriteEncryptionHeader for more info.
866 vector<Slice> v = {Slice(file_key, (key_size + 15) & -16)};
867 RETURN_NOT_OK(DoDecryptV(&server_key, 0, v));
868 memcpy(&eh->key, file_key, key_size);
869 return Status::OK();
870}
871
872const char* ResourceLimitTypeToString(Env::ResourceLimitType t) {
873 switch (t) {

Callers 4

NewSequentialFileMethod · 0.85
NewRandomAccessFileMethod · 0.85
NewRWFileMethod · 0.85

Calls 7

DoReadVFunction · 0.85
CorruptionFunction · 0.85
SubstituteFunction · 0.85
DoDecryptVFunction · 0.85
OKFunction · 0.85
SliceClass · 0.70

Tested by

no test coverage detected