|
37 | 37 | http://nacl.cr.yp.to/
|
38 | 38 | https://github.com/pyca/ed25519
|
39 | 39 |
|
40 |
| - The ed25519-related functions included here are generate(), create_signature() |
41 |
| - and verify_signature(). The 'ed25519' and PyNaCl (i.e., 'nacl') modules used |
| 40 | + The ed25519-related functions included here are generate() and create_signature(). |
| 41 | + The 'ed25519' and PyNaCl (i.e., 'nacl') modules used |
42 | 42 | by ed25519_keys.py perform the actual ed25519 computations and the functions
|
43 | 43 | listed above can be viewed as an easy-to-use public interface.
|
44 | 44 | """
|
|
67 | 67 | # avoid conflicts with own exceptions of same name
|
68 | 68 | from nacl import exceptions as nacl_exceptions
|
69 | 69 | from nacl.encoding import RawEncoder
|
70 |
| - from nacl.signing import SigningKey, VerifyKey |
| 70 | + from nacl.signing import SigningKey |
71 | 71 | except ImportError:
|
72 | 72 | NACL = False
|
73 | 73 |
|
74 | 74 | # pylint: disable=wrong-import-position
|
75 | 75 | from securesystemslib import exceptions, formats
|
76 | 76 |
|
77 |
| -# The optimized pure Python implementation of Ed25519. If |
78 |
| -# PyNaCl cannot be imported and an attempt to use is made in this module, a |
79 |
| -# 'securesystemslib.exceptions.UnsupportedLibraryError' exception is raised. |
80 |
| -from securesystemslib._vendor.ed25519 import ed25519 as python_ed25519 |
81 |
| - |
82 | 77 | # pylint: enable=wrong-import-position
|
83 | 78 |
|
84 | 79 | # Supported ed25519 signing schemes: 'ed25519'. The pure Python implementation
|
@@ -248,112 +243,6 @@ def create_signature(public_key, private_key, data, scheme):
|
248 | 243 | return signature, scheme
|
249 | 244 |
|
250 | 245 |
|
251 |
| -def verify_signature(public_key, scheme, signature, data): |
252 |
| - """ |
253 |
| - <Purpose> |
254 |
| - Determine whether the private key corresponding to 'public_key' produced |
255 |
| - 'signature'. verify_signature() will use the public key, the 'scheme' and |
256 |
| - 'sig', and 'data' arguments to complete the verification. |
257 |
| -
|
258 |
| - >>> public, private = generate_public_and_private() |
259 |
| - >>> data = b'The quick brown fox jumps over the lazy dog' |
260 |
| - >>> scheme = 'ed25519' |
261 |
| - >>> signature, scheme = \ |
262 |
| - create_signature(public, private, data, scheme) |
263 |
| - >>> verify_signature(public, scheme, signature, data) |
264 |
| - True |
265 |
| - >>> bad_data = b'The sly brown fox jumps over the lazy dog' |
266 |
| - >>> bad_signature, scheme = \ |
267 |
| - create_signature(public, private, bad_data, scheme) |
268 |
| - >>> verify_signature(public, scheme, bad_signature, data) |
269 |
| - False |
270 |
| -
|
271 |
| - <Arguments> |
272 |
| - public_key: |
273 |
| - The public key is a 32-byte string. |
274 |
| -
|
275 |
| - scheme: |
276 |
| - 'ed25519' signature scheme used by either the pure python |
277 |
| - implementation (i.e., ed25519.py) or PyNacl (i.e., 'nacl'). |
278 |
| -
|
279 |
| - signature: |
280 |
| - The signature is a 64-byte string. |
281 |
| -
|
282 |
| - data: |
283 |
| - Data object used by securesystemslib.ed25519_keys.create_signature() to |
284 |
| - generate 'signature'. 'data' is needed here to verify the signature. |
285 |
| -
|
286 |
| - <Exceptions> |
287 |
| - securesystemslib.exceptions.UnsupportedAlgorithmError. Raised if the |
288 |
| - signature scheme 'scheme' is not one supported by |
289 |
| - securesystemslib.ed25519_keys.create_signature(). |
290 |
| -
|
291 |
| - securesystemslib.exceptions.FormatError. Raised if the arguments are |
292 |
| - improperly formatted. |
293 |
| -
|
294 |
| - <Side Effects> |
295 |
| - nacl.signing.VerifyKey.verify() called if available, otherwise |
296 |
| - securesystemslib._vendor.ed25519.ed25519.checkvalid() called to do the |
297 |
| - verification. |
298 |
| -
|
299 |
| - <Returns> |
300 |
| - Boolean. True if the signature is valid, False otherwise. |
301 |
| - """ |
302 |
| - |
303 |
| - # Does 'public_key' have the correct format? |
304 |
| - # This check will ensure 'public_key' conforms to |
305 |
| - # 'securesystemslib.formats.ED25519PUBLIC_SCHEMA', which must have length 32 |
306 |
| - # bytes. Raise 'securesystemslib.exceptions.FormatError' if the check fails. |
307 |
| - formats.ED25519PUBLIC_SCHEMA.check_match(public_key) |
308 |
| - |
309 |
| - # Is 'scheme' properly formatted? |
310 |
| - formats.ED25519_SIG_SCHEMA.check_match(scheme) |
311 |
| - |
312 |
| - # Is 'signature' properly formatted? |
313 |
| - formats.ED25519SIGNATURE_SCHEMA.check_match(signature) |
314 |
| - |
315 |
| - # Verify 'signature'. Before returning the Boolean result, ensure 'ed25519' |
316 |
| - # was used as the signature scheme. |
317 |
| - public = public_key |
318 |
| - valid_signature = False |
319 |
| - |
320 |
| - if scheme in _SUPPORTED_ED25519_SIGNING_SCHEMES: |
321 |
| - if NACL: |
322 |
| - try: |
323 |
| - nacl_verify_key = VerifyKey(public) |
324 |
| - nacl_verify_key.verify(data, signature) |
325 |
| - valid_signature = True |
326 |
| - |
327 |
| - except nacl_exceptions.BadSignatureError: |
328 |
| - pass |
329 |
| - |
330 |
| - # Verify 'ed25519' signature with the pure Python implementation. |
331 |
| - else: |
332 |
| - try: |
333 |
| - python_ed25519.checkvalid(signature, data, public) |
334 |
| - valid_signature = True |
335 |
| - |
336 |
| - # The pure Python implementation raises 'Exception' if 'signature' is |
337 |
| - # invalid. |
338 |
| - except Exception: # pylint: disable=broad-except # nosec |
339 |
| - pass |
340 |
| - |
341 |
| - # This is a defensive check for a valid 'scheme', which should have already |
342 |
| - # been validated in the ED25519_SIG_SCHEMA.check_match(scheme) above. |
343 |
| - else: # pragma: no cover |
344 |
| - message = ( |
345 |
| - "Unsupported ed25519 signature scheme: " |
346 |
| - + repr(scheme) |
347 |
| - + ".\n" |
348 |
| - + "Supported schemes: " |
349 |
| - + repr(_SUPPORTED_ED25519_SIGNING_SCHEMES) |
350 |
| - + "." |
351 |
| - ) |
352 |
| - raise exceptions.UnsupportedAlgorithmError(message) |
353 |
| - |
354 |
| - return valid_signature |
355 |
| - |
356 |
| - |
357 | 246 | if __name__ == "__main__":
|
358 | 247 | # The interactive sessions of the documentation strings can
|
359 | 248 | # be tested by running 'ed25519_keys.py' as a standalone module.
|
|
0 commit comments