From 8628cc9c0e567758489e2a8ec8ae5a816d4ecf2e Mon Sep 17 00:00:00 2001 From: makejian Date: Wed, 25 Oct 2023 16:00:13 +0800 Subject: [PATCH] crypto/ripemd160: export ripemd160 algorithm via /dev/crypto Signed-off-by: makejian --- crypto/cryptodev.c | 1 + crypto/cryptosoft.c | 6 ++++++ crypto/xform.c | 9 +++++++++ include/crypto/cryptodev.h | 15 ++++++++------- include/crypto/xform.h | 1 + 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index 4c57a9392d..4fab9c1778 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -248,6 +248,7 @@ static int cryptof_ioctl(FAR struct file *filep, case CRYPTO_SHA2_512_HMAC: case CRYPTO_AES_128_GMAC: case CRYPTO_MD5: + case CRYPTO_RIPEMD160: case CRYPTO_SHA1: case CRYPTO_SHA2_224: case CRYPTO_SHA2_256: diff --git a/crypto/cryptosoft.c b/crypto/cryptosoft.c index 2fe76bd0d0..ed36542c52 100644 --- a/crypto/cryptosoft.c +++ b/crypto/cryptosoft.c @@ -776,6 +776,9 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri) case CRYPTO_MD5: axf = &auth_hash_md5; goto auth3common; + case CRYPTO_RIPEMD160: + axf = &auth_hash_ripemd_160; + goto auth3common; case CRYPTO_SHA1: axf = &auth_hash_sha1; goto auth3common; @@ -941,6 +944,7 @@ int swcr_freesession(uint64_t tid) case CRYPTO_AES_256_GMAC: case CRYPTO_CHACHA20_POLY1305_MAC: case CRYPTO_MD5: + case CRYPTO_RIPEMD160: case CRYPTO_SHA1: case CRYPTO_SHA2_224: case CRYPTO_SHA2_256: @@ -1073,6 +1077,7 @@ int swcr_process(struct cryptop *crp) break; case CRYPTO_MD5: + case CRYPTO_RIPEMD160: case CRYPTO_SHA1: case CRYPTO_SHA2_224: case CRYPTO_SHA2_256: @@ -1211,6 +1216,7 @@ void swcr_init(void) algs[CRYPTO_CHACHA20_POLY1305] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_CHACHA20_POLY1305_MAC] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_MD5] = CRYPTO_ALG_FLAG_SUPPORTED; + algs[CRYPTO_RIPEMD160] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_SHA1] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_SHA2_224] = CRYPTO_ALG_FLAG_SUPPORTED; algs[CRYPTO_SHA2_256] = CRYPTO_ALG_FLAG_SUPPORTED; diff --git a/crypto/xform.c b/crypto/xform.c index 4c5c74653f..b16bb989fd 100644 --- a/crypto/xform.c +++ b/crypto/xform.c @@ -389,6 +389,15 @@ const struct auth_hash auth_hash_md5 = (void (*) (FAR uint8_t *, FAR void *)) md5final }; +const struct auth_hash auth_hash_ripemd_160 = +{ + CRYPTO_RIPEMD160, "RIPEMD160", + 0, 20, 20, sizeof(RMD160_CTX), HMAC_RIPEMD160_BLOCK_LEN, + (void (*) (FAR void *)) rmd160init, NULL, NULL, + rmd160update_int, + (void (*) (FAR uint8_t *, FAR void *)) rmd160final +}; + const struct auth_hash auth_hash_sha1 = { CRYPTO_SHA1, "SHA1", diff --git a/include/crypto/cryptodev.h b/include/crypto/cryptodev.h index 3fe12b14a5..7d18402182 100644 --- a/include/crypto/cryptodev.h +++ b/include/crypto/cryptodev.h @@ -117,13 +117,14 @@ #define CRYPTO_CHACHA20_POLY1305 24 #define CRYPTO_CHACHA20_POLY1305_MAC 25 #define CRYPTO_MD5 26 -#define CRYPTO_SHA1 27 -#define CRYPTO_SHA2_224 28 -#define CRYPTO_SHA2_256 29 -#define CRYPTO_SHA2_384 30 -#define CRYPTO_SHA2_512 31 -#define CRYPTO_ESN 32 /* Support for Extended Sequence Numbers */ -#define CRYPTO_ALGORITHM_MAX 32 /* Keep updated */ +#define CRYPTO_RIPEMD160 27 +#define CRYPTO_SHA1 28 +#define CRYPTO_SHA2_224 29 +#define CRYPTO_SHA2_256 30 +#define CRYPTO_SHA2_384 31 +#define CRYPTO_SHA2_512 32 +#define CRYPTO_ESN 33 /* Support for Extended Sequence Numbers */ +#define CRYPTO_ALGORITHM_MAX 33 /* Keep updated */ /* Algorithm flags */ diff --git a/include/crypto/xform.h b/include/crypto/xform.h index c0e7a7dd6f..196057ea13 100644 --- a/include/crypto/xform.h +++ b/include/crypto/xform.h @@ -121,6 +121,7 @@ extern const struct auth_hash auth_hash_gmac_aes_192; extern const struct auth_hash auth_hash_gmac_aes_256; extern const struct auth_hash auth_hash_chacha20_poly1305; extern const struct auth_hash auth_hash_md5; +extern const struct auth_hash auth_hash_ripemd_160; extern const struct auth_hash auth_hash_sha1; extern const struct auth_hash auth_hash_sha2_224; extern const struct auth_hash auth_hash_sha2_256;