I am experimenting with ECDSA keys through secp256k1 curve using the micro-ecc library (downloaded through the library manager). I am running Arduino 1.8.9 on Arduino UNO ATmega328P. My code (derived from the library's example) is as follows:

#include <uECC.h>

extern "C" {
static int RNG(uint8_t *dest, unsigned size);

extern "C" {

static int RNG(uint8_t *dest, unsigned size) {
  // Use the least-significant bits from the ADC for an unconnected pin (or connected to a source of
  // random noise). This can take a long time to generate random data if the result of analogRead(0)
  // doesn't change very frequently.
  while (size) {
    uint8_t val = 0;
    for (unsigned i = 0; i < 8; ++i) {
      int init = analogRead(0);
      int count = 0;
      while (analogRead(0) == init) {

      if (count == 0) {
         val = (val << 1) | (init & 0x01);
      } else {
         val = (val << 1) | (count & 0x01);
    *dest = val;
  // NOTE: it would be a good idea to hash the resulting random data using SHA-256 or similar.
  return 1;

}  // extern "C"

void setup() {

  const struct uECC_Curve_t * curve = uECC_secp256k1();
  uint8_t private1[32];

  uint8_t public1[64];

  uECC_make_key(public1, private1, curve);

  for (uint8_t i = 0; i < 32; i++)
    Serial.print(private1[i], HEX);
  for (uint8_t i = 0; i < 64; i++)
    Serial.print(public1[i], HEX);


void loop() {


My goal for now is to just copy the generated private key from the serial monitor, import it into other code in my desktop and verify that I am getting the same public key as in Arduino.

However the key in the serial monitor only has 63 hex characters (instead of 64). Also the public key does not match. Can anyone suggest a solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.