-
• #2
jswrap_crypto_cbc.c:
[#include](https://forum.espruino.com/search/?q=%23include) <stdio.h> [#include](https://forum.espruino.com/search/?q=%23include) "crypto.h" //#include "jsinteractive.h" /*JSON{ "type" : "class", "class" : "Crypto" }*/ /*JSON{ "type" : "staticmethod", "class" : "Crypto", "name" : "cbc", "generate" : "jswrap_crypto_cbc" }*/ void jswrap_crypto_cbc() { uint8_t key[CRL_AES128_KEY]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; uint8_t iv[CRL_AES_BLOCK]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; uint8_t plaintext[1024]={'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; uint8_t ciphertext[1024]; int i = 0; // outSize is for output size, retval is for return value int32_t outSize, retval; AESCBCctx_stt AESctx_st; // The AES context // Initialize Context Flag with default value AESctx_st.mFlags = E_SK_DEFAULT; // Set Iv size to 16 AESctx_st.mIvSize=16; // Set key size to 16 AESctx_st.mKeySize=CRL_AES128_KEY; // call init function retval = AES_CBC_Encrypt_Init(&AESctx_st, key, iv); if (retval != AES_SUCCESS) { /*jsiConsolePrint("AES Encrypt Init FAILD!\r\n");*/ } // Loop to perform four calls to AES_CBC_Encrypt_Append, each processing 256 bytes for (i = 0; i < 1024; i += 256) { //Encrypt i bytes of plaintext. Put the output data in ciphertext and number //of written bytes in outSize retval = AES_CBC_Encrypt_Append(&AESctx_st, plaintext, 256, ciphertext, &outSize); if (retval != AES_SUCCESS) { /*jsiConsolePrint("AES Encrypt Append FAILD!\r\n");*/ } } //Do the finalization call (in CBC it will not return any output) retval = AES_CBC_Encrypt_Finish(&AESctx_st, ciphertext+outSize, &outSize ); if (retval != AES_SUCCESS) { /*jsiConsolePrint("AES Encrypt Finish FAILD!\r\n");*/ } }
jswrap_crypto_cbc.h:
void jswrap_crypto_cbc();
I commented out #include "jsinteractive.h" and all the jsiConsolePrint and attempted to compile again and received this error:D espruino_1v80_pico_1r3.elf /tmp/cc6qhSAv.ltrans15.ltrans.o: In function `jswrap_crypto_cbc': <artificial>:(.text.jswrap_crypto_cbc+0xea): undefined reference to `AES_CBC_Encrypt_Init' <artificial>:(.text.jswrap_crypto_cbc+0x100): undefined reference to `AES_CBC_Encrypt_Append' <artificial>:(.text.jswrap_crypto_cbc+0x114): undefined reference to `AES_CBC_Encrypt_Finish' collect2: error: ld returned 1 exit status make: *** [espruino_1v80_pico_1r3.elf] Error 1 Build failed
-
• #3
I think I narrowed down the errors I explained in the top two threads. I Think the rand() error is probably due to a conflict in naming functions? I'm assuming the espruino has a function called rand() and the Crypto library has a rand() function?
The undefined reference error in my second post is probably due to not including a header file listing the methods.
I'm not much of a programmer so I'm not really sure where to go from here to fix those issue.
-
• #4
The problem could well be because Espruino has its own version of most of the standard library functions like
rand
(unfortunately required because many of them referencemalloc
or similar, which pulls in a whole load of extra RAM/Flash usage).It might be that ST's library actually includes the main standard library, or that it includes its own
rand
, as you say. But it looks like you can work around that...As for
undefined reference to AES_CBC_Encrypt_Append
- it looks to me like you just forgot to add one of the.c
files to the Makefile - the one that actually includes theAES_CBC_Encrypt_Append
function. If you add that then it might actually compile and work...PS - the stuff in your post didn't get rendered properly as 'code' because there wasn't a clear line before and after the code markers (```) - I've just changed it for you.
I am using a stripped down version of the STM32 Cryptographic library package.
I am attempting to custom compile the pico firmware to include a very basic aes cbc cipher library. I will eventually include more, however, right now I am just trying to get the hang of custom compiling the firmware.
The error I am receiving is:
I executed
./create_pico_image_1v3.sh
to compile.I have a feeling there are more errors, but the complete output status of the compiling has been chopped off in the terminal. Is there a log file where I can view the complete compiling log?
crypto.tar.gz is the stripped down version and the original library can be found at: http://www.st.com/web/en/catalog/tools/PF259409
1 Attachment