Thursday 23 April 2015

HARDWARE SECURITY


For any electronic system to be secure it not only need to  have secure software but also need to be secure at the  Hardware level and Hardware security is an emerging issue.lets understand the difference between a secure and insecure system with the help of an example
Lets say we have to implement a 3 input encoder that assigns a 2-bit code to each of the three different input combinations. Here X,Y,Z are the inputs to the system and a and b are the outputs

If we look at the table we have used only 3 combinations of  X Y Z but there are 2^3 = 8 combinations possible with these inputs. But here the rest of the inputs are don't care .
If you will solve this system using K-map you will find following logical expression

a=x'yz' +xy'z'=(x(XOR)y)z'
b=x'y'z+xy'z'=(x(XOR)y'

But if you will analyse the  table closely there is another possible expression which is as following

a=z'  b=y'

Now lets compare these two versions ,on the first sight you might feel that the second implementation i.e a=z' and b=y' is a better implementation . Since it will require lesser number of gates which in turn means lesser propagation delay and hence faster system,lesser hardware so cheaper system,lesser space consumption. So it will be a fantastic reduction Isn't it?

But if you would really broaden your perspective and if you will look from the perspective of security this lower implementation is more vulnerable and it is more easy for a potnential intruder to find a back door.

Lets look at the problem
Here we have defined 3 input combinations. for 1,0,0 as input the output is 1,1. But there is another input combination 0,0,0 which we have not defined the system for,but can give the same output . So this is a potential backdoor.
Secondly if we give 011 or 111 is input the system gives 00 as output and  if this output is fed into another part of the system which doesn't expect this input there may arise undesirable things. Such type of attack is called a fault injection attack.

So with this small example we can understand that there is a trade off between the performance and security. Most of the time while making the system secure we have to add some extra overhead.

On the software side there is  more awareness about the vulnerabilities and techniques to fix them.With the software you may run software to test for virus and trojan horse.But on the hardware layer the first thing which is the detection of a vulnerability is very difficult once the final hardware is in your hand. . A complete trust can be only obtained if you have control over the whole development life cycle and again having control over the complete design cycle is very difficult job.
Vulnerabilities may arise in the hardware from the microchip supply chain.Someone can place a back door during the fabrication. Often the fabrication is done off shore in the areas where it can happen cheaply but it makes it difficult to control the design process. The IP and CAD design tools that are used to implement the hardware must be from a trusted source Improper implementation of logic like we saw in the above example is another cause of vulnurability.








Friday 3 April 2015

Arduino Tips & Tricks

Part1: Using buttons in a Reliable way.


Buttons are an integral part of any system. Although now we are more into touch panels and touch screens but still they are there in slightly older systems and may be their count will drop down considerably but they will remain part of newer systems too. So it is good to understand them.

There are two key issues that arise while dealing with buttons.
1. Switch debounce. This is a issue that arise when you press a switch to open it or close it. Spurious signals or sometimes termed as spikes arise when contacts are made or broken. This results in false detection of state.
2. Non usage of pull-ups or pull downs. This  also leads to a state which is un-deterministic.

So these are the problems that I am going to discuss and the measures you should take to eradicate these issues.If you couldn't understand some pieces of what i wrote just don’t worry keep reading and you will get it after you read the examples below.

Example 1:
In this example we will read the state of pin 5 on arduino and will toggle the state of LED on pin 13 according to the state of pin 5. The circuit diagram is as below.


 Here as you see a button is connected to pin 5 and there is a resistor of 20k. This resistor is technically called a pull down resistor. When the button is pressed circuit is completed and  there is a voltage drop across the 20k resistor and this voltage drop should be more than 2.5V. If it is so the state of pin 5 will be read as HIGH by the controller otherwise the state will be read as LOW and you can use this information to switch on or off any LED or anything else. If we donot use the 20k resistor then when the button is not pressed the state of pin 5 will be undeterministic  but as there is a resistance here which pulls down the state of pin 5 to ground when button is not pressed so the indeterministic state is avoided. 

Below is a code that turns the LED on and off based on the state of pin 5
const int ledPin = 13; // choose the pin for the LED     ///#D80E49
const int inputPin = 5; // choose the input pin (for a pushbutton)
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(ledPin, HIGH); // turn LED on if switch is pressed
}
else
{
digitalWrite(ledPin, LOW); // turn LED off
}
}

Here you saw the that a pulldown resistor( or a pullup resistor which is connected to Vcc instead of gnd) is very necessary. Run the above code without this resistor and you can yourself see the difference it creates. 


USING INTERNAL PULL UPS

There are internal pull up resistors available inside the the microcontroller on any arduino board. They can be activated if you want to and in that case you will not have to add an external resistor. To activate it you have to make the state of pin set as input to HIGH in the setup function of arduino.


CODE:
Look at the line  6.
const int ledPin = 13; // output pin for the LED
const int inputPin = 5; // input pin for the switch
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
digitalWrite(inputPin,HIGH); // turn on internal pull-up on the inputPin
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(ledPin, HIGH); // turn LED OFF
}
else
{
digitalWrite(ledPin, LOW); // turn LED ON
}
}
so that solves for this time .