AES library Import

Hello,
I want to use the AES library with Photon. I came across the tropicssl library and I am having troubles importing it. I know we have to copy the files but what names do I give them?
Because when I just say “aes.h” or “aes.c”, then the #include statements give an error by stating- can’t find tropicssl/aes.h
Do we have to put them in some kind of folder? If yes, then how do you create a folder along side your app?

If anybody has done this then please let me know or send me your code! Thanks!

1 Like

@ScruffR I haven’t got a reply and I am running out of time.
Could you connect me with someone who knows what I have to do.
Thanks!

@Dave has been dealing with something similar, but I doubt it’ll be a matter of minutes or even hours.

Hey All!

Let me take a look, and see if I can help you quickly.

edit: I took some time to look into this, but ran out of time unfortunately. It looks like you need to include your own copy of mbedtls entirely. I’m going to attach what I’ve done thus far, but keep in mind it’s not working yet as is. My goal is to release some examples that demonstrate some crypto basics in user-space, but it’ll take me a while before I’ll have time to get to that.

Thanks,
David

2 Likes

Hi @Dave Thank you for your quick response!
I have an example for AES encryption in Python and I think I’ll be able to convert it to Photon. I just need to know where to put the aes.h and aes.c files?
I am using the Web IDE and I tried to add files via the ‘+’ symbol which added tabs. How can I put them in folders over there?
There is an example by the Particle CTO @zachary ( https://gist.github.com/towynlin/fb1f56bdd0a77b46cf09 )
But, I am having problems as I don’t know where to add the .h and .c files.

Let me know if you find anything or I have to compulsorily do this on Atom.

You should be able to copy & paste into those new tabs. Unfortunately you can get make folders on the web IDE, but that shouldn’t be nessecary either. Particle Dev is an option, but not required either. It just gives you more control over your files.

Yes, I have done that. And I have named them “aes.h” , “aes.cpp”, etc, etc.
But when I Verify my code, I get an error that tropicssl/aes.h not found
So I changed the names to tropicsslaes.h, etc but still spark_protocol gives an error.
Let me know what the names of the files should be.

The IDE should automatically add the include line for you, so try removing the “include tropicssl/xxxx”. Likewise, change that line in the .cpp file to match the new include name.

So that means, I just put the name as “aes.h”, “aes.cpp”, etc right?
And as the IDE automatically adds those files, I need not insert anything else. Right?

You need to locate the #include "tropicssl/aes.h" the compiler is complaining about (which most likely will be in aes.cpp - as the error message should tell you too) and change that to #include "aes.h".

Yes, I did that and then it results to errors in different files, so I changed those too. Now finally it says this-

./communication/src/spark_protocol.h:33:27: fatal error: tropicssl/rsa.h: No such file or directory
#include “tropicssl/rsa.h”

Over here spark_protocol.h is inbuilt, so how do I change it?

Okay I got the code to compile. But I am stuck with using the functions. So hopefully @Dave can help me tomorrow by providing a sample code for AES_ECB encryption!
Thanks for the help! @ScruffR @Moors7

That’ll pose a problem - hence (I guess) Dave also needs some more time.

Following on from this, what I’ve found works for your own local copy of MBEDTLS (using local compilation rather than WebIDE) is:

Create a new application folder, for example ‘myapp’
cd myapp
Create subfolder mbedtls
Copy mbedtls library/.c in to myapp
Copy mbedtls/include/mbedtls/
.h in to myapp/mbedtls
Copy config-suite-b.h (or another of the example config files) to mbedtls/config.h

Write your application code ’application.cpp’ (in to myapp folder)
Add header #include lines in to application.cpp as needed for compilation

Edit config.h as appropriate for your requirements, but including these three amendments:

  • Comment out: #define MBEDTLS_NET_C
  • Add #define MBEDTLS_NO_PLATFORM_ENTROPY
  • Remove “mbedtls” from #include “mbedtls\check_config.h” line (near end of file) so it reads #include “check_config.h”

Compile. It doesn’t seem to matter that you have added the entire mbedtls *.c and *.h because when it compiles it only links in what you’ve used. The tricky part of all of this is getting config.h correct. I’ve not tried AES so you may need to include some of the AES directives (the #includes) to get AES to compile and run.

Note: I don’t use WebIDE, but suspect that you’d need to edit the *.h and *.c files to flatten the structure, in which case you would probably want to just copy in the files you actually need rather than the entire mbedtls suite.

3 Likes