You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
8.0 KiB

  1. [ed25519](http://ed25519.cr.yp.to/) is an
  2. [Elliptic Curve Digital Signature Algortithm](http://en.wikipedia.org/wiki/Elliptic_Curve_DSA),
  3. developed by [Dan Bernstein](http://cr.yp.to/djb.html),
  4. [Niels Duif](http://www.nielsduif.nl/),
  5. [Tanja Lange](http://hyperelliptic.org/tanja),
  6. [Peter Schwabe](http://www.cryptojedi.org/users/peter/),
  7. and [Bo-Yin Yang](http://www.iis.sinica.edu.tw/pages/byyang/).
  8. This project provides performant, portable 32-bit & 64-bit implementations. All implementations are
  9. of course constant time in regard to secret data.
  10. #### Performance
  11. SSE2 code and benches have not been updated yet. I will do those next.
  12. Compilers versions are gcc 4.6.3, icc 13.1.1, clang 3.4-1~exp1.
  13. Batch verfication time (in parentheses) is the average time per 1 verification in a batch of 64 signatures. Counts are in thousands of cycles.
  14. Note that SSE2 performance may be less impressive on AMD & older CPUs with slower SSE ops!
  15. Visual Studio performance for `ge25519_scalarmult_base_niels` will lag behind a bit until optimized assembler versions of `ge25519_scalarmult_base_choose_niels`
  16. are made.
  17. ##### E5200 @ 2.5ghz, march=core2
  18. <table>
  19. <thead><tr><th>Implementation</th><th>Sign</th><th>gcc</th><th>icc</th><th>clang</th><th>Verify</th><th>gcc</th><th>icc</th><th>clang</th></tr></thead>
  20. <tbody>
  21. <tr><td>ed25519-donna 64bit </td><td></td><td>100k</td><td>110k</td><td>137k</td><td></td><td>327k (144k) </td><td>342k (163k) </td><td>422k (194k) </td></tr>
  22. <tr><td>amd64-64-24k </td><td></td><td>102k</td><td> </td><td> </td><td></td><td>355k (158k) </td><td> </td><td> </td></tr>
  23. <tr><td>ed25519-donna-sse2 64bit</td><td></td><td>108k</td><td>111k</td><td>116k</td><td></td><td>353k (155k) </td><td>345k (154k) </td><td>360k (161k) </td></tr>
  24. <tr><td>amd64-51-32k </td><td></td><td>116k</td><td> </td><td> </td><td></td><td>380k (175k) </td><td> </td><td> </td></tr>
  25. <tr><td>ed25519-donna-sse2 32bit</td><td></td><td>147k</td><td>147k</td><td>156k</td><td></td><td>380k (178k) </td><td>381k (173k) </td><td>430k (192k) </td></tr>
  26. <tr><td>ed25519-donna 32bit </td><td></td><td>597k</td><td>335k</td><td>380k</td><td></td><td>1693k (720k)</td><td>1052k (453k)</td><td>1141k (493k)</td></tr>
  27. </tbody>
  28. </table>
  29. ##### E3-1270 @ 3.4ghz, march=corei7-avx
  30. <table>
  31. <thead><tr><th>Implementation</th><th>Sign</th><th>gcc</th><th>icc</th><th>clang</th><th>Verify</th><th>gcc</th><th>icc</th><th>clang</th></tr></thead>
  32. <tbody>
  33. <tr><td>amd64-64-24k </td><td></td><td> 68k</td><td> </td><td> </td><td></td><td>225k (104k) </td><td> </td><td> </td></tr>
  34. <tr><td>ed25519-donna 64bit </td><td></td><td> 71k</td><td> 75k</td><td> 90k</td><td></td><td>226k (105k) </td><td>226k (112k) </td><td>277k (125k) </td></tr>
  35. <tr><td>amd64-51-32k </td><td></td><td> 72k</td><td> </td><td> </td><td></td><td>218k (107k) </td><td> </td><td> </td></tr>
  36. <tr><td>ed25519-donna-sse2 64bit</td><td></td><td> 79k</td><td> 82k</td><td> 92k</td><td></td><td>252k (122k) </td><td>259k (124k) </td><td>282k (131k) </td></tr>
  37. <tr><td>ed25519-donna-sse2 32bit</td><td></td><td> 94k</td><td> 95k</td><td>103k</td><td></td><td>296k (146k) </td><td>294k (137k) </td><td>306k (147k) </td></tr>
  38. <tr><td>ed25519-donna 32bit </td><td></td><td>525k</td><td>299k</td><td>316k</td><td></td><td>1502k (645k)</td><td>959k (418k) </td><td>954k (416k) </td></tr>
  39. </tbody>
  40. </table>
  41. #### Compilation
  42. No configuration is needed **if you are compiling against OpenSSL**.
  43. ##### Hash Options
  44. If you are not compiling aginst OpenSSL, you will need a hash function.
  45. To use a simple/**slow** implementation of SHA-512, use `-DED25519_REFHASH` when compiling `ed25519.c`.
  46. This should never be used except to verify the code works when OpenSSL is not available.
  47. To use a custom hash function, use `-DED25519_CUSTOMHASH` when compiling `ed25519.c` and put your
  48. custom hash implementation in ed25519-hash-custom.h. The hash must have a 512bit digest and implement
  49. struct ed25519_hash_context;
  50. void ed25519_hash_init(ed25519_hash_context *ctx);
  51. void ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen);
  52. void ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash);
  53. void ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen);
  54. ##### Random Options
  55. If you are not compiling aginst OpenSSL, you will need a random function for batch verification.
  56. To use a custom random function, use `-DED25519_CUSTOMRANDOM` when compiling `ed25519.c` and put your
  57. custom hash implementation in ed25519-randombytes-custom.h. The random function must implement:
  58. void ED25519_FN(ed25519_randombytes_unsafe) (void *p, size_t len);
  59. Use `-DED25519_TEST` when compiling `ed25519.c` to use a deterministically seeded, non-thread safe CSPRNG
  60. variant of Bob Jenkins [ISAAC](http://en.wikipedia.org/wiki/ISAAC_%28cipher%29)
  61. ##### Minor options
  62. Use `-DED25519_INLINE_ASM` to disable the use of custom assembler routines and instead rely on portable C.
  63. Use `-DED25519_FORCE_32BIT` to force the use of 32 bit routines even when compiling for 64 bit.
  64. ##### 32-bit
  65. gcc ed25519.c -m32 -O3 -c
  66. ##### 64-bit
  67. gcc ed25519.c -m64 -O3 -c
  68. ##### SSE2
  69. gcc ed25519.c -m32 -O3 -c -DED25519_SSE2 -msse2
  70. gcc ed25519.c -m64 -O3 -c -DED25519_SSE2
  71. clang and icc are also supported
  72. #### Usage
  73. To use the code, link against `ed25519.o -mbits` and:
  74. #include "ed25519.h"
  75. Add `-lssl -lcrypto` when using OpenSSL (Some systems don't need -lcrypto? It might be trial and error).
  76. To generate a private key, simply generate 32 bytes from a secure
  77. cryptographic source:
  78. ed25519_secret_key sk;
  79. randombytes(sk, sizeof(ed25519_secret_key));
  80. To generate a public key:
  81. ed25519_public_key pk;
  82. ed25519_publickey(sk, pk);
  83. To sign a message:
  84. ed25519_signature sig;
  85. ed25519_sign(message, message_len, sk, pk, signature);
  86. To verify a signature:
  87. int valid = ed25519_sign_open(message, message_len, pk, signature) == 0;
  88. To batch verify signatures:
  89. const unsigned char *mp[num] = {message1, message2..}
  90. size_t ml[num] = {message_len1, message_len2..}
  91. const unsigned char *pkp[num] = {pk1, pk2..}
  92. const unsigned char *sigp[num] = {signature1, signature2..}
  93. int valid[num]
  94. /* valid[i] will be set to 1 if the individual signature was valid, 0 otherwise */
  95. int all_valid = ed25519_sign_open_batch(mp, ml, pkp, sigp, num, valid) == 0;
  96. **Note**: Batch verification uses `ed25519_randombytes_unsafe`, implemented in
  97. `ed25519-randombytes.h`, to generate random scalars for the verification code.
  98. The default implementation now uses OpenSSLs `RAND_bytes`.
  99. Unlike the [SUPERCOP](http://bench.cr.yp.to/supercop.html) version, signatures are
  100. not appended to messages, and there is no need for padding in front of messages.
  101. Additionally, the secret key does not contain a copy of the public key, so it is
  102. 32 bytes instead of 64 bytes, and the public key must be provided to the signing
  103. function.
  104. ##### Curve25519
  105. Curve25519 public keys can be generated thanks to
  106. [Adam Langley](http://www.imperialviolet.org/2013/05/10/fastercurve25519.html)
  107. leveraging Ed25519's precomputed basepoint scalar multiplication.
  108. curved25519_key sk, pk;
  109. randombytes(sk, sizeof(curved25519_key));
  110. curved25519_scalarmult_basepoint(pk, sk);
  111. Note the name is curved25519, a combination of curve and ed25519, to prevent
  112. name clashes. Performance is slightly faster than short message ed25519
  113. signing due to both using the same code for the scalar multiply.
  114. #### Testing
  115. Fuzzing against reference implemenations is now available. See [fuzz/README](fuzz/README.md).
  116. Building `ed25519.c` with `-DED25519_TEST` and linking with `test.c` will run basic sanity tests
  117. and benchmark each function. `test-batch.c` has been incorporated in to `test.c`.
  118. `test-internals.c` is standalone and built the same way as `ed25519.c`. It tests the math primitives
  119. with extreme values to ensure they function correctly. SSE2 is now supported.
  120. #### Papers
  121. [Available on the Ed25519 website](http://ed25519.cr.yp.to/papers.html)