p_256_ecc_pp.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /******************************************************************************
  2. *
  3. * Copyright 2006-2015 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This file contains simple pairing algorithms using Elliptic Curve
  21. *Cryptography for private public key
  22. *
  23. ******************************************************************************/
  24. #pragma once
  25. #include <cstdbool>
  26. #include "p_256_multprecision.h"
  27. typedef struct {
  28. uint32_t x[KEY_LENGTH_DWORDS_P256];
  29. uint32_t y[KEY_LENGTH_DWORDS_P256];
  30. uint32_t z[KEY_LENGTH_DWORDS_P256];
  31. } Point;
  32. typedef struct {
  33. // curve's coefficients
  34. uint32_t a[KEY_LENGTH_DWORDS_P256];
  35. uint32_t b[KEY_LENGTH_DWORDS_P256];
  36. // whether a is -3
  37. int a_minus3;
  38. // prime modulus
  39. uint32_t p[KEY_LENGTH_DWORDS_P256];
  40. // Omega, p = 2^m -omega
  41. uint32_t omega[KEY_LENGTH_DWORDS_P256];
  42. // base point, a point on E of order r
  43. Point G;
  44. } elliptic_curve_t;
  45. extern elliptic_curve_t curve;
  46. extern elliptic_curve_t curve_p256;
  47. bool ECC_ValidatePoint(const Point& p);
  48. void ECC_PointMult_Bin_NAF(Point* q, Point* p, uint32_t* n, uint32_t keyLength);
  49. #define ECC_PointMult(q, p, n, keyLength) \
  50. ECC_PointMult_Bin_NAF(q, p, n, keyLength)
  51. void p_256_init_curve(uint32_t keyLength);