zrtp_ec.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. */
  7. #ifndef __ZRTP_CRYPTO_EC_H__
  8. #define __ZRTP_CRYPTO_EC_H__
  9. #include "bn.h"
  10. #include "zrtp_config.h"
  11. #include "zrtp_types.h"
  12. #include "zrtp_error.h"
  13. #define ZRTP_MAXECBITS 521
  14. #define ZRTP_MAXECWORDS ((ZRTP_MAXECBITS+7)/8)
  15. typedef struct zrtp_ec_params
  16. {
  17. unsigned ec_bits; /* # EC bits: 256, 384, 521 */
  18. uint8_t P_data[ZRTP_MAXECWORDS]; /* curve field prime */
  19. uint8_t n_data[ZRTP_MAXECWORDS]; /* curve order (# points) */
  20. uint8_t b_data[ZRTP_MAXECWORDS]; /* curve param, y^3 = x^2 -3x + b */
  21. uint8_t Gx_data[ZRTP_MAXECWORDS]; /* curve point, x coordinate */
  22. uint8_t Gy_data[ZRTP_MAXECWORDS]; /* curve point, y coordinate */
  23. } zrtp_ec_params_t;
  24. #if defined(__cplusplus)
  25. extern "C"
  26. {
  27. #endif
  28. /*============================================================================*/
  29. /* Elliptic Curve library */
  30. /*============================================================================*/
  31. int zrtp_ecAdd ( struct BigNum *rsltx,
  32. struct BigNum *rslty,
  33. struct BigNum *p1x,
  34. struct BigNum *p1y,
  35. struct BigNum *p2x,
  36. struct BigNum *p2y,
  37. struct BigNum *mod);
  38. int zrtp_ecMul ( struct BigNum *rsltx,
  39. struct BigNum *rslty,
  40. struct BigNum *mult,
  41. struct BigNum *basex,
  42. struct BigNum *basey,
  43. struct BigNum *mod);
  44. zrtp_status_t zrtp_ec_random_point( zrtp_global_t *zrtp,
  45. struct BigNum *P,
  46. struct BigNum *n,
  47. struct BigNum *Gx,
  48. struct BigNum *Gy,
  49. struct BigNum *pkx,
  50. struct BigNum *pky,
  51. struct BigNum *sv,
  52. uint8_t *test_sv_data,
  53. size_t test_sv_data_len);
  54. extern zrtp_status_t zrtp_ec_init_params(struct zrtp_ec_params *params, uint32_t bits );
  55. /* Useful bignum utility functions not defined in bignum library */
  56. int bnAddMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod);
  57. int bnAddQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod);
  58. int bnSubMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod);
  59. int bnSubQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod);
  60. int bnMulMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *n2, struct BigNum *mod);
  61. int bnMulQMod_ (struct BigNum *rslt, struct BigNum *n1, unsigned n2, struct BigNum *mod);
  62. int bnSquareMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod);
  63. #if defined(__cplusplus)
  64. }
  65. #endif
  66. #endif /* __ZRTP_CRYPTO_EC_H__ */