Skip to content

Commit 59a0893

Browse files
author
marc
committed
Remove extra key length check and improve error message
1 parent f24b12a commit 59a0893

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

c-deps/libroach/ccl/key_manager.cc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
88

99
#include "key_manager.h"
10-
#include <cryptopp/aes.h>
1110
#include <cryptopp/modes.h>
1211
#include <google/protobuf/stubs/stringprintf.h>
1312

@@ -35,17 +34,8 @@ static rocksdb::Status KeyFromFile(rocksdb::Env* env, const std::string& path, E
3534
// Check that the length is valid for AES.
3635
auto key_length = contents.size();
3736
if (key_length != 16 && key_length != 24 && key_length != 32) {
38-
return rocksdb::Status::InvalidArgument(
39-
StringPrintf("key in file %s has length %llu, want 16, 24, or 32", path.c_str(), key_length));
40-
}
41-
42-
// Let's make sure CryptoPP::AES is ok with it, this returns a valid key length based on the
43-
// passed-in one (eg: 32 for 31).
44-
size_t accepted = CryptoPP::AES::Encryption::StaticGetValidKeyLength(key_length);
45-
if (accepted != key_length) {
46-
return rocksdb::Status::InvalidArgument(
47-
StringPrintf("key in file %s has length %llu, but CryptoPP::AES says the nearest acceptable is %llu",
48-
path.c_str(), key_length, accepted));
37+
return rocksdb::Status::InvalidArgument(StringPrintf(
38+
"key in file %s is %llu bytes long, AES keys can be 16, 24, or 32 bytes", path.c_str(), key_length));
4939
}
5040

5141
// Fill in the key.

c-deps/libroach/ccl/key_manager_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ TEST(FileKeyManager, ReadKeyFiles) {
4444
{"missing_new.key", "missing_old.key", "missing_new.key: File not found"},
4545
{"plain", "missing_old.key", "missing_old.key: File not found"},
4646
{"plain", "plain", ""},
47-
{"empty.key", "plain", "key in file empty.key has length 0, want 16, 24, or 32"},
48-
{"8.key", "plain", "key in file 8.key has length 8, want 16, 24, or 32"},
47+
{"empty.key", "plain", "key in file empty.key is 0 bytes long, AES keys can be 16, 24, or 32 bytes"},
48+
{"8.key", "plain", "key in file 8.key is 8 bytes long, AES keys can be 16, 24, or 32 bytes"},
4949
{"16.key", "plain", ""},
5050
{"24.key", "plain", ""},
5151
{"32.key", "plain", ""},
52-
{"64.key", "plain", "key in file 64.key has length 64, want 16, 24, or 32"},
53-
{"16.key", "8.key", "key in file 8.key has length 8, want 16, 24, or 32"},
52+
{"64.key", "plain", "key in file 64.key is 64 bytes long, AES keys can be 16, 24, or 32 bytes"},
53+
{"16.key", "8.key", "key in file 8.key is 8 bytes long, AES keys can be 16, 24, or 32 bytes"},
5454
{"16.key", "32.key", ""},
5555
};
5656

0 commit comments

Comments
 (0)