Skip to content

Commit 6ad4c73

Browse files
author
lolololol
committed
fucken
1 parent 81248c1 commit 6ad4c73

File tree

13 files changed

+71
-56
lines changed

13 files changed

+71
-56
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ lib/dist/
33
lib/build/
44
lib/sparkgap.egg-info/
55

6+
# fuck right off emu elf files
7+
emu/*.elf
8+
emu/*.hdf
9+
610
# go away preprocessor files
711
*.hdf
812
**/*.hdf

clkfriend.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
import numpy
4+
import getopt
5+
import sys
6+
7+
def usage():
8+
print("todo: usage")
9+
10+
if __name__ == "__main__":
11+
if len(sys.argv) == 1:
12+
usage()
13+
sys.exit(0)
14+
opts, args = getopt.getopt(sys.argv[1:],"f:t:",["from=","to="])
15+
for arg, val in opts:
16+
if arg in ["-f","--from"]:
17+
FROM_VAL = val
18+
elif arg in ["-t","--to"]:
19+
TO_VAL = val
20+

cpa.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def usage():
141141
out += "%02x " % int(r[i])
142142
print("Done: %s" % out)
143143
out = ""
144+
if hasattr(leakmodel,"postprocess"):
145+
leakmodel.postprocess(r)
144146
if CONFIG_PLOT:
145147
resultViz.render()
146148
resultViz.mainloop()

dpa.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ def usage():
140140
out += "%02x " % int(r[i])
141141
print("Done: %s" % out)
142142
out = ""
143-
out = ""
143+
if hasattr(leakmodel,"postprocess"):
144+
leakmodel.postprocess(r)
144145
if CONFIG_PLOT:
145146
resultViz.render()
146147
resultViz.mainloop()

emu/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# teacup
1+
# emu
22

3-
Camellia sinensis is a species of evergreen shrub or small tree in the flowering plant family Theaceae. Its leaves and leaf buds are used to produce the popular beverage tea. Common names include tea plant, tea shrub, and tea tree (unrelated to Melaleuca alternifolia, the source of tea tree oil, or the genus Leptospermum commonly called tea tree).
3+
This folder contains experiments for software-emulated side channel, using Ledger-Donjon's Rainbow framework. The example executable is DES. You can compile this with:
44

5-
arm-none-eabi-gcc -nostdlib -o hello.elf hello.c
5+
arm-none-eabi-gcc -nostdlib -o des.elf des.c

emu/aes.elf

-41.7 KB
Binary file not shown.

emu/des.elf

-37.2 KB
Binary file not shown.

emu/des_loader.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@
3434

3535
cs = None
3636

37-
KEY_ADDR = 0x18cb8
38-
DATA_ADDR = 0x18cc0
39-
OUT_ADDR = 0x18cb0
37+
KEY_ADDR = 0x18ce8
38+
DATA_ADDR = 0x18cd0
39+
OUT_ADDR = 0x18ce0
4040

41-
# DODES_END = 0x8974 # WHOLE
42-
DODES_END = 0x8668 # FIRSTROUND
41+
DODES_END = 0x8974 # WHOLE
42+
# DODES_END = 0x8668 # FIRSTROUND
4343

44-
45-
# rand_key = np.array([random.randint(0,0xFF) for i in range(0,8)],dtype=np.uint8)
4644
rand_key = np.array([0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88])
4745
key_str = " ".join(["%02x" % x for x in rand_key])
4846

@@ -57,24 +55,22 @@
5755
rand_key = np.array([random.randint(0,0xFF) for i in range(0,8)],dtype=np.uint8)
5856
key_str = " ".join(["%02x" % x for x in rand_key])
5957
print("Key is %s" % key_str)
60-
emu[KEY_ADDR] = bytes(rand_key[0:4])
61-
emu[KEY_ADDR+4] = bytes(rand_key[4:8])
62-
rand_input = np.array([random.randint(0,0xFF) for i in range(0,8)],dtype=np.uint8)
63-
emu[DATA_ADDR] = bytes(rand_input[0:4])
64-
emu[DATA_ADDR + 4] = bytes(rand_input[4:8])
65-
emu.start(emu.functions["doDESEncrypt"] , DODES_END)
58+
out_data = emu[DATA_ADDR:DATA_ADDR+8]
59+
print("%s" % binascii.hexlify(out_data))
60+
emu.start(0x8954 , DODES_END)
6661
new_trace = np.fromiter(map(lambda event: event["register"], emu.trace),dtype=np.float32)
67-
rand_output = emu[OUT_ADDR:OUT_ADDR+8]
62+
out_output = emu[OUT_ADDR:OUT_ADDR+8]
6863
if cs is None:
6964
cs = sparkgap.filemanager.CaptureSet(tracecount=CONFIG_COUNT,samplecount=len(new_trace),in_len=8,out_len=8)
70-
cs.addTrace(new_trace,rand_input,rand_output)
65+
cs.addTrace(new_trace,rand_input,out_output)
7166
else:
72-
cs.addTrace(new_trace,rand_input,rand_output)
73-
print("Run %d/%d, %s -> %s" % (i,CONFIG_COUNT,binascii.hexlify(rand_input),binascii.hexlify(rand_output)))
67+
cs.addTrace(new_trace,rand_input,out_output)
68+
print("Run %d/%d, %s -> %s" % (i,CONFIG_COUNT,binascii.hexlify(rand_input),binascii.hexlify(out_output)))
7469
del(emu)
7570
gc.collect()
7671

77-
cs.save(CONFIG_OUTFILE)
72+
if CONFIG_OUTFILE != "q":
73+
cs.save(CONFIG_OUTFILE)
7874

7975
if CONFIG_REKEY is False:
8076
print("Reminder: key is %s" % key_str)

emu/des_test.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

emu/src/des.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// #include <stdio.h>
2+
13
/* des.c */
24
/*
35
This file is part of the ARM-Crypto-Lib.
@@ -398,19 +400,26 @@ void tdes_dec(void *out, void *in, const uint8_t *key){
398400

399401
/******************************************************************************/
400402

401-
uint8_t in[8] = {0,0,0,0,0,0,0,0};
402-
uint8_t out[8] = {1,1,1,1,1,1,1,1};
403-
uint8_t key[8] = {2,2,2,2,2,2,2,2};
403+
uint8_t in[8] = {0xaa,0xbb,0xcc,0xdd,0xaa,0xbb,0xcc,0xdd};
404+
uint8_t out[8] = {0x41,0x41,0x41,0x41,0x42,0x42,0x42,0x42};
405+
// uint8_t out[8] = {0x00,0x00,0x00,0x00,0x22,0x22,0x22,0x22};
406+
uint8_t key[8] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
404407

405408
void doDESEncrypt()
406409
{
407-
des_enc(out,in,key);
410+
des_enc(&out,&in,&key);
411+
return;
408412
}
409413

410414
int main(int argc, char **argv)
411415
{
412-
doDESEncrypt();
413-
while(1)
416+
des_enc(&out,&in,&key);
417+
/*
418+
int i = 0;
419+
for(i = 0;i < 8;i++)
414420
{
421+
printf("%02x ",out[i]);
415422
}
423+
printf("\n");
424+
*/
416425
}

0 commit comments

Comments
 (0)