TropicSSL-RSA usage error on Photon

Hi,
I am trying to use RSA from TropicSSL Library. I developed new “.ino” file, and included “rsa.h” and tried to execute “rsa_self_test()”. as shown below:

#include "application.h"
#include "tropicssl/rsa.h"

void setup(){

	Serial.print(rsa_self_test(0));
}

void loop(){   

}

When i compile the project folder through particle cli, i received the following output:

Compiling code for photon Including:
H:/PhotonExamples/RSA2/tropicssl/include/TestRSA.ino H:/PhotonExamples/RSA2/tropicssl/include/aes.c H:/PhotonExamples/RSA2/tropicssl/include/bignum.c H:/PhotonExamples/RSA2/tropicssl/include/padlock.c H:/PhotonExamples/RSA2/tropicssl/include/rsa.c H:/PhotonExamples/RSA2/tropicssl/include/sha1.c
attempting to compile firmware
pushing file: H:/PhotonExamples/RSA2/tropicssl/include/TestRSA.ino
pushing file: H:/PhotonExamples/RSA2/tropicssl/include/aes.c
pushing file: H:/PhotonExamples/RSA2/tropicssl/include/bignum.c
pushing file: H:/PhotonExamples/RSA2/tropicssl/include/padlock.c
pushing file: H:/PhotonExamples/RSA2/tropicssl/include/rsa.c
pushing file: H:/PhotonExamples/RSA2/tropicssl/include/sha1.c
Errors
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/…/lib/gcc/arm-none-eabi/4.8.4/…/…/…/…/arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-writer.o): In function _write_r': writer.c:(.text._write_r+0x10): undefined reference to_write’
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/…/lib/gcc/arm-none-eabi/4.8.4/…/…/…/…/arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-closer.o): In function _close_r': closer.c:(.text._close_r+0xc): undefined reference to_close’
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/…/lib/gcc/arm-none-eabi/4.8.4/…/…/…/…/arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-fstatr.o): In function _fstat_r': fstatr.c:(.text._fstat_r+0xe): undefined reference to_fstat’
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/…/lib/gcc/arm-none-eabi/4.8.4/…/…/…/…/arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-isattyr.o): In function _isatty_r': isattyr.c:(.text._isatty_r+0xc): undefined reference to_isatty’
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/…/lib/gcc/arm-none-eabi/4.8.4/…/…/…/…/arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-lseekr.o): In function _lseek_r': lseekr.c:(.text._lseek_r+0x10): undefined reference to_lseek’
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/…/lib/gcc/arm-none-eabi/4.8.4/…/…/…/…/arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-readr.o): In function _read_r': readr.c:(.text._read_r+0x10): undefined reference to_read’ collect2: error: ld returned 1 exit status make: *** [c0c8389eea4c41c1bcd44c34f7ac3585113a95c4a9e118dcb1f66fd3d207.elf] Error 1 Compile failed. Exiting.

From the above error output, i can’t figure out what is the issue. Please tell where i am going wrong.

Regards,
Burhan

The AES library is not part of the API on the Photon (since it’s an internal implementation detail, subject to change, e.g. we may use mbedTLS in future.)

To use Tropic SSL, you can include the source code from the github repo in your project.

Hi @mdma ,
I tried to add the source code of the library on web IDE, but didn’t succeed.
May be i am making mistake while adding the library.
By adding the source code means adding library by clicking “contribute library” and then giving the URL? if yes , i tried and spark.json missing and similar more errors raised.

How can i include source code from github repo?

Regards,
Burhan

@Burhan, what @mdma meant is that you will need to cut&paste each file (content) into a file tab of the same name in the web IDE.

ok. i tried to copy/paste the required files in web IDE, but still getting same error, as shown below:

/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text._write_r+0x10): undefined reference to `_write'
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'
collect2: error: ld returned 1 exit status
make: *** [5843a57bccaa975481a12460a7c97ee9ee6a7922c3e33717e5b30b119fd4.elf] Error 1

What else can i try to make it running…

@Burhan, do you have these includes at the top of your application file?

#include "application.h"
#include "spark_protocol.h"
#include "tropicssl/rsa.h"
#include "tropicssl/aes.h"

Yes i do have them…

#include "application.h"
#include "spark_protocol.h"
#include "tropicssl/rsa.h"
#include "tropicssl/aes.h"

I have also these includes :

// This #include statement was automatically added by the Particle IDE.
#include "bignum.h"
#include "sha1.h"
#include "rsa.h"
#include "aes.h"

I tried with and without them, but in both cases, same error.

@Burhan, the errors are referring to system-part1 functions and I’m not sure why they would not link. You may need to setup a local toolchain to compile locally for this to work.

@peekay123 by local tool chain, do you mean on “Particle Dev” or compile from “partcile cli”. I have tried with cli, and having same errors.

That looks to me as if something is trying to write to stdout, possibly an unhandled exception handler?

Be sure you created .c files and not .cpp (although I don’t know for sure that .c files work in the IDE…)

@Burhan, IDE, DEV and CLI all use the cloud compile farm. Setting up a local toolchain means running the compiler and other tools on your computer. Here is a guide to doing that:

One word of caution. I don’t recommend this method for beginners.

Just adding to this thread for future readers:

I do have a local toolchain set up, and ran into this error as well. Thanks @mdma for pointing out the stdout issue, which is the underlying cause of:

/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m/libg_s.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text._write_r+0x10): undefined reference to `_write'

etc.

By #Including the C++ lib “iostream” directly or indirectly, you can cause this error, since iostream uses underlying C hooks for _write_r, _close_r, _fstat_r, _isatty_r, _lseek_r, and _read_r. These don’t seem to be part of the standard firmware lib (As far as I can tell) since there usually ins’t a tty subsystem for most things.

1 Like