Hardware attacks and countermeasures