| 836 | } |
| 837 | |
| 838 | Status 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 | |
| 872 | const char* ResourceLimitTypeToString(Env::ResourceLimitType t) { |
| 873 | switch (t) { |
no test coverage detected