Tuesday, March 14, 2017

MPLAB IPE gives "Connection Failed" on MacOS

I was given a PIC32MZ board. I am currently very interested in lightweight cryptography, and the PIC32MZ seems like a great target. It even has BSD4.4-lite port! I was trying to use the MPLAB IPE and I kept getting:
Connecting to Starter Kit on Board...

Currently loaded firmware on Starter Kit on Board
Firmware Suite Version.....01.38.10 *
Firmware type..............Unknown Firmware Type

Now Downloading new Firmware for target device: PIC32MZ2048EFH144 
Downloading AP...
AP download complete
Programming download...
Connection Failed.
Apparently, you need to run the MPLABCOMM program to install the USB drivers. The file is included with the IPE, but it apparently skips that step in the installation. The IPE worked magically after that.

Tuesday, March 7, 2017

This was supposed to be the AES S-Box, it's not.

Test vectors are so very important. Whenever possible, I try to verify all of my circuits. I was verifying the AES S-Box implementation and randomly picked: 0x00, 0x04, 0x10, 0xFF. Everything worked out except 0xFF, and due to the small data size, I can actually test every option. The resulting logic output for my S-Box follows:
Most of these entries are incorrect; however, I only noticed because the 0xFF value was off. This is just a good reminder of why I test every value if possible and why it's good to design test vectors. Now to determine if it is in my multiplicative inverse unit or the affine transform. (I'm betting the affine circuit because if the multiplicative inverse circuits were bad, 0x00 wouldn't have mapped to 0x63)

Making BASH throw an error with the function name.

Debugging bash strings is just strange. I've just come across ${FUNCNAME[0]}, which returns the function that was called. In the following code, the testwithlen4() function expects a string with the length of 4, and if you give it short or long string, it returns the error with the name.
#!/bin/sh
echoerr() { echo "$@" 1>&2; }  # echo output to STDERR

testwithlen4()
{
  isom_inputstring=$1
  isom_inputsize=${#isom_inputstring}  #get the length, it should be 4
  isom_inputmaxsize=4
  if [ "$isom_inputsize" -ne "$isom_inputmaxsize" ]; then
    echoerr "ERROR, ${FUNCNAME[0]} failed due to isom_inputsize != $isom_inputmaxsize ($isom_inputsize) " 
    exit -1
  fi
testwithlen4 "abc"
The error result will be:
ERROR, testwithlen4 failed due to isom_inputsize != 4 (3)
Now to make a whole slew of changes to my support code. :/