-
Notifications
You must be signed in to change notification settings - Fork 7.6k
possible issue in mbedtls ECDH #8128
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
Comments
Does your test code work properly under earlier versions of arduino-esp32? |
Yeah, it did . Can you see any irregularities in the code btw ? |
@anishsheikh I haven't used MBED so I can't comment on your code. I can think of two reasons the behavior might have changed between versions:
It would be useful to know the arduino-esp32 versions your test code works on vs breaks. |
I got it working, somehow it messes up using different contexts irregularly, the mpi bignum functions don't actually read the key properly, |
@anishsheikh That sounds important. Unfortunately I'm not following you. Can you spell it out for us? What lines of code need to change? |
Can you try to reproduce the problem? You have to just add some method to give the esp32 the generated public key and esp32 have to convert the hexadecimal into a byte array then input the byte array into calcsecret function , I lack time a bit right now to check what can be wrong with the compiler . I would certainly look into it later |
This really has nothing to do with arduino. I would recommend you post the issue on esp-idf. They will have much deeper knowledge of the workings of the mbedtls hardware. |
well i used arduino ide, so I posted here. anyway i will try to post there. I did mention compiler which comes with something called GCC(GNU C COMPILER) which is built for specific architecture, which is not "ARDUINO" Specific. |
@anishsheikh, could you please share your fix of the issue, it would be much appreciated. |
@anishsheikh, I found the issue in your code, when you call sizeof on a pointer, it doesn't give you the size of the data the pointer points to, but rather the size of the pointer itself. This would be 4 bytes for a 32-bit system or 8 bytes for a 64-bit system. Thus, in memcpy you're only porting the first 4 bytes instead of 32. Replacing sizeof with 32 fixes the issue for me. |
I’ve forgot to notify , i fixed the issue long ago. |
In x86_64 and aarch64 the compiler itself managed it. For code portability it should be manually managed . |
Board
ESP32-C3-DevKitM-1
Device Description
official Espressif Board
Hardware Configuration
Nothing Connected , just bare devboard
Version
v2.0.8
IDE Name
Arduino IDE
Operating System
Windows 11 22h2
Flash frequency
40
PSRAM enabled
no
Upload speed
115200
Description
I first wrote mbedtls code in C and tested with corresponding dart code which reproduces the same shared secret.
In Arduino IDE the main compilation happens on provided gcc compiler so , the code actually works just fine with mbedtls_mpi_write_binary(),
mbedtls_mpi_read_binary(),
It just doesn't produce the intended shared secret .
in RHEL 8 , gcc 8.5.0, i used mbedtls_mpi_write_binary_le(),
mbedtls_mpi_read_binary_le(),
which produced actual intended shared key in both Dart and C program, However in specific case of arduino ide , if we use the
mbedtls_mpi_write_binary_le(),
mbedtls_mpi_read_binary_le(),
both calculating functions produce error which are
mbedtls_ecdh_calc_secret() and mbedtls_ecdh_compute_shared(),
Sketch
Debug Message
Other Steps to Reproduce
it works just fine in x86_64 so i guess it is not a mbedtls specific problem, most probably the problem corresponds to compiler specific endianness issue or linking problems so i opened an issue here, any specific help would be great, the code maybe messy but logic is understandable. can you please help me out?
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: