Skip to content

Commit 83d3256

Browse files
ThePassionatexiaoxiang781216
authored andcommitted
mbedtls-alt/ripemd160: add ripemd160 alternative implementation
Signed-off-by: makejian <[email protected]>
1 parent 4fc6e7c commit 83d3256

File tree

5 files changed

+119
-2
lines changed

5 files changed

+119
-2
lines changed

crypto/mbedtls/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ config MBEDTLS_MD5_ALT
578578
select MBEDTLS_ALT
579579
default n
580580

581+
config MBEDTLS_RIPEMD160_ALT
582+
bool "Enable Mbedt TLS RIPEMD160 module alted by nuttx crypto"
583+
select MBEDTLS_ALT
584+
default n
585+
581586
config MBEDTLS_SHA1_ALT
582587
bool "Enable Mbedt TLS SHA1 module alted by nuttx crypto"
583588
select MBEDTLS_ALT

crypto/mbedtls/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ ifeq ($(CONFIG_MBEDTLS_MD5_ALT),y)
127127
CSRCS += $(APPDIR)/crypto/mbedtls/source/md5_alt.c
128128
endif
129129

130+
ifeq ($(CONFIG_MBEDTLS_RIPEMD160_ALT),y)
131+
CSRCS += $(APPDIR)/crypto/mbedtls/source/ripemd160_alt.c
132+
endif
133+
130134
ifeq ($(CONFIG_MBEDTLS_SHA1_ALT),y)
131135
CSRCS += $(APPDIR)/crypto/mbedtls/source/sha1_alt.c
132136
endif

crypto/mbedtls/include/mbedtls/mbedtls_config.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,11 @@
375375
#define MBEDTLS_MD5_ALT
376376
#endif
377377
/* #define MBEDTLS_POLY1305_ALT
378-
* #define MBEDTLS_RIPEMD160_ALT
379-
* #define MBEDTLS_RSA_ALT
378+
*/
379+
#ifdef CONFIG_MBEDTLS_RIPEMD160_ALT
380+
#define MBEDTLS_RIPEMD160_ALT
381+
#endif
382+
/* #define MBEDTLS_RSA_ALT
380383
*/
381384
#ifdef CONFIG_MBEDTLS_SHA1_ALT
382385
#define MBEDTLS_SHA1_ALT
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/****************************************************************************
2+
* apps/crypto/mbedtls/include/ripemd160_alt.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
****************************************************************************/
19+
20+
#ifndef __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H
21+
#define __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include "dev_alt.h"
28+
29+
#define mbedtls_ripemd160_context cryptodev_context_t
30+
31+
#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_RIPEMD160_ALT_H */

crypto/mbedtls/source/ripemd160_alt.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/****************************************************************************
2+
* apps/crypto/mbedtls/source/ripemd160_alt.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
****************************************************************************/
19+
20+
/****************************************************************************
21+
* Included Files
22+
****************************************************************************/
23+
24+
#include "mbedtls/ripemd160.h"
25+
26+
/****************************************************************************
27+
* Public Functions
28+
****************************************************************************/
29+
30+
void mbedtls_ripemd160_clone(FAR mbedtls_ripemd160_context *dst,
31+
FAR const mbedtls_ripemd160_context *src)
32+
{
33+
cryptodev_clone(dst, src);
34+
}
35+
36+
void mbedtls_ripemd160_init(FAR mbedtls_ripemd160_context *ctx)
37+
{
38+
cryptodev_init(ctx);
39+
}
40+
41+
void mbedtls_ripemd160_free(FAR mbedtls_ripemd160_context *ctx)
42+
{
43+
cryptodev_free(ctx);
44+
}
45+
46+
int mbedtls_ripemd160_starts(FAR mbedtls_ripemd160_context *ctx)
47+
{
48+
ctx->session.mac = CRYPTO_RIPEMD160;
49+
return cryptodev_get_session(ctx);
50+
}
51+
52+
int mbedtls_ripemd160_update(FAR mbedtls_ripemd160_context *ctx,
53+
FAR const unsigned char *input,
54+
size_t ilen)
55+
{
56+
ctx->crypt.op = COP_ENCRYPT;
57+
ctx->crypt.flags |= COP_FLAG_UPDATE;
58+
ctx->crypt.src = (caddr_t)input;
59+
ctx->crypt.len = ilen;
60+
return cryptodev_crypt(ctx);
61+
}
62+
63+
int mbedtls_ripemd160_finish(FAR mbedtls_ripemd160_context *ctx,
64+
unsigned char output[20])
65+
{
66+
int ret;
67+
68+
ctx->crypt.op = COP_ENCRYPT;
69+
ctx->crypt.flags = 0;
70+
ctx->crypt.mac = (caddr_t)output;
71+
ret = cryptodev_crypt(ctx);
72+
cryptodev_free_session(ctx);
73+
return ret;
74+
}

0 commit comments

Comments
 (0)