From a585642060f802a0bae12d7cdef97735dc5b5b7c Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 29 Nov 2024 14:04:31 +0100 Subject: [PATCH] Add serialNumber(byte sn[], size_t length) --- src/SecureElement.cpp | 17 +++++++++++++++++ src/SecureElement.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/SecureElement.cpp b/src/SecureElement.cpp index 882bf4f..f0ccd96 100644 --- a/src/SecureElement.cpp +++ b/src/SecureElement.cpp @@ -60,3 +60,20 @@ int SecureElement::SHA256(const uint8_t *buffer, size_t size, uint8_t *digest) #endif } +int SecureElement::serialNumber(byte sn[], size_t length) +{ +#if defined(SECURE_ELEMENT_IS_SE050) + return _secureElement.serialNumber(sn, length); +#else + if (sn == nullptr || length < SE_SN_LENGTH) { + return 0; + } + uint8_t tmp[12]; + if (!_secureElement.serialNumber(tmp)) { + return 0; + } + memcpy(sn, tmp, SE_SN_LENGTH); + return 1; +#endif +} + diff --git a/src/SecureElement.h b/src/SecureElement.h index 94c5188..6dc8581 100644 --- a/src/SecureElement.h +++ b/src/SecureElement.h @@ -37,6 +37,14 @@ #define SE_SHA256_BUFFER_LENGTH 32 #define SE_CERT_BUFFER_LENGTH 1024 +#if defined(SECURE_ELEMENT_IS_SE050) + #define SE_SN_LENGTH SE05X_SN_LENGTH +#elif defined(SECURE_ELEMENT_IS_ECCX08) + #define SE_SN_LENGTH 9 +#elif defined(SECURE_ELEMENT_IS_SOFTSE) + #define SE_SN_LENGTH 6 +#endif + /****************************************************************************** * CLASS DECLARATION ******************************************************************************/ @@ -52,6 +60,7 @@ class SecureElement inline int serialNumber(byte sn[]) { return _secureElement.serialNumber(sn); } inline String serialNumber() { return _secureElement.serialNumber(); } + int serialNumber(byte sn[], size_t length); inline long random(long min, long max) { return this->_secureElement.random(min, max); }; inline long random(long max) { return this->_secureElement.random(max); };