forked from Centre-for-Hardware-Security/resynthesis_attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_TroMUX_input.sh
executable file
·76 lines (62 loc) · 1.88 KB
/
helper_TroMUX_input.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
## settings
#####
# NOTE points to path where this script resides; https://stackoverflow.com/a/246128
pwd_="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
## NOTE/TODO these parameters are to be revised to match the setup at your end
source $pwd_/settings.sh
## check all parameters
#####
if [ $# -lt 1 ]; then
echo 'Parameters required:'
echo '1) Full path for locked verilog file.'
exit
fi
#
file_in=$1
if ! [[ -e $file_in ]]; then
echo "Input file does not exist; check the provided path: \"$file_in\"."
exit 1
elif [[ $file_in != *"/"* ]]; then
echo "Input file is lacking path; check the provided path: \"$file_in\"."
exit 1
elif [[ $file_in != *".v" ]]; then
echo "Input file seems to not be a verilog file; check the provided path: \"$file_in\"."
exit 1
fi
## derive runtime parameters
#####
# NOTE file name w/o path, w/ suffix
file_in_wo_path=${file_in##*/}
# NOTE file name w/o path, w/o suffix
file_in_name=${file_in_wo_path%.*}
# NOTE path name
file_in_path=${file_in%/*}
## dbg
#echo $file_in_wo_path
#echo $file_in_name
#echo $file_in_path
#exit
## main code
#####
# 1) extract key from other file
##
correct_key_string_txt=$(tail -n 1 $file_in_path/private_key.txt)
if [[ $correct_key_string_txt == "" ]]; then
echo "Input file does not contain a line with the correct key; check the provided path: \"$file_in_path/private_key.txt\"."
exit 1
fi
# extract actual key bits
correct_key_string=$(echo $correct_key_string_txt | tr -d '[:blank:]')
# 2) convert verilog to bench
##
# NOTE use semaphore here as we're not operating in an actual work dir yet
$convert $file_in v2b y
# 3) embed correct key into bench
##
correct_key_string_bench="#key=$correct_key_string"
sed -i "1i$correct_key_string_bench" $file_in_name".v2b.bench"
# 4) arrange files into original input files folder
##
mv $file_in_name".v2b.bench" $file_in_name".bench"
mv $file_in_name"."* $file_in_path/