Tuesday, August 28, 2018

Multiple timers in MacOS/FreeBSD without timer_t.

POSIX extensions strike again, as I did not have timer_t. dispatch functions allow multiple timers in C under MacOS.

int i = 0;
dispatch_queue_t queue;
dispatch_source_t timer1;
dispatch_source_t timer2;

void sigtrap(int sig)
    printf("CTRL-C received, exiting program\n");

void vector1(dispatch_source_t timer)
  printf("a: %d\n", i);
  if (i >= 20) 
void vector2(dispatch_source_t timer)
  printf("b: %d\n", i);
  if (i >= 20)  //at 20 count cancel the 

int main(int argc, const char* argv[]) {

 signal(SIGINT, &sigtrap);   //catch the cntl-c
 queue = dispatch_queue_create("timerQueue", 0);

 // Create dispatch timer source
 timer1 = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
 timer2 = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
 // Set block for dispatch source when catched events
 dispatch_source_set_event_handler(timer1, ^{vector1(timer1);});
 dispatch_source_set_event_handler(timer2, ^{vector2(timer2);});

 // Set block for dispatch source when cancel source
 dispatch_source_set_cancel_handler(timer1, ^{
 dispatch_source_set_cancel_handler(timer2, ^{

 dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC); // after 1 sec

 // Set timer
 dispatch_source_set_timer(timer1, start, NSEC_PER_SEC / 5, 0);  // 0.2 sec
 dispatch_source_set_timer(timer2, start, NSEC_PER_SEC / 2, 0);  // 0.5 sec

 return 0;

Monday, June 11, 2018

ISO rejection of Simon

I am a circuit designer by training, and not a cryptographer. One of the thing that I've found from working with cryptographers, is that I find them to be odd to work with by nature. It's most like because their products are seldom tangible, and therefore there is a lot of infighting.

In this article on the ISO rejection of SIMON, there's a quote regarding the NSA from Tomer Ashur: "They refused to motivate design choices they made such as the choice of matrices U, V, and W in Simon’s key schedule. Instead, they chose to personally attack some of the experts (including @hashbreaker, Orr Dunkelman and myself) as incompetent."

Well, I know the design choices behind U, W, V, which were related to slide attacks for some internal tool they had based on the rounds. I do not know anything about the tool, but Shor's mentioned this when I asked when I was writing my Simontool paper. The matrices in question with circuit implementation are in my simontool.supplemental.pdf. The question at hand is how U, W, and V where decided; however, I cannot answer that as I do not have their internal tools. Having said that, the circuits are beautiful, and perhaps someone will do a detailed analysis of the tradeoffs between each matrix for rounds.

Thursday, April 12, 2018

Wednesday, March 28, 2018

AES S-Box reference implementation.

One of the things that has always bothered me about academia is the "minimally publishable item". I was trying to find a reference AES circuit implementation, and I never found one, so I started writing one for me to use internally. I found the document to be so useful, I sent it out to see if anyone was interested in the tech report. Of course, no one was, so what I have is a very good text book chapter or a nice tech report that everyone seems to want, but no one wants to publish. I used to publish things on ece.gatech.edu, but they decided grad student work was not important enough to be persistent. Once I was postdoc, the same thing happened. I'm hedging now that github will be around long enough for this work to be useful. I now present:

A reference implementation of the AES S-Box:

Wednesday, January 31, 2018

Getting TeXShop to make acronym glossaries in LaTeX

I have no idea why this was so difficult. You need to make engine for TeXShop to create glossaries.
cd ~/Library/TeXShop/Engines
Now you need a text editor that can do ASCII files to create the engine. I called mine: make-glossaries.engine
bfname=$(dirname "$1")/"`basename "$1" .tex`"
makeindex -s "$bfname".ist -t "$bfname".alg -o "$bfname".acr "$bfname".acn
makeindex -s "$bfname".ist -t "$bfname".glg -o "$bfname".gls "$bfname".glo
Next you need to make it executable: chmod +x make-glossaries.engine
Once you restart TeXShop, you'll see "make-glossaries" in the drop down.

Monday, November 20, 2017

Getting a Nest Generation 3 to work with steam heat.

I had a difficult time getting a Nest to work my steam heating system, and google failed me, so I engineered through it. The nest says that it works with 95% of all systems out of the box, but when you have that 5%, it's rather vague. The Nest, and most other thermostats, are in the class of "power stealing thermostats", which basically means they use a RC circuit to leach a bit of power off the lines from the heater. This means that the power is acquired from two lines from the heater. At a minimum, you need two lines to turn on your heater, which are the R and the W. In my case, the Nest did not work; however, I guessed this might happen so I ordered a 120v to 24v transformer in advance.

I have a Beckett 7505B burner controller that does not have a common line. It has just two lugs, Tw and Tr, which are the R and W wire terminals. If you short these two wires together, the system will turn on. The issue was that the Nest need more power. The solution is to add a 24VAC transformer and connect them to the Rc and C lines. The "C" line is the common from the transformer, which is most likely a black line. The "Rc" line is the power from my non-existent air conditioner. In this way, the Nest is powered by Rc and C wires while the control is passed via the Rh and W1 wires. The final schematic follows and worked very well.

Monday, October 30, 2017

finding something in a text file

BSD and Linux have slightly different temperaments, and "find --type" didn't work under MacOS. I was trying to find the word "command" in all of my shell scripts to see how I tested if commands exists. I settled on grep:
grep --include=\*.sh -rl '.' -e 'command'