From 4720b5ac21163936fb47f524037a6f12ce6e6ce2 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 22 Jul 2026 18:31:50 +0200 Subject: rewrite: the beginning This a giant fuck-you to myself while I have nothing (actually, tons of things) to do in a hospital. * The giant screens of preprocessor code are gone, they always sucked, fuck them. * Switched everything to the "boxes" interface as the only one remaining. * Restuctured things in aes/ so that the files they're in make at least a little bit of sense. * Removed a bunch of cruft and prematurely generic code. * This is half-baked at best: I just made sure that the tests pass. A lot of cleanup awaits. --- aes/src/box.c | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) (limited to 'aes/src/box.c') diff --git a/aes/src/box.c b/aes/src/box.c index dd50f25..e4750dc 100644 --- a/aes/src/box.c +++ b/aes/src/box.c @@ -10,16 +10,10 @@ #include #include -static const AES_BoxOps* aes_box_ops_list[] = { - &aes128_box_ops, - &aes192_box_ops, - &aes256_box_ops, -}; - AES_StatusCode aes_box_init( AES_Box* box, AES_Algorithm algorithm, - const AES_BoxKey* box_key, + const AES_Key* box_key, AES_Mode mode, const AES_Block* iv, AES_ErrorDetails* err_details @@ -28,13 +22,16 @@ AES_StatusCode aes_box_init( box->algorithm = algorithm; box->mode = mode; - if (iv != NULL) + + if (!iv && aes_mode_requires_init_vector(mode)) + return aes_error_mode_requires_init_vector(err_details); + if (iv) box->iv = *iv; - box->ops = aes_box_ops_list[algorithm]; - status = box->ops->calc_round_keys( - box_key, &box->encryption_keys, &box->decryption_keys, err_details - ); + box->ops = aes_get_ops(algorithm); + + status = + box->ops->expand_key(box_key, &box->encryption_keys, &box->decryption_keys, err_details); if (aes_is_error(status)) return status; @@ -533,31 +530,3 @@ AES_StatusCode aes_box_decrypt_buffer( return status; } } - -AES_StatusCode aes_box_parse_key( - AES_BoxKey* dest, - AES_Algorithm algorithm, - const char* src, - AES_ErrorDetails* err_details -) { - if (dest == NULL) - return aes_error_null_argument(err_details, "dest"); - if (src == NULL) - return aes_error_null_argument(err_details, "src"); - - return aes_box_ops_list[algorithm]->parse_key(dest, src, err_details); -} - -AES_StatusCode aes_box_format_key( - AES_BoxKeyString* dest, - AES_Algorithm algorithm, - const AES_BoxKey* src, - AES_ErrorDetails* err_details -) { - if (dest == NULL) - return aes_error_null_argument(err_details, "dest"); - if (src == NULL) - return aes_error_null_argument(err_details, "src"); - - return aes_box_ops_list[algorithm]->format_key(dest, src, err_details); -} -- cgit v1.3