mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-26 22:50:48 +00:00
53582571fe
Some checks failed
build / linux-wasi (push) Waiting to run
build / linux-wasi-api (push) Waiting to run
build / linux-csnext (push) Waiting to run
build / linux-ssl-crypto (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
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
Code scanning - action / CodeQL-Build (push) Has been cancelled
Coverity Scan / latest (push) Has been cancelled
67 lines
1.6 KiB
C
67 lines
1.6 KiB
C
/* radare - LGPL - Copyright 2017-2022 - Sylvain Pelissier
|
|
* Implementation of SM4 block cipher
|
|
* https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10
|
|
*
|
|
* */
|
|
|
|
#include <r_crypto/r_sm4.h>
|
|
#include <r_crypto.h>
|
|
#include <memory.h>
|
|
|
|
static void sm4_crypt(const ut32 *sk, const ut8 *inbuf, ut8 *outbuf, int buflen) {
|
|
for (; buflen > 0; buflen -= SM4_BLOCK_SIZE) {
|
|
sm4_round (sk, inbuf, outbuf);
|
|
inbuf += SM4_BLOCK_SIZE;
|
|
outbuf += SM4_BLOCK_SIZE;
|
|
}
|
|
}
|
|
|
|
static bool sm4_set_key(RCryptoJob *cj, const ut8 *key, int keylen, int mode, int direction) {
|
|
cj->dir = direction;
|
|
return sm4_init (cj->sm4_sk, key, keylen, direction);
|
|
}
|
|
|
|
static int sm4_get_key_size(RCryptoJob *cry) {
|
|
return SM4_KEY_SIZE;
|
|
}
|
|
|
|
static bool update(RCryptoJob *cj, const ut8 *buf, int len) {
|
|
R_RETURN_VAL_IF_FAIL (cj&& buf, false);
|
|
ut8 *obuf = calloc (1, len);
|
|
if (!obuf) {
|
|
return false;
|
|
}
|
|
/* SM4 encryption or decryption */
|
|
sm4_crypt (cj->sm4_sk, buf, obuf, len);
|
|
r_crypto_job_append (cj, obuf, len);
|
|
free (obuf);
|
|
return true;
|
|
}
|
|
|
|
static bool end(RCryptoJob *cj, const ut8 *buf, int len) {
|
|
return update (cj, buf, len);
|
|
}
|
|
|
|
RCryptoPlugin r_crypto_plugin_sm4 = {
|
|
.type = R_CRYPTO_TYPE_ENCRYPT,
|
|
.meta = {
|
|
.name = "sm4-ecb",
|
|
.desc = "ShāngMì4 block cipher with Electronic Code Book mode",
|
|
.author = "Sylvain Pelissier",
|
|
.license = "LGPL-3.0-only",
|
|
},
|
|
.implements = "sm4-ecb",
|
|
.set_key = sm4_set_key,
|
|
.get_key_size = sm4_get_key_size,
|
|
.update = update,
|
|
.end = end
|
|
};
|
|
|
|
#ifndef R2_PLUGIN_INCORE
|
|
R_API RLibStruct radare_plugin = {
|
|
.type = R_LIB_TYPE_CRYPTO,
|
|
.data = &r_crypto_plugin_sm4,
|
|
.version = R2_VERSION
|
|
};
|
|
#endif
|