Skip to content

Commit 947c0c1

Browse files
committed
Add explicit EC test
Signed-off-by: manison <[email protected]>
1 parent 669ff5e commit 947c0c1

7 files changed

+176
-2
lines changed

.reuse/dep5

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Files: **/Makefile.am
1919
tests/Makefile.am
2020
tests/README
2121
tests/openssl.cnf.in
22+
tests/explicit_ec.*
2223
.clang-format
2324
.clang-format-ignore
2425
packaging/pkcs11-provider.spec

tests/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ tmp.softhsm:
5252
dist_check_SCRIPTS = \
5353
helpers.sh setup-softhsm.sh setup-softokn.sh softhsm-proxy.sh \
5454
test-wrapper tbasic tcerts tecc tecdh tedwards tdemoca thkdf \
55-
toaepsha2 trsapss tdigest ttls tpubkey tfork turi trand
55+
toaepsha2 trsapss tdigest ttls tpubkey tfork turi trand tecxc
5656

5757
test_LIST = \
5858
basic-softokn basic-softhsm \
@@ -72,7 +72,7 @@ test_LIST = \
7272
rand-softokn rand-softhsm \
7373
readkeys-softokn readkeys-softhsm \
7474
tls-softokn tls-softhsm \
75-
uri-softokn uri-softhsm
75+
uri-softokn uri-softhsm ecxc-softhsm
7676

7777
.PHONY: $(test_LIST)
7878

tests/explicit_ec.cnf

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
asn1=SEQUENCE:ec_param
2+
3+
[ec_param]
4+
version=INTEGER:1
5+
fieldID=SEQUENCE:fieldID
6+
curve=SEQUENCE:curve
7+
base_point=FORMAT:HEX,OCTETSTRING:043981fb5d14d3808971275dea9831573301cba0117bea9ab25ef767e188fb4a659d4693e1d27edb94bead8c345db51799
8+
point_order=INTEGER:0x2fbe975bf5652816348bcaf164dc6772e88e010fa5c95c21
9+
cof=INTEGER:0x04
10+
11+
[fieldID]
12+
oid=OID:1.2.840.10045.1.1
13+
p=INTEGER:0x00befa5d6fd594a058d22f2bc4c22009a83685639a85a54d7d
14+
15+
[curve]
16+
a=FORMAT:HEX,OCTETSTRING:6f54e1bd75f76fb5d11bec084bd18f94e68e9e02db73852a
17+
b=FORMAT:HEX,OCTETSTRING:657510e059c61603405486c8a7550ca6530aed3c98a51763

tests/explicit_ec.key.der

268 Bytes
Binary file not shown.

tests/explicit_ec.pub.der

245 Bytes
Binary file not shown.

tests/setup-softhsm.sh

+28
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,30 @@ echo "${ECPRI2URI}"
307307
echo "${ECCRT2URI}"
308308
echo ""
309309

310+
title PARA "generate explicit EC key pair"
311+
KEYID='0007'
312+
URIKEYID="%00%07"
313+
ECXCRT="${TMPPDIR}/ecExplicitCert"
314+
ECXCRTN="ecExplicitCert"
315+
316+
pkcs11-tool --write-object=explicit_ec.key.der --type=privkey --login --pin=$PINVALUE --module="$P11LIB" \
317+
--label="${ECXCRTN}" --id="$KEYID"
318+
pkcs11-tool --write-object=explicit_ec.pub.der --type=pubkey --login --pin=$PINVALUE --module="$P11LIB" \
319+
--label="${ECXCRTN}" --id="$KEYID"
320+
#ca_sign $ECXCRT $ECXCRTN "My Explicit EC Cert" $KEYID
321+
322+
ECXBASEURI="pkcs11:id=${URIKEYID}"
323+
ECXPUBURI="pkcs11:type=public;id=${URIKEYID}"
324+
ECXPRIURI="pkcs11:type=private;id=${URIKEYID}"
325+
#ECXCRTURI="pkcs11:type=cert;object=${ECXCRTN}"
326+
327+
title LINE "EXPLICIT EC PKCS11 URIS"
328+
echo "${ECXBASEURI}"
329+
echo "${ECXPUBURI}"
330+
echo "${ECXPRIURI}"
331+
#echo "${ECXCRTURI}"
332+
echo ""
333+
310334
title PARA "Show contents of softhsm token"
311335
echo " ----------------------------------------------------------------------------------------------------"
312336
pkcs11-tool -O --login --pin=$PINVALUE --module="$P11LIB"
@@ -375,6 +399,10 @@ export ECBASE2URI="${ECBASE2URI}"
375399
export ECPRI2URI="${ECPRI2URI}"
376400
export ECCRT2URI="${ECCRT2URI}"
377401
402+
export ECXBASEURI="${ECXBASEURI}"
403+
export ECXPUBURI="${ECXPUBURI}"
404+
export ECXPRIURI="${ECXPRIURI}"
405+
378406
# for listing the separate pkcs11 calls
379407
#export PKCS11SPY="${PKCS11_PROVIDER_MODULE}"
380408
#export PKCS11_PROVIDER_MODULE=/usr/lib64/pkcs11-spy.so

