ecc.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2013, Kenneth MacKay
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /* Create a public/private key pair.
  27. * Outputs:
  28. * public_key - Will be filled in with the public key.
  29. * private_key - Will be filled in with the private key.
  30. *
  31. * Returns true if the key pair was generated successfully, false
  32. * if an error occurred. The keys are with the LSB first.
  33. */
  34. bool ecc_make_key(u8 public_key[64], u8 private_key[32]);
  35. /* Compute a shared secret given your secret key and someone else's
  36. * public key.
  37. * Note: It is recommended that you hash the result of ecdh_shared_secret
  38. * before using it for symmetric encryption or HMAC.
  39. *
  40. * Inputs:
  41. * public_key - The public key of the remote party
  42. * private_key - Your private key.
  43. *
  44. * Outputs:
  45. * secret - Will be filled in with the shared secret value.
  46. *
  47. * Returns true if the shared secret was generated successfully, false
  48. * if an error occurred. Both input and output parameters are with the
  49. * LSB first.
  50. */
  51. bool ecdh_shared_secret(const u8 public_key[64], const u8 private_key[32],
  52. u8 secret[32]);