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 <makejian@xiaomi.com>
This commit is contained in:
makejian 2023-09-18 20:50:57 +08:00 committed by Xiang Xiao
parent 7a417da65e
commit cb3abc48d7
8 changed files with 24 additions and 28 deletions

View File

@ -23,6 +23,7 @@
****************************************************************************/
#include <errno.h>
#include <stddef.h>
#include <sys/queue.h>
#include <crypto/cryptodev.h>
@ -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,

View File

@ -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;

View File

@ -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)

View File

@ -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] =

View File

@ -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;

View File

@ -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 */

View File

@ -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 */

View File

@ -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 *);
};