From 07faceaa926bb61545ca2d88835480219a8dd796 Mon Sep 17 00:00:00 2001 From: Sylvain Pelissier Date: Tue, 19 Nov 2024 20:43:16 +0100 Subject: [PATCH] Update r_crypto_list arguments --- libr/core/cmd_print.inc.c | 10 +++++----- libr/core/cmd_write.inc.c | 4 ++-- libr/crypto/crypto.c | 9 +++------ libr/crypto/hash/hash.c | 2 +- libr/crypto/p/crypto_entropy.c | 2 +- libr/crypto/p/crypto_sip.c | 2 +- libr/crypto/p/crypto_strhash.c | 2 +- libr/include/r_crypto.h | 4 ++-- libr/main/rahash2.c | 2 +- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/libr/core/cmd_print.inc.c b/libr/core/cmd_print.inc.c index a89fcec1e0..d58b33493f 100644 --- a/libr/core/cmd_print.inc.c +++ b/libr/core/cmd_print.inc.c @@ -3411,7 +3411,7 @@ static void cmd_print_op(RCore *core, const char *input) { algo = r_list_get_n (args, 1); } if (!args || !algo) { - r_crypto_list (core->crypto, r_cons_printf, 0 | (int)R_CRYPTO_TYPE_SIGNATURE << 8); + r_crypto_list (core->crypto, r_cons_printf, 0, R_CRYPTO_TYPE_SIGNATURE); r_core_cmd_help_match (core, help_msg_po, "poS"); break; } @@ -3450,7 +3450,7 @@ static void cmd_print_op(RCore *core, const char *input) { algo = r_list_get_n (args, 1); } if (!args || !algo) { - r_crypto_list (core->crypto, r_cons_printf, 0 | (int)R_CRYPTO_TYPE_ENCRYPT << 8); + r_crypto_list (core->crypto, r_cons_printf, 0, R_CRYPTO_TYPE_ENCRYPT); r_core_cmd_help_match_spec (core, help_msg_po, "po", input[1]); break; } @@ -3917,19 +3917,19 @@ static bool cmd_print_ph(RCore *core, const char *input) { } if (!i0 || i0 == 'l' || i0 == 'L') { RCrypto *cry = r_crypto_new (); - r_crypto_list (cry, NULL, 'q' | (int)R_CRYPTO_TYPE_HASHER << 8); + r_crypto_list (cry, NULL, 'q', R_CRYPTO_TYPE_HASH); r_crypto_free (cry); return true; } if (i0 == 'j') { // "phj" RCrypto *cry = r_crypto_new (); - r_crypto_list (cry, r_cons_printf, 'j' | (int)R_CRYPTO_TYPE_ALL << 8); + r_crypto_list (cry, r_cons_printf, 'j', R_CRYPTO_TYPE_ALL); r_crypto_free (cry); return true; } if (i0 == 'J') { // "phJ" RCrypto *cry = r_crypto_new (); - r_crypto_list (cry, r_cons_printf, 'J' | (int)R_CRYPTO_TYPE_HASHER << 8); + r_crypto_list (cry, r_cons_printf, 'J', R_CRYPTO_TYPE_HASH); r_crypto_free (cry); return true; } diff --git a/libr/core/cmd_write.inc.c b/libr/core/cmd_write.inc.c index 69e7f25a2a..1d487a9d5d 100644 --- a/libr/core/cmd_write.inc.c +++ b/libr/core/cmd_write.inc.c @@ -430,7 +430,7 @@ static int cmd_wo(void *data, const char *input) { if (R_STR_ISNOTEMPTY (algo) && key) { write_encrypted_block (core, algo, key, direction, iv); } else { - r_crypto_list (core->crypto, r_cons_printf, 0 | (int)R_CRYPTO_TYPE_ENCRYPT << 8); + r_crypto_list (core->crypto, r_cons_printf, 0, R_CRYPTO_TYPE_ENCRYPT); r_core_cmd_help_match_spec (core, help_msg_wo, "wo", input[0]); } free (args); @@ -451,7 +451,7 @@ static int cmd_wo(void *data, const char *input) { if (R_STR_ISNOTEMPTY (algo) && key) { write_block_signature (core, algo, key); } else { - r_crypto_list (core->crypto, r_cons_printf, 0 | (int)R_CRYPTO_TYPE_SIGNATURE << 8); + r_crypto_list (core->crypto, r_cons_printf, 0, R_CRYPTO_TYPE_SIGNATURE); r_core_cmd_help_match_spec (core, help_msg_wo, "wo", input[0]); } free (args); diff --git a/libr/crypto/crypto.c b/libr/crypto/crypto.c index 168533b0bc..80a5097d7e 100644 --- a/libr/crypto/crypto.c +++ b/libr/crypto/crypto.c @@ -192,16 +192,13 @@ static inline void print_plugin_verbose(RCryptoPlugin *cp, PrintfCallback cb_pri cb_printf ("%c %12s %s\n", type, cp->meta.name, desc); } -R_API void r_crypto_list(RCrypto *cry, R_NULLABLE PrintfCallback cb_printf, int mode) { +R_API void r_crypto_list(RCrypto *cry, R_NULLABLE PrintfCallback cb_printf, int mode, RCryptoType type) { R_RETURN_IF_FAIL (cry); if (!cb_printf) { cb_printf = (PrintfCallback)printf; } PJ *pj = NULL; - // XXX R2_600 - add a type argument to be clearer but will break ABI. - RCryptoType type = (RCryptoType)mode >> 8; - mode = mode & 0xff; if (mode == 'J') { pj = pj_new (); pj_a (pj); @@ -226,7 +223,7 @@ R_API void r_crypto_list(RCrypto *cry, R_NULLABLE PrintfCallback cb_printf, int pj_o (pj); pj_ks (pj, "name", cp->meta.name); switch (cp->type) { - case R_CRYPTO_TYPE_HASHER: + case R_CRYPTO_TYPE_HASH: pj_ks (pj, "type", "hash"); break; case R_CRYPTO_TYPE_ENCRYPT: @@ -262,7 +259,7 @@ R_API void r_crypto_list(RCrypto *cry, R_NULLABLE PrintfCallback cb_printf, int } } // TODO: R2_592 move all those static hashes into crypto plugins and remove the code below - if (type == R_CRYPTO_TYPE_HASHER || type == R_CRYPTO_TYPE_ALL) { + if (type == R_CRYPTO_TYPE_HASH || type == R_CRYPTO_TYPE_ALL) { int i; for (i = 0; i < 64; i++) { ut64 bits = ((ut64)1) << i; diff --git a/libr/crypto/hash/hash.c b/libr/crypto/hash/hash.c index b3bf4fe088..162bb163c4 100644 --- a/libr/crypto/hash/hash.c +++ b/libr/crypto/hash/hash.c @@ -373,7 +373,7 @@ R_API R_MUSTUSE char *r_hash_tostring(R_NULLABLE RHash *ctx, const char *name, c ctx = r_hash_new (true, algo); } - if (cj && cj->h->type == R_CRYPTO_TYPE_HASHER) { + if (cj && cj->h->type == R_CRYPTO_TYPE_HASH) { r_crypto_job_update (cj, data, len); ut8 *result = r_crypto_job_get_output (cj, &digest_size); memcpy (ctx->digest, result, digest_size); diff --git a/libr/crypto/p/crypto_entropy.c b/libr/crypto/p/crypto_entropy.c index d7c3ea65d3..d07747f25f 100644 --- a/libr/crypto/p/crypto_entropy.c +++ b/libr/crypto/p/crypto_entropy.c @@ -52,7 +52,7 @@ RCryptoPlugin r_crypto_plugin_entropy = { .author = "pancake", .license = "MIT", }, - .type = R_CRYPTO_TYPE_HASHER, + .type = R_CRYPTO_TYPE_HASH, .update = update, .end = end }; diff --git a/libr/crypto/p/crypto_sip.c b/libr/crypto/p/crypto_sip.c index 718346e50c..beee458a8a 100644 --- a/libr/crypto/p/crypto_sip.c +++ b/libr/crypto/p/crypto_sip.c @@ -19,7 +19,7 @@ RCryptoPlugin r_crypto_plugin_sip = { .author = "pancake", .license = "MIT", }, - .type = R_CRYPTO_TYPE_HASHER, + .type = R_CRYPTO_TYPE_HASH, .implements = "sip", .update = update, .end = update diff --git a/libr/crypto/p/crypto_strhash.c b/libr/crypto/p/crypto_strhash.c index bf6453e282..f68893ebf3 100644 --- a/libr/crypto/p/crypto_strhash.c +++ b/libr/crypto/p/crypto_strhash.c @@ -20,7 +20,7 @@ RCryptoPlugin r_crypto_plugin_strhash = { .author = "pancake", .license = "MIT", }, - .type = R_CRYPTO_TYPE_HASHER, + .type = R_CRYPTO_TYPE_HASH, .implements = "strhash", .update = update, .end = update diff --git a/libr/include/r_crypto.h b/libr/include/r_crypto.h index 6a9b45d6eb..38e4f5da62 100644 --- a/libr/include/r_crypto.h +++ b/libr/include/r_crypto.h @@ -68,7 +68,7 @@ typedef struct r_crypto_job_t { typedef enum { R_CRYPTO_TYPE_ENCODER = 'e', - R_CRYPTO_TYPE_HASHER = 'h', + R_CRYPTO_TYPE_HASH = 'h', R_CRYPTO_TYPE_ENCRYPT = 'c', // CIPHER R_CRYPTO_TYPE_SIGNATURE = 's', R_CRYPTO_TYPE_ALL = 'a' @@ -103,7 +103,7 @@ R_API void r_crypto_init(RCrypto *cry); R_API bool r_crypto_add(RCrypto *cry, RCryptoPlugin *h); R_API RCrypto *r_crypto_new(void); R_API void r_crypto_free(RCrypto *cry); -R_API void r_crypto_list(RCrypto *cry, PrintfCallback cb_printf, int mode); +R_API void r_crypto_list(RCrypto *cry, PrintfCallback cb_printf, int mode, RCryptoType type); // R_API RCryptoHash *r_crypto_hash(RCrypto *cry, bool rst, const char *name); diff --git a/libr/main/rahash2.c b/libr/main/rahash2.c index d36c0046ba..1383f80e81 100644 --- a/libr/main/rahash2.c +++ b/libr/main/rahash2.c @@ -348,7 +348,7 @@ static int do_help(int line) { static void algolist(int mode) { RCrypto *cry = r_crypto_new (); - r_crypto_list (cry, NULL, mode | (int)R_CRYPTO_TYPE_ALL << 8); + r_crypto_list (cry, NULL, mode, (int)R_CRYPTO_TYPE_ALL); r_crypto_free (cry); }