Skip to content

Commit cb3abc4

Browse files
ThePassionatexiaoxiang781216
authored andcommitted
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>
1 parent 7a417da commit cb3abc4

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

arch/risc-v/src/esp32c3/esp32c3_crypto.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
****************************************************************************/
2424

2525
#include <errno.h>
26+
#include <stddef.h>
2627
#include <sys/queue.h>
2728

2829
#include <crypto/cryptodev.h>
@@ -38,10 +39,10 @@
3839
****************************************************************************/
3940

4041
static void sha1_init(void *ctx);
41-
static int sha1_update(void *ctx, const uint8_t *in, uint16_t len);
42+
static int sha1_update(void *ctx, const uint8_t *in, size_t len);
4243
static void sha1_final(uint8_t *out, void *ctx);
4344
static void sha256_init(void *ctx);
44-
static int sha256_update(void *ctx, const uint8_t *in, uint16_t len);
45+
static int sha256_update(void *ctx, const uint8_t *in, size_t len);
4546
static void sha256_final(uint8_t *out, void *ctx);
4647
static int esp32c3_freesession(uint64_t tid);
4748

@@ -104,7 +105,7 @@ static void sha1_init(void *ctx)
104105
esp32c3_sha1_starts(ctx);
105106
}
106107

107-
static int sha1_update(void *ctx, const uint8_t *in, uint16_t len)
108+
static int sha1_update(void *ctx, const uint8_t *in, size_t len)
108109
{
109110
return esp32c3_sha1_update((struct esp32c3_sha1_context_s *)ctx,
110111
(const unsigned char *)in,
@@ -122,7 +123,7 @@ static void sha256_init(void *ctx)
122123
esp32c3_sha256_starts(ctx, false);
123124
}
124125

125-
static int sha256_update(void *ctx, const uint8_t *in, uint16_t len)
126+
static int sha256_update(void *ctx, const uint8_t *in, size_t len)
126127
{
127128
return esp32c3_sha256_update((struct esp32c3_sha256_context_s *)ctx,
128129
(const unsigned char *)in,

crypto/chachapoly.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void chacha20_poly1305_reinit(FAR void *xctx, FAR const uint8_t *iv,
105105
}
106106

107107
int chacha20_poly1305_update(FAR void *xctx, FAR const uint8_t *data,
108-
uint16_t len)
108+
size_t len)
109109
{
110110
static const unsigned char zeroes[POLY1305_BLOCK_LEN];
111111
FAR CHACHA20_POLY1305_CTX *ctx = xctx;

crypto/cryptodev.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,6 @@ int cryptodev_op(FAR struct csession *cse,
379379
int error = OK;
380380
uint32_t hid;
381381

382-
if (cop->len > 64 * 1024 - 4)
383-
{
384-
return -E2BIG;
385-
}
386-
387382
if (cse->txform)
388383
{
389384
if (cop->len == 0)

crypto/gmac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void aes_gmac_reinit(FAR void *xctx, FAR const uint8_t *iv, uint16_t ivlen)
152152
bcopy(iv, ctx->J + AESCTR_NONCESIZE, ivlen);
153153
}
154154

155-
int aes_gmac_update(FAR void *xctx, FAR const uint8_t *data, uint16_t len)
155+
int aes_gmac_update(FAR void *xctx, FAR const uint8_t *data, size_t len)
156156
{
157157
FAR AES_GMAC_CTX *ctx = xctx;
158158
uint32_t blk[4] =

crypto/xform.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ void aes_xts_reinit(caddr_t, FAR uint8_t *);
117117
void aes_gcm_reinit(caddr_t, FAR uint8_t *);
118118
void aes_ofb_reinit(caddr_t, FAR uint8_t *);
119119

120-
int md5update_int(FAR void *, FAR const uint8_t *, uint16_t);
121-
int sha1update_int(FAR void *, FAR const uint8_t *, uint16_t);
122-
int rmd160update_int(FAR void *, FAR const uint8_t *, uint16_t);
123-
int sha224update_int(FAR void *, FAR const uint8_t *, uint16_t);
124-
int sha256update_int(FAR void *, FAR const uint8_t *, uint16_t);
125-
int sha384update_int(FAR void *, FAR const uint8_t *, uint16_t);
126-
int sha512update_int(FAR void *, FAR const uint8_t *, uint16_t);
120+
int md5update_int(FAR void *, FAR const uint8_t *, size_t);
121+
int sha1update_int(FAR void *, FAR const uint8_t *, size_t);
122+
int rmd160update_int(FAR void *, FAR const uint8_t *, size_t);
123+
int sha224update_int(FAR void *, FAR const uint8_t *, size_t);
124+
int sha256update_int(FAR void *, FAR const uint8_t *, size_t);
125+
int sha384update_int(FAR void *, FAR const uint8_t *, size_t);
126+
int sha512update_int(FAR void *, FAR const uint8_t *, size_t);
127127

128128
struct aes_ctr_ctx
129129
{
@@ -789,43 +789,43 @@ void aes_cfb128_decrypt(caddr_t key, FAR uint8_t *data)
789789

790790
/* And now for auth. */
791791

792-
int rmd160update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
792+
int rmd160update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
793793
{
794794
rmd160update(ctx, buf, len);
795795
return 0;
796796
}
797797

798-
int md5update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
798+
int md5update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
799799
{
800800
md5update(ctx, buf, len);
801801
return 0;
802802
}
803803

804-
int sha1update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
804+
int sha1update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
805805
{
806806
sha1update(ctx, buf, len);
807807
return 0;
808808
}
809809

810-
int sha224update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
810+
int sha224update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
811811
{
812812
sha224update(ctx, buf, len);
813813
return 0;
814814
}
815815

816-
int sha256update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
816+
int sha256update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
817817
{
818818
sha256update(ctx, buf, len);
819819
return 0;
820820
}
821821

822-
int sha384update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
822+
int sha384update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
823823
{
824824
sha384update(ctx, buf, len);
825825
return 0;
826826
}
827827

828-
int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, uint16_t len)
828+
int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
829829
{
830830
sha512update(ctx, buf, len);
831831
return 0;

include/crypto/chachapoly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CHACHA20_POLY1305_CTX;
6464
void chacha20_poly1305_init(FAR void *);
6565
void chacha20_poly1305_setkey(FAR void *, FAR const uint8_t *, uint16_t);
6666
void chacha20_poly1305_reinit(FAR void *, FAR const uint8_t *, uint16_t);
67-
int chacha20_poly1305_update(FAR void *, FAR const uint8_t *, uint16_t);
67+
int chacha20_poly1305_update(FAR void *, FAR const uint8_t *, size_t);
6868
void chacha20_poly1305_final(FAR uint8_t *, FAR void *);
6969

7070
/* WireGuard crypto */

include/crypto/gmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern void (*ghash_update)(FAR GHASH_CTX *, FAR uint8_t *, size_t);
5151
void aes_gmac_init(FAR void *);
5252
void aes_gmac_setkey(FAR void *, FAR const uint8_t *, uint16_t);
5353
void aes_gmac_reinit(FAR void *, FAR const uint8_t *, uint16_t);
54-
int aes_gmac_update(FAR void *, FAR const uint8_t *, uint16_t);
54+
int aes_gmac_update(FAR void *, FAR const uint8_t *, size_t);
5555
void aes_gmac_final(FAR uint8_t *, FAR void *);
5656

5757
#endif /* __INCLUDE_CRYPTO_GMAC_H */

include/crypto/xform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct auth_hash
5959
CODE void (*init) (FAR void *);
6060
CODE void (*setkey) (FAR void *, FAR const uint8_t *, uint16_t);
6161
CODE void (*reinit) (FAR void *, FAR const uint8_t *, uint16_t);
62-
CODE int (*update) (FAR void *, FAR const uint8_t *, uint16_t);
62+
CODE int (*update) (FAR void *, FAR const uint8_t *, size_t);
6363
CODE void (*final) (FAR uint8_t *, FAR void *);
6464
};
6565

0 commit comments

Comments
 (0)