How to Design PCBs Part 2

As promised in my previous post here is the completion of my first foray into the world of PCB design. Here I will go through installing the components and testing the boards.

The Boards

The backside of the PCB

The shipping of the boards was quicker than I expected and only took about 10 days from purchase to arrival which was the lower end of JLCs estimate. They were well-packaged and the silk screen printing was all correct. These PCBs were 2 layer copper boards with an FR4 core. Furthermore, all the holes and vias were in the proper positions.

Installing Components

PCB with components installed.

I then installed the components on the board. The component holes were slightly larger than I expected. That led to a small amount of solder leakage over to the front side of the board though it was minimal. The footprint for the MOSFET was perfect and the mounting hole lined up perfectly. I also got lucky that the footprint for the screw terminals was right. I did not check it before purchase which was probably not a great idea.

Testing

Testing the board.

After installing all the components it was time for the moment of truth. Testing that after applying a 5V input to the board we would get a 3.3V output. As can be seen above that is the case. I was somewhat surprised that this was the case as I was expecting that I had made some mistakes with the design. I would make a few changes if I were to do this again though. One change I would label the positive and negative on the terminals using silkscreen. Another change would be to increase the resistance on the LED as it seems the 220Ω resistor was not quite enough and the LED was running quite bright.

Conclusion

This project has been one of the more interesting ones I have undertaken recently. I am going to make some more boards in the future. The success of this project has increased my confidence in electronics and I am excited for my next project. However, it may be a while before my next one as the University semester has started once again.

How to Design PCBs Part 1

I have always had an interest in electronics since my Grandfather introduced the hobby to me. But over the past few years, I haven’t been as active as I once was. After a night of YouTube browsing, I found myself drawn back in and decided to teach myself Print Circuit Board (PCB) Design. This stuff is different from my normal work in the software world but is an interesting learning opportunity.

Introduction

After some research and experimentation, I decided to use the open-source software package KiCAD for my design of circuits and PCBs. I found KiCAD to have numerous resources online. It is a fully featured package for circuit and PCB design that includes symbol and footprint editors. I learnt most of the basics from this video on YouTube but the forums are very active and helpful if you have specific questions.

The Circuit

Schematic of the voltage regulator.

After some time learning about the software, I decided to create a simple circuit for fabrication. Many standard power supply methods for microcontrollers use 5V. On the other hand, my Raspberry Pi Pico and many of its components use 3.3V. So I decided to create a voltage regulator.

The main component of this is the LM1117 specifically the 3.3 variant. This takes an input voltage of 1.2 to 13.8V input and outputs 3.3V. Texas Instruments also recommends a 10uF capacitor to improve the consistency of power and reduce any noise in the circuit. So I placed one of these each on the input and output. I also added an indicator LED on the output.

I/O

For input and output, I had to decide how I would input and output power from the device. The three main options I considered were pins/sockets, soldered connections, and screw terminals.

Pins and sockets are both commonly used in the world of microcontrollers and are well-suited to hobbyist and prototyping projects. They are also the IO method for many of my microcontrollers and components. However, they lack the durability and stability needed for use in more permanent projects.

Soldered connections are the most permanent and cost-effective option. But their permanence is also their biggest drawback. For a hobbyist like myself constantly having to resolder these to each project will quickly become a hassle as I jump from project to project, prototype to prototype.

The final option was screw terminals. They are the most expensive option, the ones I am using are $1.90 each, but they strike a balance between the permanence of soldered connections and the ease of change in pins. Therefore I decided to use screw terminals for this project.

Layout

Final Version of layout.

After I designed the circuit and chose the components that would be used I imported the footprints into the PCB layout software that is a part of KiCad. I decided to use a 2-layer PCB as it provides flexibility in layout. I ended up making use of this to allow traces to cross one another.

Fabrication

JLC’s model of my PCB.

For fabrication, I decided to use JLC PCB as they are both cheap and seem to have a good reputation among hobbyists. For this, I had to generate Gerber and Drill files for them. I found KiCAD made this very easy and after uploading the files and setting a few options my PCBs were ordered. In total including shipping, this cost me only $5.67 which I consider an exceedingly reasonable price for 5 PCBs printed and shipped when working on this small of an order size.

