arduino-libraries/Arduino_SecureElement

`SecureElement::random` always returns 0

StefanaHanc opened this issue · 8 comments

I put this code in Arduino IDE. I have an Arduino Portenta H7.

/*
  secureElement Random Number

  This sketch uses the ECC508/ECC608 or SE050 to generate a random number
  every second and print it to the Serial Monitor

  Circuit:
   - A board equipped with ECC508 or ECC608 or SE050 chip

  This example code is in the public domain.
*/

#include <Arduino_SecureElement.h>

SecureElement secureElement;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!secureElement.begin()) {
    Serial.println("Failed to communicate with ECC508/ECC608!");
    while (1);
  }

  if (!secureElement.locked()) {
    Serial.println("The ECC508/ECC608 is not locked!");
  }
}

void loop() {
  Serial.print("Random number = ");
  Serial.println(secureElement.random(65535));

  delay(1000);
}

It always generates 0 instead of random numbers.

I see the message printed in Serial Monitor:

The ECC508/ECC608 is not locked!

Hi @StefanaHanc
ECC508/608 needs to be locked otherwise it cannot be used to generate a random number. You can use this example sketch to lock it and then Random number generation should work.

Hi @pennam ,

Thanks, now it works ! :)
Another question to configure a portenta H7 that has ECC508/608 as default and I want to use NXP, how could I do this?
I configured in SecureElementConfig.h to have ARDUINO_PORTENTA_H7_M7 at
SECURE_ELEMENT_IS_SE050 but it gives me the error:

 ex_sss_boot.h: No such file or directory,

Should I do anything else?

Here is SecureElementConfig.h with my change

#ifndef SECURE_ELEMENT_CONFIG_H_
#define SECURE_ELEMENT_CONFIG_H_

#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || \
  defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
  defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKR1000) || \
  defined(ARDUINO_SAMD_MKRNB1500) || \
  defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_OPTA) || \
  defined(ARDUINO_GIGA)
  #define SECURE_ELEMENT_IS_ECCX08
#endif

#if defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7)
  #define SECURE_ELEMENT_IS_SE050
#endif

#if defined(ARDUINO_UNOR4_WIFI)
  #define SECURE_ELEMENT_IS_SOFTSE
#endif

Hi @StefanaHanc,
what you ask is not possible out of the box, what SE050 features do you want to use on Portenta H7 ?

@StefanaHanc please take a look at this draft PR #12

using it should allow you to use SE050 on PortentaH7, you will also need this additional library not yet published on library manager https://github.com/pennam/Arduino_PortentaH7_SE05X

Hello @pennam
Thank you for the answer. I use portenta H7 for didactic purposes for my bachelor's thesis and I want to have access to ATTEC and NXP.I don't know how I could configure it to use NXP instead of ATTEC for portenta H7. Any helpful materials are welcome. I want to test the NXP part with all the functionalities it supports.Thank You !

Hello @pennam

I think the given library is private and I don't have access to it https://github.com/pennam/Arduino_PortentaH7_SE05X (Error 404).
Can you suggest me another library?

@StefanaHanc the repo is public now

Hello @pennam
Thank you very much, now it works!