Moddable-OpenSource / moddable

Tools for developers to create truly open IoT products using standard JavaScript on low cost microcontrollers.
http://www.moddable.com
1.29k stars 235 forks source link

Crypto library #311

Open diogoviannaaraujo opened 4 years ago

diogoviannaaraujo commented 4 years ago

Hi, im trying to port a JWT sign function to create a password for google iot core, but im having some problems find the correspondent code for Node's:

crypto.createSign(method).update(input).sign(key, 'base64').

I've been reading Moddable Crypt module but the RS256 Class I've found is really cryptic.. Is there some module that could solve this or should I make a C code wrapper?

Thanks

diogoviannaaraujo commented 4 years ago

Im pretty close, read a little more undiscovered what PKCS1_5 was about, now im just having some stack overflow problems when using its sign() function.

diogoviannaaraujo commented 4 years ago

Ok, I was able to generate the JWT to log into google cloud iot, but the process is taking 14 seconds! Need to find out how to improve that performance. I can see in the code that this is all made in JS right? Guess can get more performance doing it in C, will give a try.

Edit1: I was using 4096-bit key, changed to a 2048-bit and it now takes 2 seconds, way better. But I was not able to parse the key using PKCS1, I had to switch to PKCS8. don't know why.

Edit2: Been reading and saw benchmark of mbedtls doing rsa in .5s, still learning how.

wilberforce commented 4 years ago

I've been reading Moddable Crypt module but the RS256 Class I've found is really cryptic..

The esp hardware has acceleration for this sort of thing so if you use the esp-idf lib it will use the hardware acceleration. Much faster than doing in C!

bartmichu commented 3 years ago

@diogoviannaaraujo would you share some code? I'm planning to play around with GCP in near future.