Conclusion

To conclude, I have found this project to be one of the most engaging side projects I have done in recent times. It has greatly boosted my confidence in electronics. I have learnt a great many new skills and I hope to learn more soon. I will post an update when I receive the boards going through my assembly and testing of the boards.

React QR Code Generator

React QR Code Generator in use.
React QR Code generator in action.

As a side project to keep my mind sharp while on break, I decided to work with React some more. Most of the work I have done so far was with plain react not using external libraries. I decided to work with some external packages on this project. I am also avoiding the use of APIs as they create latency and I wanted to dynamically create the QR code.


First I created a plain JS Vite project using:

npm create vite@latest

React-colorful

I found two useful libraries for this project, qr-code and colorful, which will allow me to create the QR codes and pick their colours visually. React-colorful outputs a hex value of the colour which works well with react-qr-code. React-colorful works by having the colour value as a state and the onChange as the set function. This allows my site to dynamically update the QR code when the colour values are changed.

QR Codes

The qr-code library uses a fairly simple format for generating QR codes as shown above. As the three middle variables are states any time any of them are updated the element is re-rendered. This means any time the user changes any of the three the page will dynamically update the QR code. QR codes are output as SVG tags within the HTML DOM and therefore you cannot save by right-clicking. This would be an issue if I wanted to host this site publically but the current format is fine for my learning.

Conclusion

I made a few small HTML and CSS changes that cleaned up the look of the web app and I am pretty happy with how It has turned out. React has certainly been a great tool to add to my repertoire this year. It has made the development of web applications significantly easier than the traditional PHP method that I initially learnt. It makes prototypes such as this much quicker to produce and the variety of packages and APIs available are great assets.

Side-Channel Attack on LLC

Introduction

This semester I am taking a Cyber Security class and for the final assignment, I was tasked with performing a side-channel attack on a computer’s LLC(Last Level Cache).

Much like the last assignment to simulate quantum key encryption, there are two parts to the assignment. I was to create both a program and write a short report on the assignment. My report should cover both the theory behind the attack and the effectiveness of the program I created. To write the report I used LaTeX as I have found it to be a very effective tool this semester. I am writing the program for this assignment in Java though most languages should be effective.

What is a Side-Channel Attack?

First off I should explain what a side channel attack is. A side-channel attack is a method by which one can infer information about a computer or a program using indirect methods. If you want to learn more about side-channel attacks I would highly recommend reading about the Meltdown and Spectre vulnerabilities. The example for this assignment is inferring the size of the LLC of a computer’s CPU. Therefore to perform a side channel attack I must find an indirect way to infer the size of a computer’s LLC.

My Side-Channel Attack

After reading the article we were provided with when given the assignment I then decided on using differently sized arrays. I will measure the time needed to access data in the array and this should allow me to infer the cache size. I will step through the different sizes of arrays and measure a value for each. Plotting these values should allow me to see a spike in time which means we are having cache misses.

I used arrays from 1Kb in size up to 64Mb doubling at each step. For each size I will run 100 tests, each test will consist of incrementing values in the array 1 million times. Each test will be timed and the times for each size will be averaged. This should allow us to get an accurate value for each size without running into any outliers.

We will use two different methods to determine which element of an array we access. A random method, and a sequential method. This is another requirement of the assignment is that I test multiple methods for my attack.

Side-Channel Attack output
Output of Random Access Side-Channel Attack

The Report

I wrote a short report (5-page limit) on my methodology for the attack and the results I got from said attacks. I wrote this report using LaTeX as I have found it to be a very useful tool this semester. Included in the report were graphs of my results and an analysis of my results for each method. If you wish to read it in full the PDF is available below.

Disclaimer

Though it should go without saying I will say. This is all for purely educational purposes. Do not run software of this kind on any systems you do not have permission to use. Also, ensure when testing software of this kind you are doing so in a secure environment and are in compliance with all local laws and regulations.

