Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crypto/mbedtls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ if(CONFIG_CRYPTO_MBEDTLS)
list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/bignum_alt.c)
endif()

if(CONFIG_MBEDTLS_PSA_CRYPTODEV_ALT)
list(APPEND CSRCS ${CMAKE_CURRENT_LIST_DIR}/source/psa_crypto_se_alt.c)
endif()

endif()

# ############################################################################
Expand Down
16 changes: 16 additions & 0 deletions crypto/mbedtls/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,20 @@ config MBEDTLS_PSA_CRYPTO_STORAGE_C
depends on MBEDTLS_PSA_CRYPTO_C
default !MBEDTLS_MINIMAL

config MBEDTLS_PSA_CRYPTO_SE_C
bool "Enable dynamic secure element support in the Platform Security Architecture cryptography API."
depends on MBEDTLS_PSA_CRYPTO_C && MBEDTLS_PSA_CRYPTO_STORAGE_C
default n

config MBEDTLS_PSA_ITS_FILE_C
bool "Enable the emulation of the Platform Security Architecture Internal Trusted Storage (PSA ITS) over files."
default !MBEDTLS_MINIMAL

config PSA_ITS_STORAGE_PREFIX
string "Allows storing the key files in a directory other than the current directory."
depends on MBEDTLS_PSA_ITS_FILE_C
default ""

config MBEDTLS_RIPEMD160_C
bool "Enable the RIPEMD-160 hash algorithm."
default !MBEDTLS_MINIMAL
Expand Down Expand Up @@ -743,6 +753,12 @@ config MBEDTLS_BIGNUM_ALT
select MBEDTLS_ALT
default n

config MBEDTLS_PSA_CRYPTODEV_ALT
bool "Enable secure element of Platform Security Architecture API alted by nuttx crypto"
depends on MBEDTLS_PSA_CRYPTO_SE_C
select MBEDTLS_ALT
default n

endif # CRYPTO_CRYPTODEV

config MBEDTLS_HAVE_TIME
Expand Down
4 changes: 4 additions & 0 deletions crypto/mbedtls/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ ifeq ($(CONFIG_MBEDTLS_BIGNUM_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/bignum_alt.c
endif

ifeq ($(CONFIG_MBEDTLS_PSA_CRYPTODEV_ALT),y)
CSRCS += $(APPDIR)/crypto/mbedtls/source/psa_crypto_se_alt.c
endif

endif

include $(APPDIR)/Application.mk
6 changes: 6 additions & 0 deletions crypto/mbedtls/include/dev_alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ typedef struct cryptodev_context_s
int fd;
struct session_op session;
struct crypt_op crypt;
#ifdef CONFIG_MBEDTLS_PSA_CRYPTODEV_ALT
struct crypt_kop cryptk;
#endif
}
cryptodev_context_t;

Expand All @@ -43,5 +46,8 @@ void cryptodev_free(FAR cryptodev_context_t *ctx);
int cryptodev_get_session(FAR cryptodev_context_t *ctx);
void cryptodev_free_session(FAR cryptodev_context_t *ctx);
int cryptodev_crypt(FAR cryptodev_context_t *ctx);
#ifdef CONFIG_MBEDTLS_PSA_CRYPTODEV_ALT
int cryptodev_cryptk(FAR cryptodev_context_t *ctx);
#endif

#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_DEV_ALT_H */
18 changes: 17 additions & 1 deletion crypto/mbedtls/include/mbedtls/mbedtls_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3710,7 +3710,9 @@
*
*/

/* #define MBEDTLS_PSA_CRYPTO_SE_C */
#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_SE_C
#define MBEDTLS_PSA_CRYPTO_SE_C
#endif

/**
* \def MBEDTLS_PSA_CRYPTO_STORAGE_C
Expand Down Expand Up @@ -3741,6 +3743,20 @@
#define MBEDTLS_PSA_ITS_FILE_C
#endif

/**
* \def PSA_ITS_STORAGE_PREFIX
*
* Allows storing the key files in a directory other than the current
* directory.
*
* Module: library/psa_its_file.c
*
* Requires: MBEDTLS_PSA_ITS_FILE_C
*/
#ifdef CONFIG_PSA_ITS_STORAGE_PREFIX
#define PSA_ITS_STORAGE_PREFIX CONFIG_PSA_ITS_STORAGE_PREFIX
#endif

/**
* \def MBEDTLS_RIPEMD160_C
*
Expand Down
52 changes: 52 additions & 0 deletions crypto/mbedtls/include/psa_crypto_se_alt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/****************************************************************************
* apps/crypto/mbedtls/include/psa_crypto_se_alt.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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_PSA_CRYPTO_SE_ALT_H
#define __APPS_CRYPTO_MBEDTLS_INCLUDE_PSA_CRYPTO_SE_ALT_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <psa/crypto.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/* The PSA key location served by the secure element driver registered by
* this module. Keys whose lifetime places them at this location are
* managed through the NuttX cryptodev key management interface.
*/

#define PSA_KEY_LOCATION_LOCAL_CRYPTODEV 1

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

/* Register the cryptodev secure element driver with the PSA core. Call
* this before psa_crypto_init().
*/

psa_status_t psa_alt_register_se_driver(void);

#endif /* __APPS_CRYPTO_MBEDTLS_INCLUDE_PSA_CRYPTO_SE_ALT_H */
10 changes: 10 additions & 0 deletions crypto/mbedtls/source/dev_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ int cryptodev_crypt(FAR cryptodev_context_t *ctx)
return ret < 0 ? -errno : ret;
}

#ifdef CONFIG_MBEDTLS_PSA_CRYPTODEV_ALT
int cryptodev_cryptk(FAR cryptodev_context_t *ctx)
{
int ret;

ret = ioctl(ctx->fd, CIOCKEY, &ctx->cryptk);
return ret < 0 ? -errno : (int)ctx->cryptk.crk_status;
}
#endif /* CONFIG_MBEDTLS_PSA_CRYPTODEV_ALT */

int cryptodev_clone(FAR cryptodev_context_t *dst,
FAR const cryptodev_context_t *src)
{
Expand Down
Loading
Loading