You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "xiaoxiang781216 (via GitHub)" <gi...@apache.org> on 2023/08/17 18:05:51 UTC
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #10249: Added NXP SE05x support (secure element)
xiaoxiang781216 commented on code in PR #10249:
URL: https://github.com/apache/nuttx/pull/10249#discussion_r1297561857
##########
drivers/crypto/Kconfig:
##########
@@ -74,3 +74,60 @@ config DEV_URANDOM_ARCH
endchoice # /dev/urandom algorithm
endif # DEV_URANDOM
+
+menuconfig DEV_SE05X
+ bool "Enable secure element (SE05X)"
+ depends on I2C
+ depends on CRYPTO
+ default n
+ ---help---
+ Enable support for /dev/se05x secure element provided by NXP SE050
+ or SE051
+
+if DEV_SE05X
+
+choice
+ prompt "Channel communication interface"
+ default DEV_SE05X_PLAIN
+ ---help---
+ Select authentication method
+
+config DEV_SE05X_SCP03
+ bool "SCP03 secure channel (TBI)"
+ select CRYPTO_RANDOM_POOL
+ select CRYPTO_AES
+
+config DEV_SE05X_PLAIN
+ bool "plain communication"
Review Comment:
ensure all Kconfig indent by tab not space
##########
include/nuttx/crypto/se05x.h:
##########
@@ -0,0 +1,164 @@
+/****************************************************************************
+ * include/nuttx/crypto/se05x.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.
+ *
+ ****************************************************************************/
+
+/* Copyright 2023 NXP */
+
+#ifndef __INCLUDE_NUTTX_CRYPTO_SE05X_H_
+#define __INCLUDE_NUTTX_CRYPTO_SE05X_H_
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+#include <nuttx/config.h>
+
+#ifdef CONFIG_DEV_SE05X
+
+#include <nuttx/fs/ioctl.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SE05X_MODULE_UNIQUE_ID_LEN 18
+
+#define SEIOC_GET_INFO _SEIOC(0x0000) /* Arg: se05x_info_s */
+#define SEIOC_GET_UID _SEIOC(0x0001) /* Arg: se05x_uid_s */
+#define SEIOC_GENERATE_KEYPAIR _SEIOC(0x0002)
+/* Arg: se05x_key_store_entry_t */
+#define SEIOC_SET_KEY _SEIOC(0x0003) /* Arg: se05x_key_transmission_s */
+#define SEIOC_SET_DATA _SEIOC(0x0004) /* Arg: se05x_key_transmission_s */
+#define SEIOC_GET_KEY _SEIOC(0x0005) /* Arg: se05x_key_transmission_s */
+#define SEIOC_GET_DATA _SEIOC(0x0006) /* Arg: se05x_key_transmission_s */
+#define SEIOC_DELETE_KEY _SEIOC(0x0007) /* Arg: uint32_t key_id */
+#define SEIOC_CREATE_SIGNATURE _SEIOC(0x0008) /* Arg: se05x_signature_s */
+#define SEIOC_VERIFY_SIGNATURE _SEIOC(0x0009) /* Arg: se05x_signature_s */
+#define SEIOC_DERIVE_SYMM_KEY _SEIOC(0x000A) /* Arg: se05x_derive_key_s */
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+typedef enum
+{
+ SE05X_ASYM_CIPHER_EC_NIST_P_256 = 0,
+} se05x_asym_cipher_type;
Review Comment:
```suggestion
} se05x_asym_cipher_type_e;
```
##########
include/nuttx/crypto/se05x.h:
##########
@@ -0,0 +1,164 @@
+/****************************************************************************
+ * include/nuttx/crypto/se05x.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.
+ *
+ ****************************************************************************/
+
+/* Copyright 2023 NXP */
+
+#ifndef __INCLUDE_NUTTX_CRYPTO_SE05X_H_
+#define __INCLUDE_NUTTX_CRYPTO_SE05X_H_
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+#include <nuttx/config.h>
+
+#ifdef CONFIG_DEV_SE05X
+
+#include <nuttx/fs/ioctl.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SE05X_MODULE_UNIQUE_ID_LEN 18
+
+#define SEIOC_GET_INFO _SEIOC(0x0000) /* Arg: se05x_info_s */
+#define SEIOC_GET_UID _SEIOC(0x0001) /* Arg: se05x_uid_s */
+#define SEIOC_GENERATE_KEYPAIR _SEIOC(0x0002)
+/* Arg: se05x_key_store_entry_t */
+#define SEIOC_SET_KEY _SEIOC(0x0003) /* Arg: se05x_key_transmission_s */
+#define SEIOC_SET_DATA _SEIOC(0x0004) /* Arg: se05x_key_transmission_s */
+#define SEIOC_GET_KEY _SEIOC(0x0005) /* Arg: se05x_key_transmission_s */
+#define SEIOC_GET_DATA _SEIOC(0x0006) /* Arg: se05x_key_transmission_s */
+#define SEIOC_DELETE_KEY _SEIOC(0x0007) /* Arg: uint32_t key_id */
+#define SEIOC_CREATE_SIGNATURE _SEIOC(0x0008) /* Arg: se05x_signature_s */
+#define SEIOC_VERIFY_SIGNATURE _SEIOC(0x0009) /* Arg: se05x_signature_s */
+#define SEIOC_DERIVE_SYMM_KEY _SEIOC(0x000A) /* Arg: se05x_derive_key_s */
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+typedef enum
+{
+ SE05X_ASYM_CIPHER_EC_NIST_P_256 = 0,
+} se05x_asym_cipher_type;
+
+typedef enum
+{
+ SE05X_ALGORITHM_NA = 0,
+ SE05X_ALGORITHM_PLAIN,
+ SE05X_ALGORITHM_SHA,
+ SE05X_ALGORITHM_SHA224,
+ SE05X_ALGORITHM_SHA256,
+ SE05X_ALGORITHM_SHA384,
+ SE05X_ALGORITHM_SHA512,
+ SE05X_ALGORITHM_SIZE,
+} se05x_algorithm;
Review Comment:
```suggestion
} se05x_algorithm_e;
```
##########
drivers/crypto/se05x_internal.h:
##########
@@ -0,0 +1,49 @@
+/****************************************************************************
+ * drivers/crypto/se05x_internal.h
Review Comment:
why not move into pnt folder
##########
drivers/crypto/pnt/Make.defs:
##########
@@ -0,0 +1,80 @@
+############################################################################
+# drivers/crypto/pnt/Make.defs
+#
+# 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.
+#
+############################################################################
+
+# Copyright 2023 NXP
+
+PNT_GIT_COMMIT_HASH = d7323c25d967edb0ff1957459586850f447eb8c5
+PNT_DOWNLOAD_URL = https://github.com/NXPPlugNTrust/nano-package/archive/$(PNT_GIT_COMMIT_HASH).zip
+PNT_WRAPPER_DIR = crypto/pnt
+PNT_NANO_ZIP = $(PNT_WRAPPER_DIR)/pnt_$(PNT_GIT_COMMIT_HASH).zip
+PNT_NANO_DIR = $(PNT_WRAPPER_DIR)/nano-package
+
+PNT_INCDIRS = \
+ -I. \
+ -I$(PNT_WRAPPER_DIR) \
+ -I$(PNT_NANO_DIR)/lib/apdu \
+ -I$(PNT_NANO_DIR)/lib/t1oi2c \
+
+CSRCS += \
+ $(PNT_WRAPPER_DIR)/pnt_se05x_api.c \
+ $(PNT_WRAPPER_DIR)/pnt_util.c \
+ $(PNT_WRAPPER_DIR)/sm_i2c.c \
+ $(PNT_WRAPPER_DIR)/sm_timer.c \
+ $(PNT_NANO_DIR)/lib/apdu/smCom.c \
+ $(PNT_NANO_DIR)/lib/apdu/se05x_tlv.c \
+ $(PNT_NANO_DIR)/lib/apdu/se05x_APDU_impl.c \
+ $(PNT_NANO_DIR)/lib/t1oi2c/phNxpEse_Api.c \
+ $(PNT_NANO_DIR)/lib/t1oi2c/phNxpEseProto7816_3.c \
+ $(PNT_NANO_DIR)/lib/t1oi2c/phNxpEsePal_i2c.c \
+
+ifeq ($(CONFIG_DEV_SE05X_SCP03),y)
+ PNT_INCDIRS += -I$(PNT_NANO_DIR)/lib/apdu/scp03
+ CFLAGS += DWITH_PLATFORM_SCP03
+ CSRCS += hcrypto.c $(PNT_NANO_DIR)/lib/apdu/scp03/se05x_scp03.c
+endif
+
+CFLAGS += $(PNT_INCDIRS) -DT1oI2C -DT1oI2C_UM11225 -DAX_EMBEDDED=0
+
+UNPACK ?= unzip -q -o
+
+PATCH ?= patch -p1
+
+$(PNT_NANO_ZIP):
+ @echo "Downloading: $(PNT_DOWNLOAD_URL)"
+ $(Q) curl -o $(PNT_NANO_ZIP) -L $(PNT_DOWNLOAD_URL)
+
+$(PNT_NANO_DIR): $(PNT_NANO_ZIP)
+ @echo "Unpacking: $(PNT_NANO_ZIP) -> $(PNT_NANO_DIR)"
+ $(Q) $(UNPACK) $(PNT_NANO_ZIP) -d $(PNT_WRAPPER_DIR)
+ $(call DELDIR, $(PNT_NANO_DIR))
+ $(Q) mv -T $(PNT_NANO_DIR)-$(PNT_GIT_COMMIT_HASH) $(PNT_NANO_DIR)
+ $(Q) $(foreach PATCH_FILE, $(sort $(wildcard $(PNT_WRAPPER_DIR)/*.patch)), $(PATCH) -d $(PNT_NANO_DIR) < $(PATCH_FILE);)
+
+context:: $(PNT_NANO_DIR)
+
+distclean::
+ $(call DELFILE, $(PNT_NANO_ZIP))
+ $(call DELDIR, $(PNT_NANO_DIR))
+
+# Include crypto device driver build support
+
+DEPPATH += --dep-path crypto
+VPATH += :crypto
Review Comment:
remove vpath for crypto
##########
drivers/crypto/pnt/Make.defs:
##########
@@ -0,0 +1,80 @@
+############################################################################
+# drivers/crypto/pnt/Make.defs
+#
+# 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.
+#
+############################################################################
+
+# Copyright 2023 NXP
+
+PNT_GIT_COMMIT_HASH = d7323c25d967edb0ff1957459586850f447eb8c5
+PNT_DOWNLOAD_URL = https://github.com/NXPPlugNTrust/nano-package/archive/$(PNT_GIT_COMMIT_HASH).zip
+PNT_WRAPPER_DIR = crypto/pnt
+PNT_NANO_ZIP = $(PNT_WRAPPER_DIR)/pnt_$(PNT_GIT_COMMIT_HASH).zip
+PNT_NANO_DIR = $(PNT_WRAPPER_DIR)/nano-package
+
+PNT_INCDIRS = \
+ -I. \
+ -I$(PNT_WRAPPER_DIR) \
+ -I$(PNT_NANO_DIR)/lib/apdu \
+ -I$(PNT_NANO_DIR)/lib/t1oi2c \
+
+CSRCS += \
+ $(PNT_WRAPPER_DIR)/pnt_se05x_api.c \
+ $(PNT_WRAPPER_DIR)/pnt_util.c \
+ $(PNT_WRAPPER_DIR)/sm_i2c.c \
+ $(PNT_WRAPPER_DIR)/sm_timer.c \
+ $(PNT_NANO_DIR)/lib/apdu/smCom.c \
+ $(PNT_NANO_DIR)/lib/apdu/se05x_tlv.c \
+ $(PNT_NANO_DIR)/lib/apdu/se05x_APDU_impl.c \
+ $(PNT_NANO_DIR)/lib/t1oi2c/phNxpEse_Api.c \
+ $(PNT_NANO_DIR)/lib/t1oi2c/phNxpEseProto7816_3.c \
+ $(PNT_NANO_DIR)/lib/t1oi2c/phNxpEsePal_i2c.c \
+
+ifeq ($(CONFIG_DEV_SE05X_SCP03),y)
+ PNT_INCDIRS += -I$(PNT_NANO_DIR)/lib/apdu/scp03
+ CFLAGS += DWITH_PLATFORM_SCP03
+ CSRCS += hcrypto.c $(PNT_NANO_DIR)/lib/apdu/scp03/se05x_scp03.c
+endif
+
+CFLAGS += $(PNT_INCDIRS) -DT1oI2C -DT1oI2C_UM11225 -DAX_EMBEDDED=0
+
+UNPACK ?= unzip -q -o
+
+PATCH ?= patch -p1
+
+$(PNT_NANO_ZIP):
+ @echo "Downloading: $(PNT_DOWNLOAD_URL)"
+ $(Q) curl -o $(PNT_NANO_ZIP) -L $(PNT_DOWNLOAD_URL)
+
+$(PNT_NANO_DIR): $(PNT_NANO_ZIP)
+ @echo "Unpacking: $(PNT_NANO_ZIP) -> $(PNT_NANO_DIR)"
+ $(Q) $(UNPACK) $(PNT_NANO_ZIP) -d $(PNT_WRAPPER_DIR)
+ $(call DELDIR, $(PNT_NANO_DIR))
+ $(Q) mv -T $(PNT_NANO_DIR)-$(PNT_GIT_COMMIT_HASH) $(PNT_NANO_DIR)
+ $(Q) $(foreach PATCH_FILE, $(sort $(wildcard $(PNT_WRAPPER_DIR)/*.patch)), $(PATCH) -d $(PNT_NANO_DIR) < $(PATCH_FILE);)
+
+context:: $(PNT_NANO_DIR)
+
+distclean::
+ $(call DELFILE, $(PNT_NANO_ZIP))
+ $(call DELDIR, $(PNT_NANO_DIR))
+
+# Include crypto device driver build support
+
+DEPPATH += --dep-path crypto
+VPATH += :crypto
+CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)crypto$(DELIM)pnt}
Review Comment:
```suggestion
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)drivers$(DELIM)crypto$(DELIM)pnt}
```
##########
drivers/crypto/pnt/Make.defs:
##########
@@ -0,0 +1,80 @@
+############################################################################
+# drivers/crypto/pnt/Make.defs
+#
+# 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.
+#
+############################################################################
+
+# Copyright 2023 NXP
+
+PNT_GIT_COMMIT_HASH = d7323c25d967edb0ff1957459586850f447eb8c5
+PNT_DOWNLOAD_URL = https://github.com/NXPPlugNTrust/nano-package/archive/$(PNT_GIT_COMMIT_HASH).zip
+PNT_WRAPPER_DIR = crypto/pnt
+PNT_NANO_ZIP = $(PNT_WRAPPER_DIR)/pnt_$(PNT_GIT_COMMIT_HASH).zip
+PNT_NANO_DIR = $(PNT_WRAPPER_DIR)/nano-package
+
+PNT_INCDIRS = \
+ -I. \
Review Comment:
align
##########
drivers/crypto/Make.defs:
##########
@@ -18,12 +18,19 @@
#
############################################################################
+# Copyright 2023 NXP
Review Comment:
remove
##########
drivers/crypto/Kconfig:
##########
@@ -74,3 +74,60 @@ config DEV_URANDOM_ARCH
endchoice # /dev/urandom algorithm
endif # DEV_URANDOM
+
+menuconfig DEV_SE05X
+ bool "Enable secure element (SE05X)"
+ depends on I2C
+ depends on CRYPTO
+ default n
+ ---help---
+ Enable support for /dev/se05x secure element provided by NXP SE050
+ or SE051
+
+if DEV_SE05X
+
+choice
+ prompt "Channel communication interface"
+ default DEV_SE05X_PLAIN
+ ---help---
+ Select authentication method
+
+config DEV_SE05X_SCP03
+ bool "SCP03 secure channel (TBI)"
+ select CRYPTO_RANDOM_POOL
Review Comment:
tab
##########
drivers/crypto/se05x.c:
##########
@@ -0,0 +1,266 @@
+/****************************************************************************
+ * drivers/crypto/se05x.c
Review Comment:
why not move into pnt folder
##########
drivers/crypto/se05x_internal.h:
##########
@@ -0,0 +1,49 @@
+/****************************************************************************
+ * drivers/crypto/se05x_internal.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.
+ *
+ ****************************************************************************/
+
+/* Copyright 2023 NXP */
+
+#ifndef __INCLUDE_NUTTX_DRIVERS_CRYPTO_SE05X_INTERNAL_H_
+#define __INCLUDE_NUTTX_DRIVERS_CRYPTO_SE05X_INTERNAL_H_
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <semaphore.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct i2c_master_s;
+struct pnt_handle;
+struct se05x_config_s;
+
+struct se05x_dev_s
+{
+ FAR struct se05x_config_s *config;
+ FAR struct i2c_master_s *i2c; /* I2C interface */
+ FAR struct pnt_handle *pnt;
+ sem_t mutex;
Review Comment:
```suggestion
mutex_t mutex;
```
and call mutex_xxx api
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org