Implement the secure element driver registration function
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index 61bc13d..78c233a 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -53,6 +53,7 @@
platform_util.c
poly1305.c
psa_crypto.c
+ psa_crypto_se.c
psa_crypto_slot_management.c
psa_crypto_storage.c
psa_its_file.c
diff --git a/library/Makefile b/library/Makefile
index 921b68e..2b979b4 100644
--- a/library/Makefile
+++ b/library/Makefile
@@ -80,7 +80,7 @@
pk.o pk_wrap.o pkcs12.o \
pkcs5.o pkparse.o pkwrite.o \
platform.o platform_util.o poly1305.o \
- psa_crypto.o \
+ psa_crypto.o psa_crypto_se.o \
psa_crypto_slot_management.o \
psa_crypto_storage.o \
psa_its_file.o \
diff --git a/library/psa_crypto_se.c b/library/psa_crypto_se.c
new file mode 100644
index 0000000..33d0da8
--- /dev/null
+++ b/library/psa_crypto_se.c
@@ -0,0 +1,72 @@
+/*
+ * PSA crypto support for secure element drivers
+ */
+/* Copyright (C) 2019, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "mbedtls/config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
+#if defined(MBEDTLS_PSA_CRYPTO_C)
+
+#include "psa_crypto_se.h"
+
+typedef struct
+{
+ psa_key_lifetime_t lifetime;
+ const psa_drv_se_t *methods;
+} method_table_entry_t;
+
+static method_table_entry_t driver_table[PSA_MAX_SE_DRIVERS];
+
+psa_status_t psa_register_se_driver(
+ psa_key_lifetime_t lifetime,
+ const psa_drv_se_t *methods)
+{
+ size_t i;
+
+ if( methods->hal_version != PSA_DRV_SE_HAL_VERSION )
+ return( PSA_ERROR_NOT_SUPPORTED );
+ if( lifetime == PSA_KEY_LIFETIME_VOLATILE ||
+ lifetime == PSA_KEY_LIFETIME_PERSISTENT )
+ {
+ return( PSA_ERROR_INVALID_ARGUMENT );
+ }
+
+ for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ )
+ {
+ if( driver_table[i].lifetime == 0 )
+ break;
+ /* Check that lifetime isn't already in use up to the first free
+ * entry. Since entries are created in order and never deleted,
+ * there can't be a used entry after the first free entry. */
+ if( driver_table[i].lifetime == lifetime )
+ return( PSA_ERROR_ALREADY_EXISTS );
+ }
+ if( i == PSA_MAX_SE_DRIVERS )
+ return( PSA_ERROR_INSUFFICIENT_MEMORY );
+
+ driver_table[i].lifetime = lifetime;
+ driver_table[i].methods = methods;
+ return( PSA_SUCCESS );
+}
+
+#endif /* MBEDTLS_PSA_CRYPTO_C */
diff --git a/library/psa_crypto_se.h b/library/psa_crypto_se.h
new file mode 100644
index 0000000..1085f48
--- /dev/null
+++ b/library/psa_crypto_se.h
@@ -0,0 +1,37 @@
+/*
+ * PSA crypto support for secure element drivers
+ */
+/* Copyright (C) 2019, ARM Limited, All Rights Reserved
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed 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.
+ *
+ * This file is part of Mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef PSA_CRYPTO_SE_H
+#define PSA_CRYPTO_SE_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+#include "mbedtls/config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
+#include "psa/crypto.h"
+#include "psa/crypto_se_driver.h"
+
+/** The maximum number of registered secure element driver lifetimes. */
+#define PSA_MAX_SE_DRIVERS 4
+
+#endif /* PSA_CRYPTO_SE_H */
diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj
index 07c80e8..2034a84 100644
--- a/visualc/VS2010/mbedTLS.vcxproj
+++ b/visualc/VS2010/mbedTLS.vcxproj
@@ -225,6 +225,7 @@
<ClInclude Include="..\..\library/psa_crypto_core.h" />
<ClInclude Include="..\..\library/psa_crypto_invasive.h" />
<ClInclude Include="..\..\library/psa_crypto_its.h" />
+ <ClInclude Include="..\..\library/psa_crypto_se.h" />
<ClInclude Include="..\..\library/psa_crypto_service_integration.h" />
<ClInclude Include="..\..\library/psa_crypto_slot_management.h" />
<ClInclude Include="..\..\library/psa_crypto_storage.h" />
@@ -281,6 +282,7 @@
<ClCompile Include="..\..\library\platform_util.c" />
<ClCompile Include="..\..\library\poly1305.c" />
<ClCompile Include="..\..\library\psa_crypto.c" />
+ <ClCompile Include="..\..\library\psa_crypto_se.c" />
<ClCompile Include="..\..\library\psa_crypto_slot_management.c" />
<ClCompile Include="..\..\library\psa_crypto_storage.c" />
<ClCompile Include="..\..\library\psa_its_file.c" />