Changeset View
Standalone View
tools/tools/crypto/cryptocheck.c
Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | int pkey; | ||||
.evp_cipher = EVP_aes_256_ccm, .tag_len = AES_CBC_MAC_HASH_LEN }, | .evp_cipher = EVP_aes_256_ccm, .tag_len = AES_CBC_MAC_HASH_LEN }, | ||||
{ .name = "chacha20-poly1305", .cipher = CRYPTO_CHACHA20_POLY1305, | { .name = "chacha20-poly1305", .cipher = CRYPTO_CHACHA20_POLY1305, | ||||
.type = T_AEAD, .tag_len = POLY1305_HASH_LEN, | .type = T_AEAD, .tag_len = POLY1305_HASH_LEN, | ||||
.evp_cipher = EVP_chacha20_poly1305 }, | .evp_cipher = EVP_chacha20_poly1305 }, | ||||
}; | }; | ||||
static bool verbose; | static bool verbose; | ||||
static int requested_crid; | static int requested_crid; | ||||
static size_t aad_sizes[48], sizes[128]; | static size_t aad_sizes[48], sizes[EALG_MAX_BLOCK_LEN * 2]; | ||||
markj: I don't quite understand the relationship between EALG_MAX_BLOCK_LEN and the number of sizes we… | |||||
jhbAuthorUnsubmitted Done Inline ActionsBefore it was also a bit of a guess at a number (the magic 128). The assertion _should_ ensure that we don't overflow the array in practice. It's mostly just laziness to avoid having to deal with malloc. Alternatively this could be in C++ with a std::vector<> which would avoid the need for static sizes here as well as the helper variables (naad_sizes and nsizes). I mostly just used N * 2 I as I know we needed at least N + 1 and my plan was to let '-z' assert if it was too small and if so bump it up to N * 3, etc. That is roughly the plan I used when I used 128 before though it was more of a guess that worked the first time. jhb: Before it was also a bit of a guess at a number (the magic 128). The assertion _should_ ensure… | |||||
static u_int naad_sizes, nsizes; | static u_int naad_sizes, nsizes; | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"usage: cryptocheck [-z] [-a algorithm] [-d dev] [size ...]\n"); | "usage: cryptocheck [-z] [-a algorithm] [-d dev] [size ...]\n"); | ||||
exit(1); | exit(1); | ||||
▲ Show 20 Lines • Show All 1,484 Lines • ▼ Show 20 Lines | if (naad_sizes == 0) { | ||||
} else { | } else { | ||||
aad_sizes[0] = 0; | aad_sizes[0] = 0; | ||||
naad_sizes = 1; | naad_sizes = 1; | ||||
} | } | ||||
} | } | ||||
if (nsizes == 0) { | if (nsizes == 0) { | ||||
if (testall) { | if (testall) { | ||||
for (i = 1; i <= 32; i++) { | for (i = 1; i <= EALG_MAX_BLOCK_LEN; i++) { | ||||
sizes[nsizes] = i; | sizes[nsizes] = i; | ||||
nsizes++; | nsizes++; | ||||
} | } | ||||
base_size = 32; | for (i = EALG_MAX_BLOCK_LEN + 8; | ||||
i <= EALG_MAX_BLOCK_LEN * 2; i += 8) { | |||||
Not Done Inline Actions16 isn’t a partial block for any 128-bit cipher, like AES? cem: 16 isn’t a partial block for any 128-bit cipher, like AES? | |||||
Done Inline Actions
Ugh, only for Chacha I guess. I could lower the increment to 8. jhb: > 16 isn’t a partial block for any 128-bit cipher, like AES?
Ugh, only for Chacha I guess. I… | |||||
Not Done Inline Actions8 sounds good to me. No one should be using 64-bit block ciphers anymore (DES). cem: 8 sounds good to me. No one should be using 64-bit block ciphers anymore (DES). | |||||
sizes[nsizes] = i; | |||||
nsizes++; | |||||
} | |||||
base_size = EALG_MAX_BLOCK_LEN * 2; | |||||
while (base_size * 2 < 240 * 1024) { | while (base_size * 2 < 240 * 1024) { | ||||
base_size *= 2; | base_size *= 2; | ||||
assert(nsizes < nitems(sizes)); | assert(nsizes < nitems(sizes)); | ||||
sizes[nsizes] = base_size; | sizes[nsizes] = base_size; | ||||
nsizes++; | nsizes++; | ||||
} | } | ||||
if (sizes[nsizes - 1] < 240 * 1024) { | if (sizes[nsizes - 1] < 240 * 1024) { | ||||
Show All 39 Lines |
I don't quite understand the relationship between EALG_MAX_BLOCK_LEN and the number of sizes we use. We test
so with the current max block length of 128 == EALG_MAX_BLOCK_LEN * 2 it just happens to work.