… | |
… | |
36 | # verify message |
36 | # verify message |
37 | $valid = Crypt::Ed25519::eddsa_verify $message, $pubkey, $signature; |
37 | $valid = Crypt::Ed25519::eddsa_verify $message, $pubkey, $signature; |
38 | |
38 | |
39 | # verify, but croak on failure |
39 | # verify, but croak on failure |
40 | Crypt::Ed25519:eddsa_verify_croak $message, $pubkey, $signature; |
40 | Crypt::Ed25519:eddsa_verify_croak $message, $pubkey, $signature; |
|
|
41 | |
|
|
42 | ############################################ |
|
|
43 | # Key exchange |
|
|
44 | |
|
|
45 | # side A: |
|
|
46 | ($pubkey_a, $privkey_a) = Crypt::Ed25519::generate_keypair; |
|
|
47 | # send $pubkey to side B |
|
|
48 | |
|
|
49 | # side B: |
|
|
50 | ($pubkey_b, $privkey_b) = Crypt::Ed25519::generate_keypair; |
|
|
51 | # send $pubkey to side A |
|
|
52 | |
|
|
53 | # side A then calculates their shared secret: |
|
|
54 | $shared_secret = Crypt::Ed25519::key_exchange $pubkey_b, $privkey_a; |
|
|
55 | |
|
|
56 | # and side B does this: |
|
|
57 | $shared_secret = Crypt::Ed25519::key_exchange $pubkey_a, $privkey_b; |
|
|
58 | |
|
|
59 | # the generated $shared_secret will be the same - you cna now |
|
|
60 | # hash it with hkdf or something else to generate symmetric private keys |
41 | |
61 | |
42 | =head1 DESCRIPTION |
62 | =head1 DESCRIPTION |
43 | |
63 | |
44 | This module implements Ed25519 public key generation, message signing and |
64 | This module implements Ed25519 public key generation, message signing and |
45 | verification. It is a pretty bare-bones implementation that implements |
65 | verification. It is a pretty bare-bones implementation that implements |
… | |
… | |
74 | =cut |
94 | =cut |
75 | |
95 | |
76 | package Crypt::Ed25519; |
96 | package Crypt::Ed25519; |
77 | |
97 | |
78 | BEGIN { |
98 | BEGIN { |
79 | $VERSION = 1.04; |
99 | $VERSION = 1.05; |
80 | |
100 | |
81 | require XSLoader; |
101 | require XSLoader; |
82 | XSLoader::load Crypt::Ed25519::, $VERSION; |
102 | XSLoader::load Crypt::Ed25519::, $VERSION; |
83 | } |
103 | } |
84 | |
104 | |
… | |
… | |
186 | derive the public key as needed. On the other hand, signing using the |
206 | derive the public key as needed. On the other hand, signing using the |
187 | private key is faster than using the secret key, so converting the secret |
207 | private key is faster than using the secret key, so converting the secret |
188 | key to a public/private key pair allows you to sign a small message, or |
208 | key to a public/private key pair allows you to sign a small message, or |
189 | many messages, faster. |
209 | many messages, faster. |
190 | |
210 | |
|
|
211 | =head1 Key Exchange |
|
|
212 | |
|
|
213 | As an extension to Ed25519, this module implements a key exchange similar |
|
|
214 | (But not identical) to Curve25519. For this, both sides generate a keypair |
|
|
215 | and send their public key to the other side. Then both sides can generate |
|
|
216 | the same shared secret using this function: |
|
|
217 | |
|
|
218 | =over |
|
|
219 | |
|
|
220 | =item $shared_secret = Crypt::Ed25519::key_exchange $other_public_key, $own_private_key |
|
|
221 | |
|
|
222 | Return the 32 octet shared secret generated from the given public and |
|
|
223 | private key. See SYNOPSIS for an actual example. |
|
|
224 | |
|
|
225 | =back |
|
|
226 | |
191 | =head1 SUPPORT FOR THE PERL MULTICORE SPECIFICATION |
227 | =head1 SUPPORT FOR THE PERL MULTICORE SPECIFICATION |
192 | |
228 | |
193 | This module supports the perl multicore specification |
229 | This module supports the perl multicore specification |
194 | (L<http://perlmulticore.schmorp.de/>) for key generation (usually the |
230 | (L<http://perlmulticore.schmorp.de/>) for all operations, although it |
195 | slowest operation), and all signing and verification functions. |
231 | makes most sense to use it when signing or verifying longer messages. |
196 | |
232 | |
197 | =head1 IMPLEMENTATIOIN |
233 | =head1 IMPLEMENTATION |
198 | |
234 | |
199 | This module currently uses "Nightcracker's Ed25519" implementation, which |
235 | This module currently uses "Nightcracker's Ed25519" implementation, which |
200 | is unmodified except for some portability fixes and static delcarations, |
236 | is unmodified except for some portability fixes and static delcarations, |
201 | but the interface is kept implementation-agnostic to allow usage of other |
237 | but the interface is kept implementation-agnostic to allow usage of other |
202 | implementations in the future. |
238 | implementations in the future. |
203 | |
239 | |
204 | =head1 AUTHOR |
240 | =head1 AUTHOR |
205 | |
241 | |
206 | Marc Lehmann <schmorp@schmorp.de> |
242 | Marc Lehmann <schmorp@schmorp.de> |
207 | http://sfotware.schmorp.de/pkg/Crypt-Ed25519.html |
243 | http://software.schmorp.de/pkg/Crypt-Ed25519.html |
208 | |
244 | |
209 | =cut |
245 | =cut |
210 | |
246 | |
211 | 1 |
247 | 1 |
212 | |
248 | |