Skip to content

Commit 628d01d

Browse files
frkvrlubos
authored andcommitted
nrf_security: Enabling DHM for CryptoCell
-Enabling DHM_ALT to use CryptoCell runtime for DHM operations -Adding missing APIs in CryptoCell library copied from Mbed TLS in dhm_ext.c that is added to the build. ref: NCSDK-13744 Signed-off-by: Frank Audun Kvamtrø <[email protected]>
1 parent a317fe2 commit 628d01d

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

nrf_security/Kconfig.legacy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ config MBEDTLS_CHACHAPOLY_ALT
114114

115115
config MBEDTLS_DHM_ALT
116116
bool
117-
#depends on CC3XX_BACKEND || PSA_CRYPTO_DRIVER_CC3XX
118-
#default y - Currently not supported
117+
depends on CC3XX_BACKEND || PSA_CRYPTO_DRIVER_CC3XX
118+
default y
119119

120120
config MBEDTLS_ECP_ALT
121121
bool

nrf_security/src/legacy/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ if (CONFIG_OBERON_BACKEND OR PSA_CRYPTO_DRIVER_OBERON)
9494
else()
9595
list(APPEND src_crypto_legacy
9696
${ARM_MBEDTLS_PATH}/library/aes.c
97+
${CMAKE_CURRENT_LIST_DIR}/dhm_ext.c
9798
)
9899
endif()
99100

nrf_security/src/legacy/dhm_ext.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Diffie-Hellman-Merkle key exchange
3+
*
4+
* Copyright The Mbed TLS Contributors
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* 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.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
/*
20+
* The following sources were referenced in the design of this implementation
21+
* of the Diffie-Hellman-Merkle algorithm:
22+
*
23+
* [1] Handbook of Applied Cryptography - 1997, Chapter 12
24+
* Menezes, van Oorschot and Vanstone
25+
*
26+
*/
27+
28+
/* Copied from mbed TLS, missing in CryptoCell runtime library */
29+
30+
#include "common.h"
31+
32+
#if defined(MBEDTLS_DHM_C) && defined(CONFIG_CC3XX_BACKEND)
33+
34+
#include "mbedtls/dhm.h"
35+
#include "mbedtls/platform_util.h"
36+
#include "mbedtls/error.h"
37+
38+
#include <string.h>
39+
40+
#if defined(MBEDTLS_PEM_PARSE_C)
41+
#include "mbedtls/pem.h"
42+
#endif
43+
44+
#if defined(MBEDTLS_ASN1_PARSE_C)
45+
#include "mbedtls/asn1.h"
46+
#endif
47+
48+
#if defined(MBEDTLS_PLATFORM_C)
49+
#include "mbedtls/platform.h"
50+
#else
51+
#include <stdlib.h>
52+
#include <stdio.h>
53+
#define mbedtls_printf printf
54+
#define mbedtls_calloc calloc
55+
#define mbedtls_free free
56+
#endif
57+
58+
size_t mbedtls_dhm_get_bitlen( const mbedtls_dhm_context *ctx )
59+
{
60+
return( mbedtls_mpi_bitlen( &ctx->P ) );
61+
}
62+
63+
size_t mbedtls_dhm_get_len( const mbedtls_dhm_context *ctx )
64+
{
65+
return( mbedtls_mpi_size( &ctx->P ) );
66+
}
67+
68+
69+
#endif /* defined(MBEDTLS_DHM_C) && defined(CONFIG_CC3XX_BACKEND) */

0 commit comments

Comments
 (0)