3 ;; Copyright (C) 2016 g10 Code GmbH
5 ;; This file is part of GnuPG.
7 ;; GnuPG is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GnuPG is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, see <http://www.gnu.org/licenses/>.
20 (load (with-path "defs.scm"))
21 (setup-legacy-environment)
23 (define keygrips '("8E06A180EFFE4C65B812150CAF19BF30C0689A4C"
24 "E4403F3FD7A443FAC29FEF288FA0D20AC212851E"
25 "0B7554421FFB14A06CB9F63FB49A85A58E97ABAC"
26 "303ACC892C2D786C8A789677C0BE54DA8538F903"
27 "9FE5C36985351524B6AFA19FDCBC1A3A750B6F5F"
28 "145A52CC7ED3FD41C5B0A26BE220FEED36AF24DE"))
29 (define mainkeyids '("BAA59D9C" "0F54719F" "45AF2FFE"))
31 (unless (have-pubkey-algo? "ECDH")
32 (skip "No ECC support due to an old Libgcrypt"))
34 (info "Preparing for ECC test")
37 (catch '() (unlink (string-append "private-keys-v1.d/" grip ".key")))
38 (call-check `(,(tool 'gpg-preset-passphrase)
39 --preset --passphrase ecc ,grip)))
42 (info "Importing ECC public keys")
45 (call `(,(tool 'gpg) --delete-key --batch --yes ,keyid)))
50 (call-check `(,(tool 'gpg) --import
51 ,(in-srcdir (string-append
52 "samplekeys/ecc-sample-"
57 ;; The following is an opaque ECDSA signature on a message "This is one
58 ;; line\n" (17 byte long) by the primary 256 bit key:
59 (define msg_opaque_signed_256 "-----BEGIN PGP MESSAGE-----
60 Version: GnuPG v2.1.0-ecc (GNU/Linux)
62 owGbwMvMwCHMvVT3w66lc+cwrlFK4k5N1k3KT6nUK6ko8Zl8MSEkI7NYAYjy81IV
63 cjLzUrk64lgYhDkY2FiZQNIMXJwCMO31rxgZ+tW/zesUPxWzdKWrtLGW/LkP5rXL
64 V/Yvnr/EKjBbQuvZSYa/klsum6XFmTze+maVgclT6Rc6hzqqxNy6o6qdTTmLJuvp
67 -----END PGP MESSAGE----")
69 ;; The following is an opaque ECDSA signature on a message "This is one
70 ;; line\n" (17 byte long) by the primary 384 bit key:
71 (define msg_opaque_signed_384 "-----BEGIN PGP MESSAGE-----
72 Version: PGP Command Line v10.0.0 (Linux)
74 qANQR1DIqwE7wsvMwCnM2WDcwR9SOJ/xtFISd25qcXFieqpeSUUJAxCEZGQWKwBR
75 fl6qQk5mXirXoXJmVgbfYC5xmC5hzsDPjHXqbDLzpXpTBXSZV3L6bAgP3Kq7Ykmo
76 7Ds1v4UfBS+3CSSon7Pzq79WLjzXXEH54MkjPxnrw+8cfMVnY7Bi18J702Nnsa7a
77 9lMv/PM0/ao9CZ3KX7Q+Tv1rllTZ5Hj4V1frw431QnHfAA==
79 -----END PGP MESSAGE-----")
81 ;; The following is an opaque ECDSA signature on a message "This is one
82 ;; line\n" (17 byte long) by the primary 521 bit key:
83 (define msg_opaque_signed_521 "-----BEGIN PGP MESSAGE-----
84 Version: PGP Command Line v10.0.0 (Linux)
86 qANQR1DIwA8BO8LLzMAlnO3Y8tB1vf4/xtNKSdy5qcXFiempeiUVJQxAEJKRWawA
87 RPl5qQo5mXmpXIdmMLMy+AaLnoLpEubatpeJY2Lystd7Qt32q2UcvRS5kNPWtDB7
88 ryufvcrWtFM7Jx8qXKDxZuqr7b9PGv1Ssk+I8TzB2O9dZC+n/jv+PAdbuu7mLe33
89 Gf9pLd3weV3Qno6FOqxGa5ZszQx+uer2xH3/El9x/2pVeO4l15ScsL7qWMTmffmG
90 Ic1RdzgeCfosMF+l/zVRchcLKzenEQA=
92 -----END PGP MESSAGE-----")
95 (letfd ((fd (open z (logior O_WRONLY O_CREAT O_BINARY) #o600)))
96 (display "This is one line\n" (fdopen fd "wb")))
99 "Checking opaque ECDSA signatures"
102 (call-with-output-file
103 x (lambda (p) (display (eval test (current-environment)) p)))
104 (call-check `(,(tool 'gpg) --verify ,x))
105 (call-check `(,(tool 'gpg) --output ,y ,x))
106 (unless (file=? y z) (fail "mismatch"))))
107 '(msg_opaque_signed_256 msg_opaque_signed_384 msg_opaque_signed_521)))
110 ;; Import the secret keys so that we now can sign and decrypt.
112 ;; Note that the PGP generated secret keys are not self-signed, thus we
113 ;; need to pass an appropriate option.
115 (info "Importing ECC secret keys")
116 (setenv "PINENTRY_USER_DATA" "ecc" #t)
119 (call-check `(,(tool 'gpg) --import
120 ,@(if (> n 1) '(--allow-non-selfsigned-uid) '())
121 ,(in-srcdir (string-append
122 "samplekeys/ecc-sample-"
128 ;; Check a few sample encrtpted messages.
130 (info "Checking ECC encryption")
132 ;; The following block encrypts the text "This is one line\n", 17 bytes,
133 ;; with the subkey 4089AB73.
134 (define msg_encrypted_256 "-----BEGIN PGP MESSAGE-----
135 Version: GnuPG v2.1.0-ecc (GNU/Linux)
137 hH4Dd863o0CJq3MSAgMEHdIYZQx+rV1cjy7qitIOEICFFzp4cjsRX4r+rDdMcQUs
138 h7VZmbP1c9C0s9sgCKwubWfkcYUl2ZOju4gy+s4MYTBb4/j8JjnJ9Bqn6LWutTXJ
139 zwsdP13VIJLnhiNqISdR3/6xWQ0ICRYzwb95nUZ1c1DSVgFpjPgUvi4pgYbTpcDB
140 jzILKWBfBDT/jck169XE8vgtbcqVQYZ7lZpaY9CzEbC+4dXZmV1gm5MafpTyFWgH
141 VnyrZB4gad9Lp9e0RKHHcOOE7s/NeLuu
143 -----END PGP MESSAGE-----")
145 ;; The following block encrypts the text "This is one line\n", 17 bytes,
146 ;; with the subkey 9A201946:
147 (define msg_encrypted_384 "-----BEGIN PGP MESSAGE-----
148 Version: PGP Command Line v10.0.0 (Linux)
150 qANQR1DBngOqi5OPmiAZRhIDAwQqIr/00cJyf+QP+VA4QKVkk77KMHdz9OVaR2XK
151 0VYu0F/HPm89vL2orfm2hrAZxY9G2R0PG4Wk5Lg04UjKca/O72uWtjdPYulFidmo
152 uB0QpzXFz22ZZinxeVPLPEr19Pow0EwCc95cg4HAgrD0nV9vRcTJ/+juVfvsJhAO
153 isMKqrFNMvwnK5A1ECeyVXe7oLZl0lUBRhLr59QTtvf85QJjg/m5kaGy8XCJvLv3
154 61pZa6KUmw89PjtPak7ebcjnINL01vwmyeg1PAyW/xjeGGvcO+R4P1b4ewyFnJyR
157 -----END PGP MESSAGE-----")
159 ;; The following block encrypts the text "This is one line\n", 17 bytes,
160 ;; with the subkey A81C4838:
161 (define msg_encrypted_521 "-----BEGIN PGP MESSAGE-----
162 Version: PGP Command Line v10.0.0 (Linux)
164 qANQR1DBwAIDB+qqSKgcSDgSBCMEAKpzTUxB4c56C7g09ekD9I+ttC5ER/xzDmXU
165 OJmFqU5w3FllhFj4TgGxxdH+8fv4W2Ag0IKoJvIY9V1V7oUCClfqAR01QbN7jGH/
166 I9GFFnH19AYEgMKgFmh14ZwN1BS6/VHh+H4apaYqapbx8/09EL+DV9zWLX4GRLXQ
167 VqCR1N2rXE29MJFzGmDOCueQNkUjcbuenoCSKcNT+6xhO27U9IYVCg4BhRUDGfD6
168 dhfRzBLxL+bKR9JVAe46+K8NLjRVu/bd4Iounx4UF5dBk8ERy+/8k9XantDoQgo6
169 RPqCad4Dg/QqkpbK3y574ds3VFNJmc4dVpsXm7lGV5w0FBxhVNPoWNhhECMlTroX
172 -----END PGP MESSAGE-----")
175 (letfd ((fd (open z (logior O_WRONLY O_CREAT O_BINARY) #o600)))
176 (display "This is one line\n" (fdopen fd "wb")))
179 "Checking ECDSA decryption"
182 (call-with-output-file
183 x (lambda (p) (display (eval test (current-environment)) p)))
184 (call-check `(,@GPG --yes --output ,y ,x))
185 (unless (file=? y z) (fail "mismatch"))))
186 '(msg_encrypted_256 msg_encrypted_384 msg_encrypted_521)))
189 ;; Now check that we can encrypt and decrypt our own messages.
191 ;; Note that we don't need to provide a passphrase because we already
192 ;; preset the passphrase into the gpg-agent.
195 "Checking ECC encryption and decryption"
202 (tr:gpg "" `(--yes --encrypt --recipient ,keyid))
204 (tr:assert-identity source)))
206 (append plain-files data-files))
209 ;; Now check that we can sign and verify our own messages.
212 "Checking ECC signing and verifiction"
219 (tr:gpg "" `(--yes --sign --local-user ,keyid))
221 (tr:assert-identity source)))
223 (append plain-files data-files))
226 ;; Let us also try to import the keys only from a secret keyblock.
228 ;; Because PGP does not sign the UID, it is not very useful to work
229 ;; with this key unless we go into the trouble of adding the
232 (info "Importing ECC secret keys directly")
235 (catch '() (unlink (string-append "private-keys-v1.d/" keyid ".key"))))
239 (call `(,(tool 'gpg) --delete-key --batch --yes ,keyid)))
244 (call-check `(,(tool 'gpg) --import
245 ,@(if (> n 1) '(--allow-non-selfsigned-uid) '())
246 ,(in-srcdir (string-append
247 "samplekeys/ecc-sample-"