Avatar for Cryptizard

Cryptizard

Member since Jun 2021 • Last active Oct 2022
  • 2 conversations
  • 5 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Cryptizard

    Figured it out. The gloves were actually shorting out the Puck. They are extremely conductive I guess. When I put it in the housing it worked fine.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Cryptizard

    Hi everyone, I have been using the Puck for a while now as part of my research and I have run into some very, very weird behavior recently. I am trying to do some tests where I put the Puck in an RF isolation box (Ramsey) so I can isolate the signals coming from it and for some reason it just refuses to work.

    If I load a program onto the Puck, it works completely fine until the second I close the lid on the RF box and then it appears to reboot continuously until I open the lid, then it happily goes back to running the program that was in flash memory.

    I have attached a video showing this happen. I loaded a program that just blinks the green LED when the button is pressed. The red light is, I believe the Puck rebooting? It keeps doing that indefinitely if I keep it in the box.

    Any ideas as to why this might be happening or what I could do to fix it?

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Cryptizard

    Weird, I am using malloc in several places and it works fine now after I fixed the init thing, so that note can't be correct. I will change it to static buffers just to be safe. Thanks for the help!

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Cryptizard

    Fixed it by adding mbedtls_ecp_group_init before the line that was crashing. Not sure why this is necessary since the first line of the load function immediately frees the group, and it worked fine in Linux the way it was originally written, but it works now on the puck.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Cryptizard

    I have built a new firmware for the Puck.js in order to add a C function that does some Elliptic Curve math that would be too slow in JS. I have gotten this firmware to build and load onto the puck successfully, but when I try to run the function I wrote it crashes for some reason (puck becomes unresponsive, disconnects from Web IDE). The function is included below for reference. I used LED lighting to narrow down where exactly it stops working and it appears to be on the line with "mbedtls_ecp_group_load".

    When I build Espruino with a LINUX target, this code works completely fine, so there doesn't appear to be anything wrong with the code itself. I'm having trouble debugging what could be wrong here. Is there any way to attach a debugger to the Puck or something else I could do here? It seems very difficult to debug C code on the Puck because if anything goes wrong it just disconnects from the Web IDE.

    Thank you.

    /*JSON{
      "type" : "staticmethod",
      "class" : "crypto",
      "name" : "PointGen",
      "generate" : "jswrap_crypto_PointGen",
      "params" : [
        ["pkey","JsVar","Private key to multiply P-224 generator with, should be a string up to 100 chars"]
      ],
      "return" : ["JsVar","Returns an X coordinate string"],
      "ifdef" : "USE_TLS"
    }
    
    Key generator
    */
    JsVar *jswrap_crypto_PointGen(JsVar * pkey){
    
      jshPinOutput(LED1_PININDEX, 1);
    
      //jsiConsolePrintf("Allocating buffers...\n");
      char* pkeystr = malloc(20);
      char* outputbuf = malloc(80);
    
    
    
      //jsiConsolePrintf("Retrieving string from jvar...\n");
      jsvGetString(pkey, pkeystr, 19);
    
      //jsiConsolePrintf("%s\n", pkeystr);
    
      mbedtls_mpi * mpikey = malloc(sizeof(mbedtls_mpi));
      mbedtls_mpi_init(mpikey);
    
     
    
      //jsiConsolePrintf("Converting to MPI...\n");
      int ret = mbedtls_mpi_read_string(mpikey, 10, pkeystr);
      if(ret != 0)
      {
        return jsvVarPrintf("MPI READ - %d\n", ret);
      }
    
      mbedtls_ecp_group * grp = malloc(sizeof(mbedtls_ecp_group));
    
      jshPinOutput(LED2_PININDEX, 1);
    
      //jsiConsolePrintf("Loading group parameters...\n");
      ret = mbedtls_ecp_group_load(grp, MBEDTLS_ECP_DP_SECP224R1);
      if(ret != 0)
      {
        jshPinOutput(LED2_PININDEX, 0);
        jshPinOutput(LED3_PININDEX, 1);
        return jsvVarPrintf("GROUP LOAD FAILED - %d\n", ret);
      }
    
      jshPinOutput(LED3_PININDEX, 1);
    
      mbedtls_ecp_point * pt = malloc(sizeof(mbedtls_ecp_point));
      mbedtls_ecp_point_init(pt);
    
      //jsiConsolePrintf("Multiplying points...\n");
      ret = mbedtls_ecp_mul(grp, pt, mpikey, &grp->G, NULL, NULL);
      if(ret != 0)
      {
        return jsvVarPrintf("ECP MUL - %d\n", ret);
      }
    
      //jsiConsolePrintf("Writing to string...\n");
      size_t outputlen;
      ret = mbedtls_mpi_write_string(&pt->X, 10, outputbuf, 120, &outputlen);
      if(ret != 0)
      {
        return jsvVarPrintf("MPI WRITE - %d\n", ret);
      }
    
      JsVar * returnstring = jsvNewFromString(outputbuf);
    
      free(pkeystr);
      free(outputbuf);
    
      return returnstring;
    }
    
Actions