Closed y3k00000 closed 1 year ago
I've never tried a build for pico w, I don't think asm for rp2040 is supported by the tomsfastmath library, probably just disable asm optimizations and use the C implementation.
At the moment I don't have so much time to spend on the library, as soon as I can take a look I will update you.
After commenting out all TFM flags the building works indeed.
Though it's taking about 8 seconds for pico to do the gen_keypair() -> ecdsa.sign() -> ecdsa.verify() procedure.
Also a new issue on uhashlib emerged, I'll get another opened.
I have remove all asm optimizations to easy build on more platform and reduce code size.
see d9e6de1
@dmazzella Sorry but the build seems still not working with latest version.
I found that I can set TFM_NO_ASM in tfm_mpi.h. That makes the building work but I don't know how to make it responsive to specific board.
I can't reproduce it, can you give me some more information?
Just did the example steps in (README.md)[https://github.com/dmazzella/ucrypto/blob/master/README.md]. All I did else is modifying the USER_C_MODULES into the micropython's root.
git clone https://github.com/micropython/micropython.git
cd micropython
git submodule update --init
cp -R examples/usercmodule .
git clone https://github.com/dmazzella/ucrypto.git usercmodule/ucrypto
(vim edit the usercmodule/micropython.cmake, change contents to only bulild ucrypto)
make -j4 -C mpy-cross
make -j4 -C ports/rp2 BOARD="PICO_W" USER_C_MODULES="$(pwd)/usercmodule/micropython.cmake"
I bet it's because of version or environment difference, I use python3.10 and gcc-arm-none-eabi in ubuntu. Perhaps docker can be used to do the checking.
[update] In docker ubuntu:22.10 setup:
apt update
apt install build-essential cmake python3 git gcc-arm-none-eabi
apt install mc vim
<- personal favorites
can you try to set this:
#define TFM_NO_ASM
#define TFM_ECC192
#define TFM_ECC224
#define TFM_ECC256
#define TFM_ECC384
#define TFM_ECC512
#define TFM_RSA512
#define TFM_RSA1024
#define TFM_RSA2048
with these options do you have a correct build and performance improvements?
With different setup I've got these two uf2s. Will be testing them tomorrow.
Tested and it turns out that:
NO_ASM + optimizations off -> around 8100 millis. NO_ASM + TFM_ECC256 on -> around 8000 millis. NO_ASN + optimizations on ->around 9000 millis.
with test-ecdsa.py.
Thanks for testing, another factor that affects performance is FP_MAX_SIZE, as close as possible to the maximum size used improves performance.
For example:
#ifndef FP_MAX_SIZE
#define FP_MAX_SIZE ((512 * 2) + (8 * DIGIT_BIT))
#endif
➜ micropython (master) ✗ python3 -Bu tools/pyboard.py -d /dev/cu.usbmodem3688376D31302 ports/stm32/boards/ARDUINO_PORTENTA_H7/modules/ucrypto/tests/ufastecdsa_1.py
280
private_key: 68064901822059193297355591236270794728570578525458395771548415797682124487321
public_key: 56273711433973141702864361997854131929063237701262685114076392214438313357953 115155927802927194099351565796401784074052754432979716409418596763418442132236 P256
287
R: 101067716677444751429800737846638201796005626664305676910811172654282380192024
S: 38644738558257852906388494618343781460720385280070907211689080560316366956269
244
True
with
#ifndef FP_MAX_SIZE
#define FP_MAX_SIZE ((2048 * 2) + (8 * DIGIT_BIT))
#endif
➜ micropython (master) ✗ python3 -Bu tools/pyboard.py -d /dev/cu.usbmodem3688376D31302 ports/stm32/boards/ARDUINO_PORTENTA_H7/modules/ucrypto/tests/ufastecdsa_1.py
309
private_key: 106472340573254775222227974495724840087995146439037220355858078754156495846972
public_key: 34108113635331697938951275200982830719278582384817159601339677764586131156916 26696693941607843593491661137010237005121733009205668037610180205162806112865 P256
316
R: 60171275703764229238973891383583154634870790505500210504418251675921058838795
S: 56886345508105931706026392037038427444849138514384029497210354262019795569665
273
True
With latest sources, both micropython and ucrypto. Trying to make a build for pico w board, but it always fails in the last steps :
The building keeps failing with Error
selected processor does not support ***** in Thumb mode
instruction not supported -- '*******'
To the best of my knowledge these kind of asm issues should be automatically solved by compiler, but it seems currently not.
What else can be done to make things work or it's just a unsolvable platform supporting issue?