mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-06 18:13:46 +00:00
New commands poE
and poD
##crypto
Some checks are pending
build / linux-wasi (push) Waiting to run
build / linux-wasi-api (push) Waiting to run
build / linux-csnext (push) Waiting to run
build / tarball (push) Waiting to run
build / linux-static (push) Waiting to run
build / linux-acr-rpm-64 (push) Waiting to run
build / linux-acr-deb (amd64) (push) Waiting to run
build / linux-acr-deb (arm64, aarch64-linux-gnu) (push) Waiting to run
build / linux-acr-deb (i386, multilib) (push) Waiting to run
build / macos-acr (arm64, 13) (push) Waiting to run
build / macos-acr (x86_64, 12) (push) Waiting to run
build / ios (cydia32) (push) Waiting to run
build / ios (true, cydia) (push) Waiting to run
build / android-acr (16, arm) (push) Waiting to run
build / android-acr (aarch64) (push) Waiting to run
build / android-meson (x86_64) (push) Waiting to run
build / w32-meson (push) Waiting to run
build / w64-static-2022 (push) Waiting to run
build / w64-static (push) Waiting to run
build / w64-meson (push) Waiting to run
build / check_abi_compatibility (push) Blocked by required conditions
build / check_release (push) Blocked by required conditions
build / release (push) Blocked by required conditions
CI / linux-acr-oldlibsbug (push) Waiting to run
CI / linux-nocs (push) Waiting to run
CI / linux-acr-gperf (push) Waiting to run
CI / linux-sys-capstone (push) Waiting to run
CI / linux-acr-resymlink (push) Waiting to run
CI / linux-test (push) Waiting to run
CI / linux-static-meson (push) Waiting to run
CI / macos-test (push) Waiting to run
CI / linux-rpath (push) Waiting to run
CI / macos-rpath (push) Waiting to run
CI / linux-meson-spaces (push) Waiting to run
CI / linux-tinyasan-fuzz (push) Waiting to run
CI / linux-asan-fuzz (push) Waiting to run
CI / w64-make (push) Waiting to run
CI / w32-mingw (push) Waiting to run
CI / w64-mingw (push) Waiting to run
Code scanning - action / CodeQL-Build (push) Waiting to run
Coverity Scan / latest (push) Waiting to run
tcc / ubuntu-tcc-newabi (push) Waiting to run
tcc / ubuntu-tcc-test (push) Waiting to run
tcc / ubuntu-tcc-nodbg (push) Waiting to run
tcc / r2pm-tcc (push) Waiting to run
tcc / ubuntu-tcc-syslibs (push) Waiting to run
Some checks are pending
build / linux-wasi (push) Waiting to run
build / linux-wasi-api (push) Waiting to run
build / linux-csnext (push) Waiting to run
build / tarball (push) Waiting to run
build / linux-static (push) Waiting to run
build / linux-acr-rpm-64 (push) Waiting to run
build / linux-acr-deb (amd64) (push) Waiting to run
build / linux-acr-deb (arm64, aarch64-linux-gnu) (push) Waiting to run
build / linux-acr-deb (i386, multilib) (push) Waiting to run
build / macos-acr (arm64, 13) (push) Waiting to run
build / macos-acr (x86_64, 12) (push) Waiting to run
build / ios (cydia32) (push) Waiting to run
build / ios (true, cydia) (push) Waiting to run
build / android-acr (16, arm) (push) Waiting to run
build / android-acr (aarch64) (push) Waiting to run
build / android-meson (x86_64) (push) Waiting to run
build / w32-meson (push) Waiting to run
build / w64-static-2022 (push) Waiting to run
build / w64-static (push) Waiting to run
build / w64-meson (push) Waiting to run
build / check_abi_compatibility (push) Blocked by required conditions
build / check_release (push) Blocked by required conditions
build / release (push) Blocked by required conditions
CI / linux-acr-oldlibsbug (push) Waiting to run
CI / linux-nocs (push) Waiting to run
CI / linux-acr-gperf (push) Waiting to run
CI / linux-sys-capstone (push) Waiting to run
CI / linux-acr-resymlink (push) Waiting to run
CI / linux-test (push) Waiting to run
CI / linux-static-meson (push) Waiting to run
CI / macos-test (push) Waiting to run
CI / linux-rpath (push) Waiting to run
CI / macos-rpath (push) Waiting to run
CI / linux-meson-spaces (push) Waiting to run
CI / linux-tinyasan-fuzz (push) Waiting to run
CI / linux-asan-fuzz (push) Waiting to run
CI / w64-make (push) Waiting to run
CI / w32-mingw (push) Waiting to run
CI / w64-mingw (push) Waiting to run
Code scanning - action / CodeQL-Build (push) Waiting to run
Coverity Scan / latest (push) Waiting to run
tcc / ubuntu-tcc-newabi (push) Waiting to run
tcc / ubuntu-tcc-test (push) Waiting to run
tcc / ubuntu-tcc-nodbg (push) Waiting to run
tcc / r2pm-tcc (push) Waiting to run
tcc / ubuntu-tcc-syslibs (push) Waiting to run
This commit is contained in:
parent
09ee59c92a
commit
fe31b6759f
@ -524,6 +524,8 @@ static RCoreHelpMessage help_msg_po = {
|
||||
"poa", " [val]", "+= addition (f.ex: poa 0102)",
|
||||
"poA", " [val]", "&= and",
|
||||
"pod", " [val]", "/= divide",
|
||||
"poD", " [algo] [key] [iv]", "Print block decryption",
|
||||
"poE", " [algo] [key] [iv]", "Print block encryption",
|
||||
"pol", " [val]", "<<= shift left",
|
||||
"pom", " [val]", "*= multiply",
|
||||
"poo", " [val]", "|= or",
|
||||
@ -3277,6 +3279,57 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void print_encrypted_block(RCore *core, const char *algo, const char *key, int direction, const char *iv) {
|
||||
int keylen = 0;
|
||||
ut8 *binkey = NULL;
|
||||
if (!strncmp (key, "s:", 2)) {
|
||||
binkey = (ut8 *)strdup (key + 2);
|
||||
keylen = strlen (key + 2);
|
||||
} else {
|
||||
binkey = (ut8 *)strdup (key);
|
||||
keylen = r_hex_str2bin (key, binkey);
|
||||
}
|
||||
if (!binkey) {
|
||||
return;
|
||||
}
|
||||
if (keylen < 1) {
|
||||
const char *mode = (!direction)? "Encryption": "Decryption";
|
||||
R_LOG_ERROR ("%s key not defined", mode);
|
||||
free (binkey);
|
||||
return;
|
||||
}
|
||||
RCryptoJob *cj = r_crypto_use (core->crypto, algo);
|
||||
if (cj && cj->h->type == R_CRYPTO_TYPE_ENCRYPT) {
|
||||
if (r_crypto_job_set_key (cj, binkey, keylen, 0, direction)) {
|
||||
if (iv) {
|
||||
ut8 *biniv = malloc (strlen (iv) + 1);
|
||||
int ivlen = r_hex_str2bin (iv, biniv);
|
||||
if (ivlen < 1) {
|
||||
ivlen = strlen (iv);
|
||||
strcpy ((char *)biniv, iv);
|
||||
}
|
||||
if (!r_crypto_job_set_iv (cj, biniv, ivlen)) {
|
||||
R_LOG_ERROR ("Invalid IV");
|
||||
return;
|
||||
}
|
||||
}
|
||||
r_crypto_job_update (cj, (const ut8 *)core->block, core->blocksize);
|
||||
|
||||
int result_size = 0;
|
||||
ut8 *result = r_crypto_job_get_output (cj, &result_size);
|
||||
if (result) {
|
||||
r_print_bytes (core->print, result, result_size, "%02x");
|
||||
free (result);
|
||||
}
|
||||
}
|
||||
free (binkey);
|
||||
return;
|
||||
} else {
|
||||
R_LOG_ERROR ("Unknown %s algorithm '%s'", ((!direction)? "encryption": "decryption"), algo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void cmd_print_op(RCore *core, const char *input) {
|
||||
ut8 *buf = NULL;
|
||||
if (!input[0]) {
|
||||
@ -3347,6 +3400,30 @@ static void cmd_print_op(RCore *core, const char *input) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'D': // "poD"
|
||||
case 'E': { // "poE"
|
||||
int direction = (input[1] == 'E')? R_CRYPTO_DIR_ENCRYPT: R_CRYPTO_DIR_DECRYPT;
|
||||
char *cmd = strdup (input);
|
||||
RList *args = r_str_split_list (cmd, " ", 0);
|
||||
char *algo = NULL;
|
||||
if (args) {
|
||||
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_core_cmd_help_match_spec (core, help_msg_po, "po", input[1]);
|
||||
break;
|
||||
}
|
||||
char *key = r_list_get_n (args, 2);
|
||||
if (!key) {
|
||||
const char *mode = (direction == R_CRYPTO_DIR_ENCRYPT)? "Encryption": "Decryption";
|
||||
R_LOG_ERROR ("%s key not defined", mode);
|
||||
return;
|
||||
}
|
||||
char *iv = r_list_get_n (args, 3);
|
||||
print_encrypted_block (core, algo, key, direction, iv);
|
||||
break;
|
||||
}
|
||||
case '\0':
|
||||
case '?':
|
||||
default:
|
||||
|
@ -255,7 +255,7 @@ static void write_encrypted_block(RCore *core, const char *algo, const char *key
|
||||
return;
|
||||
}
|
||||
if (keylen < 1) {
|
||||
const char *mode = (!direction)? "Encryption": "Decryption";
|
||||
const char *mode = (direction == R_CRYPTO_DIR_ENCRYPT)? "Encryption": "Decryption";
|
||||
R_LOG_ERROR ("%s key not defined. Use -S [key]", mode);
|
||||
free (binkey);
|
||||
return;
|
||||
@ -290,7 +290,7 @@ static void write_encrypted_block(RCore *core, const char *algo, const char *key
|
||||
free (binkey);
|
||||
return;
|
||||
} else {
|
||||
R_LOG_ERROR ("Unknown %s algorithm '%s'", ((!direction)? "encryption": "decryption"), algo);
|
||||
R_LOG_ERROR ("Unknown %s algorithm '%s'", ((direction == R_CRYPTO_DIR_ENCRYPT)? "encryption": "decryption"), algo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -309,7 +309,7 @@ static void write_block_signature(RCore *core, const char *algo, const char *key
|
||||
return;
|
||||
}
|
||||
if (keylen < 1) {
|
||||
R_LOG_ERROR ("Private key not defined. Use -S [key]");
|
||||
R_LOG_ERROR ("Private key not defined");
|
||||
free (binkey);
|
||||
return;
|
||||
}
|
||||
|
@ -1299,4 +1299,28 @@ EOF
|
||||
EXPECT=<<EOF
|
||||
6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=poE blowfish (Test vectors)
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
b 8
|
||||
wx 0123456789abcdef @ 131
|
||||
poE blowfish fedcba9876543210 @ 131
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0aceab0fc6a0a28d
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=poD blowfish (Test vectors)
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
b 8
|
||||
wx 0aceab0fc6a0a28d @ 27
|
||||
poD blowfish fedcba9876543210 @ 27
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0123456789abcdef
|
||||
EOF
|
||||
RUN
|
Loading…
Reference in New Issue
Block a user