crypto: export crc32 from /dev/crypto
Signed-off-by: makejian <makejian@xiaomi.com>
This commit is contained in:
parent
963c5e8e52
commit
28974b8a21
5 changed files with 50 additions and 2 deletions
|
@ -255,6 +255,7 @@ static int cryptof_ioctl(FAR struct file *filep,
|
|||
case CRYPTO_SHA2_256:
|
||||
case CRYPTO_SHA2_384:
|
||||
case CRYPTO_SHA2_512:
|
||||
case CRYPTO_CRC32:
|
||||
thash = true;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -835,6 +835,10 @@ int swcr_newsession(FAR uint32_t *sid, FAR struct cryptoini *cri)
|
|||
axf = &auth_hash_poly1305;
|
||||
goto auth4common;
|
||||
|
||||
case CRYPTO_CRC32:
|
||||
axf = &auth_hash_crc32;
|
||||
goto auth4common;
|
||||
|
||||
case CRYPTO_CHACHA20_POLY1305_MAC:
|
||||
axf = &auth_hash_chacha20_poly1305;
|
||||
|
||||
|
@ -956,6 +960,7 @@ int swcr_freesession(uint64_t tid)
|
|||
case CRYPTO_SHA2_256:
|
||||
case CRYPTO_SHA2_384:
|
||||
case CRYPTO_SHA2_512:
|
||||
case CRYPTO_CRC32:
|
||||
axf = swd->sw_axf;
|
||||
|
||||
if (swd->sw_ictx)
|
||||
|
@ -1090,6 +1095,7 @@ int swcr_process(struct cryptop *crp)
|
|||
case CRYPTO_SHA2_256:
|
||||
case CRYPTO_SHA2_384:
|
||||
case CRYPTO_SHA2_512:
|
||||
case CRYPTO_CRC32:
|
||||
if ((crp->crp_etype = swcr_hash(crp, crd, sw,
|
||||
crp->crp_buf)) != 0)
|
||||
{
|
||||
|
@ -1230,6 +1236,7 @@ void swcr_init(void)
|
|||
algs[CRYPTO_SHA2_256] = CRYPTO_ALG_FLAG_SUPPORTED;
|
||||
algs[CRYPTO_SHA2_384] = CRYPTO_ALG_FLAG_SUPPORTED;
|
||||
algs[CRYPTO_SHA2_512] = CRYPTO_ALG_FLAG_SUPPORTED;
|
||||
algs[CRYPTO_CRC32] = CRYPTO_ALG_FLAG_SUPPORTED;
|
||||
algs[CRYPTO_ESN] = CRYPTO_ALG_FLAG_SUPPORTED;
|
||||
|
||||
crypto_register(swcr_id, algs, swcr_newsession,
|
||||
|
|
|
@ -72,9 +72,16 @@
|
|||
#include <crypto/gmac.h>
|
||||
#include <crypto/chachapoly.h>
|
||||
#include <crypto/poly1305.h>
|
||||
#include <nuttx/crc32.h>
|
||||
|
||||
#include "des_locl.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CRC32_XOR_VALUE 0xFFFFFFFFUL
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -129,6 +136,9 @@ 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);
|
||||
void crc32setkey(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
int crc32update(FAR void *, FAR const uint8_t *, size_t);
|
||||
void crc32final(FAR uint8_t *, FAR void *);
|
||||
|
||||
struct aes_ctr_ctx
|
||||
{
|
||||
|
@ -457,6 +467,13 @@ const struct auth_hash auth_hash_sha2_512 =
|
|||
(void (*)(FAR uint8_t *, FAR void *)) sha512final
|
||||
};
|
||||
|
||||
const struct auth_hash auth_hash_crc32 =
|
||||
{
|
||||
CRYPTO_CRC32, "CRC32",
|
||||
0, 32, 0, sizeof(uint32_t), 1,
|
||||
null_init, crc32setkey, NULL, crc32update, crc32final
|
||||
};
|
||||
|
||||
/* Encryption wrapper routines. */
|
||||
|
||||
void des3_encrypt(caddr_t key, FAR uint8_t *blk)
|
||||
|
@ -879,3 +896,24 @@ int sha512update_int(FAR void *ctx, FAR const uint8_t *buf, size_t len)
|
|||
sha512update(ctx, buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void crc32setkey(FAR void *ctx, FAR const uint8_t *key, uint16_t len)
|
||||
{
|
||||
FAR uint32_t *val = (FAR uint32_t *)key;
|
||||
uint32_t tmp = (*val) ^ CRC32_XOR_VALUE;
|
||||
memcpy(ctx, &tmp, len);
|
||||
}
|
||||
|
||||
int crc32update(FAR void *ctx, FAR const uint8_t *buf, size_t len)
|
||||
{
|
||||
FAR uint32_t *startval = (FAR uint32_t *)ctx;
|
||||
*startval = crc32part(buf, len, *startval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void crc32final(FAR uint8_t *digest, FAR void *ctx)
|
||||
{
|
||||
FAR uint32_t *val = (FAR uint32_t *)ctx;
|
||||
uint32_t result = (*val) ^ CRC32_XOR_VALUE;
|
||||
memcpy(digest, &result, sizeof(uint32_t));
|
||||
}
|
||||
|
|
|
@ -124,8 +124,9 @@
|
|||
#define CRYPTO_SHA2_256 31
|
||||
#define CRYPTO_SHA2_384 32
|
||||
#define CRYPTO_SHA2_512 33
|
||||
#define CRYPTO_ESN 34 /* Support for Extended Sequence Numbers */
|
||||
#define CRYPTO_ALGORITHM_MAX 34 /* Keep updated */
|
||||
#define CRYPTO_CRC32 34
|
||||
#define CRYPTO_ESN 35 /* Support for Extended Sequence Numbers */
|
||||
#define CRYPTO_ALGORITHM_MAX 35 /* Keep updated */
|
||||
|
||||
/* Algorithm flags */
|
||||
|
||||
|
|
|
@ -128,5 +128,6 @@ extern const struct auth_hash auth_hash_sha2_224;
|
|||
extern const struct auth_hash auth_hash_sha2_256;
|
||||
extern const struct auth_hash auth_hash_sha2_384;
|
||||
extern const struct auth_hash auth_hash_sha2_512;
|
||||
extern const struct auth_hash auth_hash_crc32;
|
||||
|
||||
#endif /* __INCLUDE_CRYPTO_XFORM_H */
|
||||
|
|
Loading…
Reference in a new issue