mbedtls-alt/ripemd160: add ripemd160 alternative implementation

Signed-off-by: makejian <makejian@xiaomi.com>
This commit is contained in:
makejian 2023-10-25 15:56:32 +08:00 committed by Xiang Xiao
parent 4fc6e7ca0c
commit 83d3256f91
5 changed files with 119 additions and 2 deletions

View file

@ -578,6 +578,11 @@ config MBEDTLS_MD5_ALT
select MBEDTLS_ALT
default n
config MBEDTLS_RIPEMD160_ALT
bool "Enable Mbedt TLS RIPEMD160 module alted by nuttx crypto"
select MBEDTLS_ALT
default n
config MBEDTLS_SHA1_ALT
bool "Enable Mbedt TLS SHA1 module alted by nuttx crypto"
select MBEDTLS_ALT

View file

@ -127,6 +127,10 @@ ifeq ($(CONFIG_MBEDTLS_MD5_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/md5_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_RIPEMD160_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/ripemd160_alt.c
endif
ifeq ($(CONFIG_MBEDTLS_SHA1_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/sha1_alt.c
endif

View file

@ -375,8 +375,11 @@
#define MBEDTLS_MD5_ALT
#endif
/* #define MBEDTLS_POLY1305_ALT
* #define MBEDTLS_RIPEMD160_ALT
* #define MBEDTLS_RSA_ALT
*/
#ifdef CONFIG_MBEDTLS_RIPEMD160_ALT
#define MBEDTLS_RIPEMD160_ALT
#endif
/* #define MBEDTLS_RSA_ALT
*/
#ifdef CONFIG_MBEDTLS_SHA1_ALT
#define MBEDTLS_SHA1_ALT

View file

@ -0,0 +1,31 @@
/****************************************************************************
* apps/crypto/mbedtls/include/ripemd160_alt.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/
#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H
#define __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H
/****************************************************************************
* Included Files
****************************************************************************/
#include "dev_alt.h"
#define mbedtls_ripemd160_context cryptodev_context_t
#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H */

View file

@ -0,0 +1,74 @@
/****************************************************************************
* apps/crypto/mbedtls/source/ripemd160_alt.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "mbedtls/ripemd160.h"
/****************************************************************************
* Public Functions
****************************************************************************/
void mbedtls_ripemd160_clone(FAR mbedtls_ripemd160_context *dst,
FAR const mbedtls_ripemd160_context *src)
{
cryptodev_clone(dst, src);
}
void mbedtls_ripemd160_init(FAR mbedtls_ripemd160_context *ctx)
{
cryptodev_init(ctx);
}
void mbedtls_ripemd160_free(FAR mbedtls_ripemd160_context *ctx)
{
cryptodev_free(ctx);
}
int mbedtls_ripemd160_starts(FAR mbedtls_ripemd160_context *ctx)
{
ctx->session.mac = CRYPTO_RIPEMD160;
return cryptodev_get_session(ctx);
}
int mbedtls_ripemd160_update(FAR mbedtls_ripemd160_context *ctx,
FAR const unsigned char *input,
size_t ilen)
{
ctx->crypt.op = COP_ENCRYPT;
ctx->crypt.flags |= COP_FLAG_UPDATE;
ctx->crypt.src = (caddr_t)input;
ctx->crypt.len = ilen;
return cryptodev_crypt(ctx);
}
int mbedtls_ripemd160_finish(FAR mbedtls_ripemd160_context *ctx,
unsigned char output[20])
{
int ret;
ctx->crypt.op = COP_ENCRYPT;
ctx->crypt.flags = 0;
ctx->crypt.mac = (caddr_t)output;
ret = cryptodev_crypt(ctx);
cryptodev_free_session(ctx);
return ret;
}