tests/tecxc

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash -e
2+
# Copyright (C) 2023 Simo Sorce <[email protected]>
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
source ${TESTSSRCDIR}/helpers.sh
6+
7+
title PARA "Export EC Public key to a file"
8+
ossl 'pkey -in $ECXPUBURI -pubin -pubout -out ${TMPPDIR}/ecout.pub'
9+
title LINE "Print EC Public key from private"
10+
ossl 'pkey -in $ECXPRIURI -pubout -text' output
11+
FAIL=0
12+
echo $output | grep "PKCS11 EC Public Key (190 bits)" > /dev/null 2>&1 || FAIL=1
13+
if [ $FAIL -eq 1 ]; then
14+
echo "Pkcs11 encoder function failed"
15+
echo
16+
echo "Original command output:"
17+
echo "$output"
18+
echo
19+
exit 1
20+
fi
21+
22+
title PARA "Sign and Verify with provided Hash and EC"
23+
ossl '
24+
pkeyutl -sign -inkey "${ECXBASEURI}"
25+
-in ${TMPPDIR}/sha256.bin
26+
-out ${TMPPDIR}/sha256-ecsig.bin'
27+
28+
ossl '
29+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
30+
-in ${TMPPDIR}/sha256.bin
31+
-sigfile ${TMPPDIR}/sha256-ecsig.bin'
32+
33+
ossl '
34+
pkeyutl -verify -inkey "${TMPPDIR}/ecout.pub" -pubin
35+
-in ${TMPPDIR}/sha256.bin
36+
-sigfile ${TMPPDIR}/sha256-ecsig.bin'
37+
38+
title PARA "DigestSign and DigestVerify with ECC (SHA-256)"
39+
ossl '
40+
pkeyutl -sign -inkey "${ECXBASEURI}"
41+
-digest sha256
42+
-in ${RAND64FILE}
43+
-rawin
44+
-out ${TMPPDIR}/sha256-ecdgstsig.bin'
45+
ossl '
46+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
47+
-digest sha256
48+
-in ${RAND64FILE}
49+
-rawin
50+
-sigfile ${TMPPDIR}/sha256-ecdgstsig.bin'
51+
52+
title PARA "DigestSign and DigestVerify with ECC (SHA-384)"
53+
ossl '
54+
pkeyutl -sign -inkey "${ECXBASEURI}"
55+
-digest sha384
56+
-in ${RAND64FILE}
57+
-rawin
58+
-out ${TMPPDIR}/sha384-ecdgstsig.bin'
59+
ossl '
60+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
61+
-digest sha384
62+
-in ${RAND64FILE}
63+
-rawin
64+
-sigfile ${TMPPDIR}/sha384-ecdgstsig.bin'
65+
66+
title PARA "DigestSign and DigestVerify with ECC (SHA-512)"
67+
ossl '
68+
pkeyutl -sign -inkey "${ECXBASEURI}"
69+
-digest sha512
70+
-in ${RAND64FILE}
71+
-rawin
72+
-out ${TMPPDIR}/sha512-ecdgstsig.bin'
73+
ossl '
74+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
75+
-digest sha512
76+
-in ${RAND64FILE}
77+
-rawin
78+
-sigfile ${TMPPDIR}/sha512-ecdgstsig.bin'
79+
80+
title PARA "DigestSign and DigestVerify with ECC (SHA3-256)"
81+
ossl '
82+
pkeyutl -sign -inkey "${ECXBASEURI}"
83+
-digest sha3-256
84+
-in ${RAND64FILE}
85+
-rawin
86+
-out ${TMPPDIR}/sha3-256-ecdgstsig.bin'
87+
ossl '
88+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
89+
-digest sha3-256
90+
-in ${RAND64FILE}
91+
-rawin
92+
-sigfile ${TMPPDIR}/sha3-256-ecdgstsig.bin'
93+
94+
title PARA "DigestSign and DigestVerify with ECC (SHA3-384)"
95+
ossl '
96+
pkeyutl -sign -inkey "${ECXBASEURI}"
97+
-digest sha3-384
98+
-in ${RAND64FILE}
99+
-rawin
100+
-out ${TMPPDIR}/sha3-384-ecdgstsig.bin'
101+
ossl '
102+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
103+
-digest sha3-384
104+
-in ${RAND64FILE}
105+
-rawin
106+
-sigfile ${TMPPDIR}/sha3-384-ecdgstsig.bin'
107+
108+
title PARA "DigestSign and DigestVerify with ECC (SHA3-512)"
109+
ossl '
110+
pkeyutl -sign -inkey "${ECXBASEURI}"
111+
-digest sha3-512
112+
-in ${RAND64FILE}
113+
-rawin
114+
-out ${TMPPDIR}/sha3-512-ecdgstsig.bin'
115+
ossl '
116+
pkeyutl -verify -inkey "${ECXBASEURI}" -pubin
117+
-digest sha3-512
118+
-in ${RAND64FILE}
119+
-rawin
120+
-sigfile ${TMPPDIR}/sha3-512-ecdgstsig.bin'
121+
122+
title PARA "Test CSR generation from private ECC keys"
123+
ossl '
124+
req -new -batch -key "${ECXPRIURI}" -out ${TMPPDIR}/ecdsa_csr.pem'
125+
ossl '
126+
req -in ${TMPPDIR}/ecdsa_csr.pem -verify -noout'
127+
128+
exit 0

0 commit comments

Comments
 (0)