Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
23e6c280
authored
Jul 15, 2019
by
Enrico Pozzobon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
arduino uno measurements start
parent
2ec67af2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
13 deletions
+88
-13
compile_all.py
+11
-3
measurements/.mkdir
+0
-0
templates/uno/configure
+4
-2
templates/uno/src/main.ino
+8
-0
templates/uno/test
+10
-3
test.py
+55
-5
No files found.
compile_all.py
View file @
23e6c280
...
...
@@ -16,6 +16,7 @@ def build(algo_dir, template_dir):
d
=
os
.
path
.
join
(
"build"
,
r
)
if
not
os
.
path
.
isdir
(
d
):
build_dir
=
d
print
(
"Building in
%
s"
%
build_dir
)
# copy all the files from the submitted algorithm into the build directory
shutil
.
copytree
(
algo_dir
,
build_dir
)
...
...
@@ -65,6 +66,8 @@ def build(algo_dir, template_dir):
assert
p
.
returncode
==
0
finally
:
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
os
.
chdir
(
wd
)
# if execution arrives here, the build was successful
...
...
@@ -132,7 +135,7 @@ def main(argv):
# For testing, we only do the first 1
files
=
files
[:
1
]
#
files = files[:1]
# Clear the build directory as it is a leftover from the previous execution
if
os
.
path
.
isdir
(
'build'
):
...
...
@@ -148,8 +151,13 @@ def main(argv):
for
t
,
d
in
files
:
print
()
print
(
d
)
b
=
build
(
d
,
template_dir
)
test_script
.
write
(
"./test.py
%
s
%
s
\n
"
%
(
t
,
os
.
path
.
join
(
b
,
'test'
)))
try
:
b
=
build
(
d
,
template_dir
)
test_script
.
write
(
"echo
\"
TESTING
%
s
\"\n
./test.py
%
s
%
s
\n
"
%
(
d
,
t
,
os
.
path
.
join
(
b
,
'test'
)))
print
(
"COMPILATION SUCCESS FOR
%
s"
%
d
)
except
Exception
:
print
(
"COMPILATION FAILED FOR
%
s"
%
d
)
st
=
os
.
stat
(
test_script_path
)
os
.
chmod
(
test_script_path
,
st
.
st_mode
|
stat
.
S_IEXEC
)
...
...
measurements/.mkdir
0 → 100644
View file @
23e6c280
templates/uno/configure
View file @
23e6c280
#!/bin/bash
mv
*
.c src/
mv
*
.h include/
mv
-n
*
.c
*
.C
*
.s
*
.S src/
mv
-n
*
.h
*
.H include/
sed
-i
src/encrypt.c
-e
"s/
\(\s\)
init(/
\1
_init(/g"
exit
0
templates/uno/src/main.ino
View file @
23e6c280
...
...
@@ -96,14 +96,22 @@ void loop() {
case
'p'
:
assert
(
l
==
CRYPTO_NPUBBYTES
);
memcpy
(
npub
,
var
,
l
);
break
;
case
's'
:
assert
(
l
==
CRYPTO_NSECBYTES
);
memcpy
(
nsec
,
var
,
l
);
break
;
case
'e'
:
noInterrupts
();
asm
(
"nop"
);
digitalWrite
(
LED_BUILTIN
,
LOW
);
res
=
crypto_aead_encrypt
(
c
,
&
clen
,
m
,
mlen
,
ad
,
adlen
,
nsec
,
npub
,
k
);
digitalWrite
(
LED_BUILTIN
,
HIGH
);
asm
(
"nop"
);
interrupts
();
break
;
case
'd'
:
noInterrupts
();
asm
(
"nop"
);
digitalWrite
(
LED_BUILTIN
,
LOW
);
res
=
crypto_aead_decrypt
(
m
,
&
mlen
,
nsec
,
c
,
clen
,
ad
,
adlen
,
npub
,
k
);
digitalWrite
(
LED_BUILTIN
,
HIGH
);
asm
(
"nop"
);
interrupts
();
break
;
case
'M'
:
var
=
m
;
rl
=
mlen
;
break
;
case
'C'
:
var
=
c
;
rl
=
clen
;
break
;
...
...
templates/uno/test
View file @
23e6c280
...
...
@@ -2,6 +2,7 @@
import
os
import
sys
import
time
import
struct
import
serial
import
subprocess
...
...
@@ -12,9 +13,12 @@ def eprint(*args, **kargs):
print
(
*
args
,
file
=
sys
.
stderr
,
**
kargs
)
def
flash
():
def
flash
(
tty
=
None
):
pipe
=
subprocess
.
PIPE
p
=
subprocess
.
Popen
([
'platformio'
,
'run'
,
'-e'
,
'uno'
,
'--target'
,
'upload'
],
cmd
=
[
'platformio'
,
'run'
,
'-e'
,
'uno'
,
'--target'
,
'upload'
]
if
tty
is
not
None
:
cmd
.
extend
([
'--upload-port'
,
tty
])
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
sys
.
stderr
,
stdin
=
pipe
)
stdout
,
stderr
=
p
.
communicate
(
""
)
...
...
@@ -105,9 +109,12 @@ def main(argv):
script_dir
=
os
.
path
.
split
(
argv
[
0
])[
0
]
if
len
(
script_dir
)
>
0
:
os
.
chdir
(
script_dir
)
flash
()
dev
=
get_serial
()
flash
(
dev
)
eprint
(
"Flashed"
)
time
.
sleep
(
1
)
ser
=
serial
.
Serial
(
dev
,
baudrate
=
115200
,
timeout
=
5
)
uartp
=
UARTP
(
ser
)
...
...
test.py
View file @
23e6c280
...
...
@@ -7,14 +7,34 @@ import struct
from
subprocess
import
Popen
,
PIPE
def
main
(
argv
):
if
len
(
argv
)
<
3
:
print
(
"Usage: test.py LWC_AEAD_KAT.txt program [arguments]"
)
test_file
=
open
(
argv
[
1
],
'r'
)
p
=
Popen
(
argv
[
2
:],
bufsize
=
0
,
stdin
=
PIPE
,
stdout
=
PIPE
)
cmd
=
argv
[
2
:]
for
attempt
in
range
(
3
):
print
(
"beginning test
%
d of '
%
s' using test vectors '
%
s'"
%
(
attempt
,
' '
.
join
(
cmd
),
argv
[
1
]))
measurements
=
begin_measurement
()
try
:
test
(
test_file
,
cmd
)
print
(
"TEST SUCCESSFUL"
)
return
0
except
Exception
as
ex
:
print
(
str
(
ex
))
print
(
"TEST FAILED"
)
finally
:
end_measurement
(
measurements
)
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
return
1
def
test
(
test_file
,
cmd
):
p
=
Popen
(
cmd
,
bufsize
=
0
,
stdin
=
PIPE
,
stdout
=
PIPE
)
def
write
(
data
):
l
=
p
.
stdin
.
write
(
data
)
...
...
@@ -22,6 +42,8 @@ def main(argv):
raise
Exception
(
"could not write
%
d bytes of data (put
%
d)"
%
(
len
(
data
),
l
))
def
read
(
l
):
if
l
==
0
:
return
b
""
data
=
p
.
stdout
.
read
(
l
)
if
len
(
data
)
==
0
:
print
(
"Unexpected end of stream"
,
file
=
sys
.
stderr
)
...
...
@@ -40,8 +62,9 @@ def main(argv):
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
return
read
(
l
)
if
read
(
14
)
!=
b
"Hello, World!
\n
"
:
raise
Exception
(
"Unexpected output"
)
output
=
read
(
14
)
if
output
!=
b
"Hello, World!
\n
"
:
raise
Exception
(
"Unexpected output:
%
s"
%
output
)
print
(
"Ready"
)
m
=
b
""
...
...
@@ -110,6 +133,33 @@ def main(argv):
else
:
print
(
"ERROR: unparsed line in test vectors file: '
%
s'"
%
line
)
def
begin_measurement
():
import
saleae
import
time
sal
=
saleae
.
Saleae
()
sal
.
set_active_channels
([
0
,
1
],
[])
sal
.
set_sample_rate
(
sal
.
get_all_sample_rates
()[
0
])
sal
.
set_capture_seconds
(
6000
)
sal
.
capture_start
()
time
.
sleep
(
1
)
return
sal
def
end_measurement
(
sal
):
import
time
time
.
sleep
(
1
)
sal
.
capture_stop
();
while
not
sal
.
is_processing_complete
():
pass
outfile
=
"measurement_
%
s.csv"
%
time
.
strftime
(
"
%
Y
%
m
%
d-
%
H
%
M
%
S"
)
outfile
=
os
.
path
.
join
(
"measurements"
,
outfile
)
if
os
.
path
.
isfile
(
outfile
):
os
.
unlink
(
outfile
)
sal
.
export_data2
(
os
.
path
.
abspath
(
outfile
))
print
(
"Measurements written to '
%
s'"
%
outfile
)
mdbfile
=
os
.
path
.
join
(
"measurements"
,
"measurements.txt"
)
mdbfile
=
open
(
mdbfile
,
"a"
)
mdbfile
.
write
(
"
%
s >
%
s
\n
"
%
(
' '
.
join
(
sys
.
argv
),
outfile
))
mdbfile
.
close
()
if
__name__
==
"__main__"
:
sys
.
exit
(
main
(
sys
.
argv
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment