Skip to content

SecureElement::random always returns 0 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StefanaHanc opened this issue Feb 29, 2024 · 8 comments · Fixed by #10
Closed

SecureElement::random always returns 0 #9

StefanaHanc opened this issue Feb 29, 2024 · 8 comments · Fixed by #10
Labels
conclusion: resolved Issue was resolved topic: documentation Related to documentation for the project type: enhancement Proposed improvement

Comments

@StefanaHanc
Copy link

StefanaHanc commented Feb 29, 2024

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!
@pennam
Copy link
Contributor

pennam commented Feb 29, 2024

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.

@per1234 per1234 changed the title Random Generation SecureElement::random always returns 0 Mar 1, 2024
@per1234 per1234 added topic: documentation Related to documentation for the project type: enhancement Proposed improvement labels Mar 1, 2024
@StefanaHanc
Copy link
Author

StefanaHanc commented Mar 4, 2024

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

@pennam
Copy link
Contributor

pennam commented Mar 5, 2024

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

@pennam
Copy link
Contributor

pennam commented Mar 5, 2024

@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

@StefanaHanc
Copy link
Author

StefanaHanc commented Mar 6, 2024

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 !

@StefanaHanc
Copy link
Author

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?

@pennam
Copy link
Contributor

pennam commented Mar 11, 2024

@StefanaHanc the repo is public now

@StefanaHanc
Copy link
Author

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

@pennam pennam linked a pull request Mar 18, 2024 that will close this issue
@per1234 per1234 added the conclusion: resolved Issue was resolved label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: documentation Related to documentation for the project type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants