From cb3abc48d7ed6fa2ede573861c3507db0c54f839 Mon Sep 17 00:00:00 2001 From: makejian Date: Mon, 18 Sep 2023 20:50:57 +0800 Subject: [PATCH] crypto/cryptodev: expansion hash operation (1) remove size restriction for single hash operation (2) support hash operation to update uint32_t data Signed-off-by: makejian --- arch/risc-v/src/esp32c3/esp32c3_crypto.c | 9 ++++---- crypto/chachapoly.c | 2 +- crypto/cryptodev.c | 5 ----- crypto/gmac.c | 2 +- crypto/xform.c | 28 ++++++++++++------------ include/crypto/chachapoly.h | 2 +- include/crypto/gmac.h | 2 +- include/crypto/xform.h | 2 +- 8 files changed, 24 insertions(+), 28 deletions(-) diff --git a/arch/risc-v/src/esp32c3/esp32c3_crypto.c b/arch/risc-v/src/esp32c3/esp32c3_crypto.c index 71f3495d9b..de170596df 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_crypto.c +++ b/arch/risc-v/src/esp32c3/esp32c3_crypto.c @@ -23,6 +23,7 @@ ****************************************************************************/ #include +#include #include #include @@ -38,10 +39,10 @@ ****************************************************************************/ static void sha1_init(void *ctx); -static int sha1_update(void *ctx, const uint8_t *in, uint16_t len); +static int sha1_update(void *ctx, const uint8_t *in, size_t len); static void sha1_final(uint8_t *out, void *ctx); static void sha256_init(void *ctx); -static int sha256_update(void *ctx, const uint8_t *in, uint16_t len); +static int sha256_update(void *ctx, const uint8_t *in, size_t len); static void sha256_final(uint8_t *out, void *ctx); static int esp32c3_freesession(uint64_t tid); @@ -104,7 +105,7 @@ static void sha1_init(void *ctx) esp32c3_sha1_starts(ctx); } -static int sha1_update(void *ctx, const uint8_t *in, uint16_t len) +static int sha1_update(void *ctx, const uint8_t *in, size_t len) { return esp32c3_sha1_update((struct esp32c3_sha1_context_s *)ctx, (const unsigned char *)in, @@ -122,7 +123,7 @@ static void sha256_init(void *ctx) esp32c3_sha256_starts(ctx, false); } -static int sha256_update(void *ctx, const uint8_t *in, uint16_t len) +static int sha256_update(void *ctx, const uint8_t *in, size_t len) { return esp32c3_sha256_update((struct esp32c3_sha256_context_s *)ctx, (const unsigned char *)in, diff --git a/crypto/chachapoly.c b/crypto/chachapoly.c index 14602942d9..ec2e65cf4a 100644 --- a/crypto/chachapoly.c +++ b/crypto/chachapoly.c @@ -105,7 +105,7 @@ void chacha20_poly1305_reinit(FAR void *xctx, FAR const uint8_t *iv, } int chacha20_poly1305_update(FAR void *xctx, FAR const uint8_t *data, - uint16_t len) + size_t len) { static const unsigned char zeroes[POLY1305_BLOCK_LEN]; FAR CHACHA20_POLY1305_CTX *ctx = xctx; diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index 738c5984c4..aaa89a11ba 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -379,11 +379,6 @@ int cryptodev_op(FAR struct csession *cse, int error = OK; uint32_t hid; - if (cop->len > 64 * 1024 - 4) - { - return -E2BIG; - } - if (cse->txform) { if (cop->len == 0) diff --git a/crypto/gmac.c b/crypto/gmac.c index d05b601aa6..729b50b077 100644 --- a/crypto/gmac.c +++ b/crypto/gmac.c @@ -152,7 +152,7 @@ void aes_gmac_reinit(FAR void *xctx, FAR const uint8_t *iv, uint16_t ivlen) bcopy(iv, ctx->J + AESCTR_NONCESIZE, ivlen); } -int aes_gmac_update(FAR void *xctx, FAR const uint8_t *data, uint16_t len) +int aes_gmac_update(FAR void *xctx, FAR const uint8_t *data, size_t len) { FAR AES_GMAC_CTX *ctx = xctx; uint32_t blk[4] = diff --git a/crypto/xform.c b/crypto/xform.c index c2298aa6d2..4c5c74653f 100644 --- a/crypto/xform.c +++ b/crypto/xform.c @@ -117,13 +117,13 @@ void aes_xts_reinit(caddr_t, FAR uint8_t *); void aes_gcm_reinit(caddr_t, FAR uint8_t *); void aes_ofb_reinit(caddr_t, FAR uint8_t *); -int md5update_int(FAR void *, FAR const uint8_t *, uint16_t); -int sha1update_int(FAR void *, FAR const uint8_t *, uint16_t); -int rmd160update_int(FAR void *, FAR const uint8_t *, uint16_t); -int sha224update_int(FAR void *, FAR const uint8_t *, uint16_t); -int sha256update_int(FAR void *, FAR const uint8_t *, uint16_t); -int sha384update_int(FAR void *, FAR const uint8_t *, uint16_t); -int sha512update_int(FAR void *, FAR const uint8_t *, uint16_t); +int md5update_int(FAR void *, FAR const uint8_t *, size_t); +int sha1update_int(FAR void *, FAR const uint8_t *, size_t); +int rmd160update_int(FAR void *, FAR const uint8_t *, size_t); +int sha224update_int(FAR void *, FAR const uint8_t *, size_t); +int sha256update_int(FAR void *, FAR const uint8_t *, size_t); +int sha384update_int(FAR void *, FAR const uint8_t *, size_t); +int sha512update_int(FAR void *, FAR const uint8_t *, size_t); struct aes_ctr_ctx { @@ -789,43 +789,43 @@ void aes_cfb128_decrypt(caddr_t key, FAR uint8_t *data) /* And now for auth. */ -int rmd160update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int rmd160update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { rmd160update(ctx, buf, len); return 0; } -int md5update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int md5update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { md5update(ctx, buf, len); return 0; } -int sha1update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int sha1update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { sha1update(ctx, buf, len); return 0; } -int sha224update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int sha224update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { sha224update(ctx, buf, len); return 0; } -int sha256update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int sha256update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { sha256update(ctx, buf, len); return 0; } -int sha384update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int sha384update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { sha384update(ctx, buf, len); return 0; } -int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len) +int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len) { sha512update(ctx, buf, len); return 0; diff --git a/include/crypto/chachapoly.h b/include/crypto/chachapoly.h index 06bb72040f..af1d4dd03b 100644 --- a/include/crypto/chachapoly.h +++ b/include/crypto/chachapoly.h @@ -64,7 +64,7 @@ CHACHA20_POLY1305_CTX; void chacha20_poly1305_init(FAR void *); void chacha20_poly1305_setkey(FAR void *, FAR const uint8_t *, uint16_t); void chacha20_poly1305_reinit(FAR void *, FAR const uint8_t *, uint16_t); -int chacha20_poly1305_update(FAR void *, FAR const uint8_t *, uint16_t); +int chacha20_poly1305_update(FAR void *, FAR const uint8_t *, size_t); void chacha20_poly1305_final(FAR uint8_t *, FAR void *); /* WireGuard crypto */ diff --git a/include/crypto/gmac.h b/include/crypto/gmac.h index 9dee9fa251..623ee01fc4 100644 --- a/include/crypto/gmac.h +++ b/include/crypto/gmac.h @@ -51,7 +51,7 @@ extern void (*ghash_update)(FAR GHASH_CTX *, FAR uint8_t *, size_t); void aes_gmac_init(FAR void *); void aes_gmac_setkey(FAR void *, FAR const uint8_t *, uint16_t); void aes_gmac_reinit(FAR void *, FAR const uint8_t *, uint16_t); -int aes_gmac_update(FAR void *, FAR const uint8_t *, uint16_t); +int aes_gmac_update(FAR void *, FAR const uint8_t *, size_t); void aes_gmac_final(FAR uint8_t *, FAR void *); #endif /* __INCLUDE_CRYPTO_GMAC_H */ diff --git a/include/crypto/xform.h b/include/crypto/xform.h index df913e8071..c0e7a7dd6f 100644 --- a/include/crypto/xform.h +++ b/include/crypto/xform.h @@ -59,7 +59,7 @@ struct auth_hash CODE void (*init) (FAR void *); CODE void (*setkey) (FAR void *, FAR const uint8_t *, uint16_t); CODE void (*reinit) (FAR void *, FAR const uint8_t *, uint16_t); - CODE int (*update) (FAR void *, FAR const uint8_t *, uint16_t); + CODE int (*update) (FAR void *, FAR const uint8_t *, size_t); CODE void (*final) (FAR uint8_t *, FAR void *); };