Elliptic Curves with Arduino

Hello, is there a reliable library for encrypting/decrypting simple messages for Arduino using elliptic curves?

I have found this library:

but I doubt if it encrypts/decrypts... I have run it but it only finds private/public keys and it compares them, based on this code:

ecc_test.ino

Thank you...

I guess you just need to hunt around for published source code e.g.
https://www.codeproject.com/Articles/22452/A-simple-C-implementation-of-Elliptic-Curve-Crypto

Memory may be a problem.

ardly:
I guess you just need to hunt around for published source code e.g.
A simple C++ implementation of Elliptic Curve Cryptography - CodeProject

Memory may be a problem.

Thanks, but again it is for numbers, it does not support text message encryption/decryption. However, is it generally possible to build a library for Arduino (MEGA 2560 for example) that should do this: small text (about 30 bytes) encryption/decryption?

Provided the hardware isn't holding you back too much (processing speed, available memory) - I'm quite sure it can be done.

Another major issue is your C++ and math skills. This is, especially on the math part, pretty high level stuff. You'd first have to make sure you fully understand the math behind it, then if your programming skills are up to it you can try to adapt the code given in the links provided. I can do a lot with Arduinos myself but am quite sure not this, mostly as I just don't get math :slight_smile:

360modena_cs:
but I doubt if it encrypts/decrypts... I have run it but it only finds private/public keys and it compares them,

It is generating a 20 byte (160 bit) shared secret. You can then use that shared secret as a key for your favorite encryption process. Perhaps one of the AES encryption Arduino libraries.

Alice generates a public/private key pair.
Alice publishes the public key.
Bob generates a public/private key pair.
Bob publishes the public key.
Bob wants to send a secret message to Alice.
Bob generates their shared secret from his private key and Alice's published public key.
Bob encrypts his message to Alice with their shared secret and sends it (or publishes it).
Alice sees the message from Bob.
Alice generates their shared secret from her private key and Bob's published public key.
Alice uses the shared secret to decrypt the message.

Hi, can you run the example code in this library?
when I try, it show up this error:

ecc_test:5:15: error: expected unqualified-id before string constant

static int RNG(uint8_t *dest, unsigned size) {

That’s a weird one. It seems to be caused by the Arduino IDE generating a C++ prototype for the C function. I suspect the IDE changed behavior since the library example was written. You can suppress the automatically generated prototype by adding one of your own:

#include <uECC.h>

///// Insert these three lines:
extern "C" {
static int RNG(uint8_t *dest, unsigned size);
}

extern "C" {

That fixes the the error and generates three warnings:

In file included from /Users/john/Documents/Arduino/libraries/micro-ecc-master/uECC.c:181:0:
/Users/john/Documents/Arduino/libraries/micro-ecc-master/asm_avr.inc: In function 'uECC_vli_mult':
/Users/john/Documents/Arduino/libraries/micro-ecc-master/asm_avr.inc:908:27: warning: unused variable 'r' [-Wunused-variable]
     volatile uECC_word_t *r = result;
                           ^
In file included from /Users/john/Documents/Arduino/libraries/micro-ecc-master/uECC.c:738:0:
/Users/john/Documents/Arduino/libraries/micro-ecc-master/curve-specific.inc: In function 'mod_sqrt_secp224r1':
/Users/john/Documents/Arduino/libraries/micro-ecc-master/curve-specific.inc:544:59: warning: unused parameter 'curve' [-Wunused-parameter]
 static void mod_sqrt_secp224r1(uECC_word_t *a, uECC_Curve curve) {
                                                           ^
/Users/john/Documents/Arduino/libraries/micro-ecc-master/uECC.c: At top level:
/Users/john/Documents/Arduino/libraries/micro-ecc-master/uECC.c:369:13: warning: 'muladd' defined but not used [-Wunused-function]
 static void muladd(uECC_word_t a,
             ^
Sketch uses 9798 bytes (30%) of program storage space. Maximum is 32256 bytes.
Global variables use 566 bytes (27%) of dynamic memory, leaving 1482 bytes for local variables. Maximum is 2048 bytes.

As near as I can tell, those warnings are harmless. Give the fixed code a try to see what happens.

Be warned that on an Arduino UNO it can take a LONG time to generate a public/private pair. Typically it's a second or two but in one case it took 135 seconds to generate a pair.

I have fixed it by remove "static" at 5th line:

int RNG(uint8_t *dest, unsigned size) {
...
}

now I can flash it into my WeMos board but after a long time waiting, nothing show up in COM monitor

nthanhha26:
I have fixed it by remove "static" at 5th line:

int RNG(uint8_t *dest, unsigned size) {
...
}

now I can flash it into my WeMos board but after a long time waiting, nothing show up in COM monitor

It's hard to say what you've done. You might have removed the RNG entropy source from the ECC library. Therefore you generate nothing, never.

What exactly is that you try to achieve? Using crypto this way, without understanding the basic principles in not secure.

What I did when using uECC was to rename
static int RNG(uint8_t *dest, unsigned size);
to
static int RNG1(uint8_t *dest, unsigned size);
because RNG(); was defined by a different library in a different spot.

The "ecc_test.ino" example in the uECC library contains this setup():

void setup() {
  Serial.begin(115200);
  Serial.print("Testing ecc\n");
  uECC_set_rng(&RNG);
}

If you don't see the "Testing ecc" message immediately after startup or reset then something more fundamental is wrong. Perhaps a baud rate mismatch? Do you have Serial Monitor set for 115200 baud?

Hii

I am newcomer for Arduino.I'm try to create simple Encryption/ decryption code using Arduino uno .
I'm trying to find tutorial or something..Can you help me plz?

Is is possible to ECC encryption in arduino uno board?