Regular Expression Parser and Compiler

I have been given an assignment focused on regular expressions (regexp) and parsing. This assignment is split into two parts. A parser and compiler that converts a regular expression into a set of Finite State Machines (FSM) that can then be loaded into a second piece of software that searches a piece of text for patterns that match the regular expression. I will work on the first part and my partner will work on the second.

The parser and compiler will adhere to a set of rules that have been laid out for us in the assignment document. An expression will then be run through that set of rules and the program will output a set of FSM that the second piece can then read. This will require format to be agreed with my partner but I feel this should be relatively simple. The rules for this compiler are as follows:

Rules

  • Any non-special character is a literal
  • . (period) is a wild card that can be any literal
  • adjacent regexps are concatenated to a single regexp
  • * indicates closure (zero or more) on the preceding regexp
  • ? indicates that the preceding regexp can occur zero or one times
  • | is an infix alternation operator such that if r and e are regexps r|e means r or e
  • ( and ) may enclose a regexp to raise its precedence such that (e) is a regexp that is equivilent to e
  • \ is an escape character that matches λ but indicates that the following character loses any special meaning and is a literal
  • Operator precedence is as follows:
    • Escaped characters
    • Paretheses
    • Repetition
    • Concatenation
    • Alternation
  • Optional: ! not operator

An example of this would be (r | e) a*:

State0123456
Typebrbrrebraλ
Next 1124454.
Next 213..6..
FMS Table of Regular Expression Above
Regular Expression FSM graph

I will continue to work on this over the next few weeks and provide updates as I go along with the development process.

Quantum Key Encryption Simulation in Java

Introduction

The goal of this assignment was to simulate symmetric Quantum Key Encryption. We did this by creating a Qubit class and using that to generate the key that is to be used in the XOR class we create. This will allow us to pass messages without exposing their content to the outside world. I decided to do this in Java as it is what I have the most experience in.

Qubit Class

This part of the assignment was quite simple as we were given a UML diagram for the class and were able to simply create the class based on that. It is a simple object that allows for the storage of a value and a polarisation. There is also a measure method that returns the value if the polarisation matches else it generates a new random polarisation and then returns the value.

XOR Class

This was just a simple matter of applying an XOR operation to the message using the key repeated to the end of the message.

The Encryption Algorithm

I decided to break this down into three parts. A transmitter class, a receiver class, and the main method. The transmitter creates a random stream of bytes. Then the receiver takes that stream of qubits and using random polarisation generates its stream of qubits using the values from the transmitter’s random polarisation.  Then the transmitter passes back the new qubits and each generates its key. Both keys should match. Then the main method performs the XOR encryption and decryption.

Testing

I wrote a few simple unit tests throughout the creation of this project using jUnit. These helped me to ensure all parts of the software were working as I intended and allowed me to better identify issues and bugs I found while creating software.

Encryption Unit Testing
JUnit test

Conclusion

This project was quite fun and it was interesting to learn about some of the lesser-known parts of computer science such as Quantum Computing and Encyrption. I learned a lot and look forward to studying some parts of this a bit further.

Creating a RESTful API

For a class on advanced web development, I was tasked with creating a RESTful API for events using NODE.js and Express. All the data is stored in a MySQL database and was formatted using ‘id, name, description, start date, end date’. I also created a homepage that includes the documentation for said API.

RESTful API documentation.
Homepage created for API.

I used a tool in VS Code called ‘Postman’ which allows for simple testing of APIs by allowing quick creation and viewing of HTTP requests and their responses. As this project is just a proof of concept and not meant for hosting on the web it lacks any sort of validation but allows any user to view, create, update, or delete any event in the database.

The back end is routed using Express which allows for the triggering of functions based on the URL and method of the request i.e. http://localhost:3000/events would call a function in the server that selects all events in the database.

RESTful routing code
Calls the getAll function.

This project was an interesting one and presented new challenges, I have yet to do much web development that did not involve making websites so the opportunity to create a RESTful API was great. It allowed me to learn more about the use of API’s and the formatting of HTTP requests.