ec.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009-2010 Adam Ierymenko <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. /* Elliptic curve glue -- hides OpenSSL code behind this source module */
  17. #ifndef _ANODE_EC_H
  18. #define _ANODE_EC_H
  19. #include "misc.h"
  20. /* Right now, only one mode is supported: NIST-P-256. This is the only mode
  21. * supported in the spec as well, and should be good for quite some time.
  22. * If other modes are needed this code will need to be refactored. */
  23. /* NIST-P-256 prime size in bytes */
  24. #define ANODE_EC_PRIME_BYTES 32
  25. /* Sizes of key fields */
  26. #define ANODE_EC_GROUP NID_X9_62_prime256v1
  27. #define ANODE_EC_PUBLIC_KEY_BYTES (ANODE_EC_PRIME_BYTES + 1)
  28. #define ANODE_EC_PRIVATE_KEY_BYTES ANODE_EC_PRIME_BYTES
  29. /* Larger of public or private key bytes, used for buffers */
  30. #define ANODE_EC_MAX_BYTES ANODE_EC_PUBLIC_KEY_BYTES
  31. struct AnodeECKey
  32. {
  33. unsigned char key[ANODE_EC_MAX_BYTES];
  34. unsigned int bytes;
  35. };
  36. struct AnodeECKeyPair
  37. {
  38. struct AnodeECKey pub;
  39. struct AnodeECKey priv;
  40. void *internal_key;
  41. };
  42. /* Key management functions */
  43. int AnodeECKeyPair_generate(struct AnodeECKeyPair *pair);
  44. int AnodeECKeyPair_init(struct AnodeECKeyPair *pair,const struct AnodeECKey *pub,const struct AnodeECKey *priv);
  45. void AnodeECKeyPair_destroy(struct AnodeECKeyPair *pair);
  46. int AnodeECKeyPair_agree(const struct AnodeECKeyPair *my_key_pair,const struct AnodeECKey *their_pub_key,unsigned char *key_buf,unsigned int key_len);
  47. /* Provides access to the secure PRNG used to generate keys */
  48. void AnodeEC_random(unsigned char *buf,unsigned int len);
  49. #endif