Skip to content

Commit

Permalink
correlation only on AES, bug fix on chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Remote-HWA committed Mar 6, 2021
1 parent 691ea37 commit 047885b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ media/
docs/build
deploy_sca
deploy_sca.pub
.
.
src/run_on_windows.txt
2 changes: 1 addition & 1 deletion src/lib/cpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def guess_stats(cls, cor, key):
correlations : Compute temporal correlation.
"""
best = np.amax(cor, axis=2)
best = np.amax(np.absolute(cor), axis=2)
guess = np.argmax(best, axis=1)
rank = COUNT_HYP - np.argsort(np.argsort(best, axis=1), axis=1)
rank = np.array([rank[b, key[b]] for b in range(BLOCK_SIZE)])
Expand Down
38 changes: 36 additions & 2 deletions src/lib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def __init__(self, path=None, count=None, start=0):
"""

self.mode = None
self.algo = None
self.direction = None
self.target = 0
self.sensors = 0
Expand Down Expand Up @@ -386,6 +387,7 @@ def clear(self):
"""
self.mode = None
self.algo = None
self.direction = None
self.target = 0
self.sensors = 0
Expand Down Expand Up @@ -431,7 +433,7 @@ def read_csv(self, path, count=None, start=0):
row = next(reader)
except StopIteration:
return
self.mode = row[Keywords.MODE]
self.mode = row[Keywords.MODE]
self.direction = row[Keywords.DIRECTION]
self.target = int(row[Keywords.TARGET])
self.sensors = int(row[Keywords.SENSORS])
Expand Down Expand Up @@ -476,12 +478,21 @@ class Request:

ACQ_CMD_NAME = "sca"

class Algos(Enum):
AES = "aes"
PRESENT = "present"
KLEIN = "klein"
CRYPTON = "crypton"

class Modes(Enum):
HARDWARE = "hw"
TINY = "tiny"
OPENSSL = "ssl"
DHUERTAS = "dhuertas"

PRESENT = "present"
KLEIN = "klein"
CRYPTON = "crypton"

class Directions(Enum):
ENCRYPT = "enc"
DECRYPT = "dec"
Expand All @@ -498,6 +509,7 @@ def __init__(self, args=None):
self.target = ""
self.iterations = 0
self.mode = Request.Modes.HARDWARE
self.algo = Request.Algos.AES
self.model = Handler.Models.SBOX_R0
self.direction = Request.Directions.ENCRYPT
self.verbose = False
Expand All @@ -519,6 +531,7 @@ def _from_namespace(self, args):
self.target = args.target
if hasattr(args, "mode"):
self.mode = next(filter(lambda e: args.mode == e.name, Request.Modes))
self._set_algo(self.mode)
if hasattr(args, "model"):
self.model = next(filter(lambda e: args.model == e.name, Handler.Models))
if hasattr(args, "direction"):
Expand All @@ -543,6 +556,7 @@ def _from_dict(self, args):
self.target = args["target"]
if "mode" in args:
self.mode = args["mode"]
self._set_algo(self.mode)
if "model" in args:
self.model = args["model"]
if "direction" in args:
Expand All @@ -560,6 +574,26 @@ def _from_dict(self, args):
if "path" in args:
self.path = args["path"]

def _set_algo(self, mode):

if(mode == Request.Modes.HARDWARE):
self.algo = Request.Algos.AES
elif(mode == Request.Modes.TINY):
self.algo = Request.Algos.AES
elif(mode == Request.Modes.OPENSSL):
self.algo = Request.Algos.AES
elif(mode == Request.Modes.DHUERTAS):
self.algo = Request.Algos.AES
elif(mode == Request.Modes.PRESENT):
self.algo = Request.Algos.PRESENT
elif(mode == Request.Modes.KLEIN):
self.algo = Request.Algos.KLEIN
elif(mode == Request.Modes.CRYPTON):
self.algo = Request.Algos.CRYPTON
else:
print("unknown mode")


def __repr__(self):
return f"{type(self).__name__}" \
f"({self.target!r}, " \
Expand Down
19 changes: 11 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,14 @@ async def acknowledge_pending(self):
self.pending &= ~ Pending.STATISTICS
await self.show_stats()

if self.pending & Pending.CORRELATION:
self.pending &= ~ Pending.CORRELATION
self.frames.log.clear()
await self.show_corr()
await self.show_parsing()
if self.state != State.IDLE:
await self.show_starting()
if(self.request.algo == self.request.Algos.AES):
if self.pending & Pending.CORRELATION:
self.pending &= ~ Pending.CORRELATION
self.frames.log.clear()
await self.show_corr()
await self.show_parsing()
if self.state != State.IDLE:
await self.show_starting()

if self.pending & Pending.CHUNK:
self.pending &= ~ Pending.CHUNK
Expand Down Expand Up @@ -572,7 +573,7 @@ def _validate(self):

def _set(self):
self.frames.config.general.iterations = self.request.iterations
self.frames.config.perfs.chunks = self.request.chunks
self.frames.config.general.chunks = self.request.chunks
self.frames.config.general.mode = self.request.mode
self.frames.config.general.model = self.request.model
self.frames.config.target.target = self.request.target
Expand Down Expand Up @@ -633,6 +634,7 @@ async def stop(self):
logging.info(f"stopping acquisition, duration {timedelta(seconds=self.t_start - self.t_end)}")

async def show_idle(self):

if self.status & Status.VALID:
self.frames.log.var_status.set("Ready to launch acquisition !")
self.frames.unlock_launch()
Expand Down Expand Up @@ -754,6 +756,7 @@ async def show_corr(self):
lo = asyncio.get_event_loop()
app = App(lo, request=Request(argp.parse_args()))
app.title("SCABox Demo")
app.geometry("1200x800")
try:
lo.run_forever()
except KeyboardInterrupt:
Expand Down
50 changes: 39 additions & 11 deletions src/widgets/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ def _validate_chunks(self):

def validate(self):
valid = self._validate_mode()
#print("_validate_mode = %d"%valid)
valid = self._validate_model() and valid
#print("_validate_model = %d"%valid)
valid = self._validate_chunks() and valid
return self._validate_iterations() and valid
#print("_validate_model = %d"%valid)
valid =self._validate_iterations() and valid
#print("_validate_iterations = %d"%valid)
return valid


def lock(self):
self.entry_iterations["state"] = DISABLED
Expand Down Expand Up @@ -505,13 +511,15 @@ def validate(self):
valid = True
for field in self.fields:
valid = field.validate() and valid
return self._validate_freq() and valid
valid = self._validate_freq() and valid
return valid


class FilterFrame(LabelFrame):
class Mode(Enum):
AUTO = 0
MANUAL = 1
NONE = 0
AUTO = 1
MANUAL = 2

def __init__(self, master):
super().__init__(master, text="Filter")
Expand All @@ -522,36 +530,45 @@ def __init__(self, master):
self._freq = None
self.var_mode = IntVar(value=0)
self.var_freq = StringVar()

self.radio_mode_none = Radiobutton(self,
text="None",
variable=self.var_mode,
value=FilterFrame.Mode.NONE.value)
self.radio_mode_none.grid(row=0, column=0, columnspan=1, sticky=NSEW, padx=4)

self.radio_mode_auto = Radiobutton(self,
text="Auto",
variable=self.var_mode,
value=FilterFrame.Mode.AUTO.value)
self.radio_mode_auto.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=4)
self.radio_mode_auto.grid(row=0, column=1, columnspan=1, sticky=NSEW, padx=4)

self.radio_mode_manual = Radiobutton(self,
text="Manual",
variable=self.var_mode,
value=FilterFrame.Mode.MANUAL.value)
self.radio_mode_manual.grid(row=0, column=2, sticky=NSEW, padx=4)
self.radio_mode_manual.grid(row=0, column=2, columnspan=1,sticky=NSEW, padx=4)

self.freqs = FilterList(self, 4)
self.freqs = FilterList(self, 2)
self.freqs.grid(row=2, column=0, columnspan=3, sticky=NSEW)

@property
def mode(self):
return self._mode

def lock(self):
self.radio_mode_none["state"] = DISABLED
self.radio_mode_auto["state"] = DISABLED
self.radio_mode_manual["state"] = DISABLED

def unlock(self):
self.radio_mode_none["state"] = NORMAL
self.radio_mode_auto["state"] = NORMAL
self.radio_mode_manual["state"] = NORMAL

def validate(self):
self._mode = FilterFrame.Mode(value=self.var_mode.get())
if self._mode == FilterFrame.Mode.AUTO:
if self._mode == FilterFrame.Mode.AUTO or self._mode == FilterFrame.Mode.NONE:
self.freqs.lock()
return True
else:
Expand Down Expand Up @@ -758,8 +775,8 @@ class Mode(Enum):

def __init__(self, master):
super().__init__(master, text="Mode")
self._mode = PlotList.Mode.CORRELATION
self._old_mode = PlotList.Mode.CORRELATION
self._mode = PlotList.Mode.STATISTICS
self._old_mode = PlotList.Mode.STATISTICS
self.var_mode = StringVar(value=self._mode.value)
self.radios_mode = [Radiobutton(self,
text=e.value,
Expand All @@ -782,6 +799,15 @@ def validate(self):
self._mode = PlotList.Mode(value=self.var_mode.get())
return True

def lock(self):
self.radios_mode[0]["state"] = DISABLED
self.radios_mode[1]["state"] = DISABLED
self.radios_mode[2]["state"] = DISABLED

def unlock(self):
self.radios_mode[0]["state"] = NORMAL
self.radios_mode[1]["state"] = NORMAL
self.radios_mode[2]["state"] = NORMAL

class PlotOptions(LabelFrame):
class Mode(Enum):
Expand Down Expand Up @@ -878,7 +904,9 @@ def validate(self):
valid = self.target.validate() and valid
valid = self.perfs.validate() and valid
valid = self.plot.validate() and valid
return self.file.validate() and valid
valid = self.file.validate() and valid

return valid

def lock(self):
self.general.lock()
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LogFrame(LabelFrame):
def __init__(self, master):
super().__init__(master, text="Logging")
self.text_log = Text(self, state=DISABLED)
self.text_log.configure(height=18)
self.text_log.configure(height=8)
self.text_log.pack()
self.text_status = Text(self, state=DISABLED)
self.text_status.configure(height=5)
Expand Down

0 comments on commit 047885b

Please sign in to comment.