-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_linux_tvs.sh
executable file
·76 lines (71 loc) · 1.91 KB
/
create_linux_tvs.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
#!/usr/bin/env bash
# Script to generate Linux test vectors
CURVE="secp521r1"
for hash in sha1 sha224 sha256 sha384 sha512; do
openssl req \
-x509 \
-${hash} \
-newkey ec \
-pkeyopt ec_paramgen_curve:${CURVE} \
-keyout key.pem \
-days 365 \
-subj '/CN=test' \
-nodes \
-outform der \
-out cert.der
# key
line=$(openssl asn1parse -in cert.der -inform der |
grep "BIT STRING" | head -n1)
#echo $line
skip=$(echo $line | cut -d":" -f1)
#echo $skip
hl=$(echo $line | sed -n 's/.*hl=\s*\([^ ]*\).*/\1/p')-2
length=$(echo $line | sed -n 's/.*l=\s*\([^ ]*\).*/\1/p')
#echo "l=$length"
echo -e "\t.key ="
dd bs=1 count=$((length-1)) skip=$((skip+3+hl)) if=cert.der 2>/dev/null |
od -tx1 |
sed -n "s/^[0-9]\{7\} \(.*\)$/\t\" \1/p" |
sed -n "s/ \([0-9a-f]\)/\\\x\1/gp"
echo ","
echo -e "\t.key_len = $((length-1)),"
#openssl asn1parse -in cert.der -inform der
line=$(openssl asn1parse -in cert.der -inform der 2>&1|
grep id-ecPublicKey -B1 |
head -n1)
#echo $line
skip=$(echo $line | cut -d":" -f1)
#echo $skip
length=$(echo $line | sed -n 's/.*l=\s*\([^ ]*\).*/\1/p')
#echo "l=$length"
echo -e "\t.params ="
dd bs=1 count=$((length+2)) skip=$skip if=cert.der 2>/dev/null |
od -tx1 |
sed -n "s/^[0-9]\{7\} \(.*\)$/\t\" \1/p" |
sed -n "s/ \([0-9a-f]\)/\\\x\1/gp"
echo ","
echo -e "\t.param_len = $((length + 2)),"
message="${RANDOM}${RANDOM}"
echo -e "\t.m ="
echo -en "${message}" |
openssl dgst \
-${hash} | \
sed -n "s/.*= \(.*\)$/\t\"\1/p" | \
sed -n "s/[0-9a-f]\{2\}/\\\x\0/pg"
echo ","
echo -e "\t.m_size = ,"
echo -e "\t.algo = OID_id_ecdsa_with_${hash},"
# get the signature
echo -e "\t.c ="
echo -en "${message}" |
openssl dgst \
-${hash} \
-sign key.pem |
od -tx1 |
sed -n "s/^[0-9]\{7\} \(.*\)$/\t\" \1/p" |
sed -n "s/ \([0-9a-f]\)/\\\x\1/gp"
echo ","
echo -e "\t.c_size = ,"
echo -e "\t.public_key_vec = true,"
echo -e "\t.siggen_sigver_test = true,"
done