• 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
    
About

Avatar for d0773d @d0773d started