You are reading a single comment by @Wilberforce and its replies. Click here to read the full conversation.
  • Which board are you doing this on? The Pico would 'just work'.

    It would be great to get SHA1 function into the core.

    It is in the core though. You just need the crypto library to be built in.

    I wondering if the hashlib library would be a good place to add the sha1 function

    Seriously, just figure out why mbedtls library isn't building (I guess this is for ESP8266?) rather than just duplicating something that already exists and works fine.

    I'm planning to remove hashlib at some point. Crypto is trying to be similar to CryptoJS so should be easy for people to get to grips with. mbedtls is great, and will be an easy source of loads more crypto functions if/when people want them as well.

    Perhaps one issue is that you only want SHA1 and not AES/etc - but that could be tweaked with some ifdefs pretty easily.

  • I'm trying to build crypto for esp8266.

    CC libs/crypto/jswrap_crypto.o
    libs/crypto/jswrap_crypto.c: In function 'jswrap_crypto_error':
    libs/crypto/jswrap_crypto.c:91:3: error: invalid initializer
       if (e) jsError(e);
       ^
    libs/crypto/jswrap_crypto.c: At top level:JsVar
    
    *jswrap_crypto_error_to_jsvar(int err) {
      const char *e = jswrap_crypto_error_to_str(err);
      if (e) return jsvNewFromString(e);
      return jsvVarPrintf("-0x%x", -err);
    }
    
    void jswrap_crypto_error(int err) {
      const char *e = jswrap_crypto_error_to_str(err);
    >>>  if (e) jsError(e);
      else jsError("Unknown error: -0x%x", -err);
    }
    

    The issue appears to be the flash_str #define:

    [#define](https://forum.espruino.com/search/?q=%23define) jsError(fmt, ...) do { \
        FLASH_STR(flash_str, fmt); \
        jsError_flash(flash_str, ##__VA_ARGS__); \
      } while(0)
    
    root@esp8266-VirtualBox:~/Espruino# grep '#define FLASH_STR' src/*.h
    src/jsutils.h:#define FLASH_STR(name, x) static char name[] __attribute__((section(".irom.literal"))) __attribute__((aligned(4))) = x
    

    static char name[] vs const char *

    Is there a simple way to resolve this?

    I'm not sure the protocol here - should I raise as a github issue?

About

Avatar for Wilberforce @Wilberforce started