pairing.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*############################################################################
  2. # Copyright 2016-2017 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /*!
  17. * \file
  18. * \brief Pairing interface.
  19. */
  20. #ifndef EPID_COMMON_MATH_PAIRING_H_
  21. #define EPID_COMMON_MATH_PAIRING_H_
  22. #include "epid/common/errors.h"
  23. #include "epid/common/math/ecgroup.h"
  24. #include "epid/common/math/finitefield.h"
  25. #include "epid/common/types.h"
  26. /// Pairing operations
  27. /*!
  28. \defgroup PairingPrimitives pairing
  29. Provides APIs for defining and using a pairing relationship between two
  30. elliptic curve groups.
  31. \ingroup EpidMath
  32. @{
  33. */
  34. /// A pairing
  35. typedef struct PairingState PairingState;
  36. /// Constructs a new pairing state.
  37. /*!
  38. Allocates memory and creates a new pairing state for Optimal Ate Pairing.
  39. Use DeletePairingState() to free memory.
  40. \param[in] ga
  41. The EcGroup from which the first parameter of the pairing is taken.
  42. \param[in] gb
  43. The EcGroup from which the second parameter of the pairing is taken.
  44. \param[in] ff
  45. The result finite field. Must be a Fq12 field.
  46. \param[in] t
  47. A positive integer such that 6(t^2) == q - p, where p and q are parameters
  48. of G1.
  49. \param[in] neg
  50. Select the alternate "negate" processing path for Optimal Ate Pairing.
  51. \param[out] ps
  52. Newly constructed pairing state.
  53. \returns ::EpidStatus
  54. \attention It is the responsibility of the caller to ensure that ga, gb, and
  55. ff exist for the entire lifetime of the new PairingState.
  56. \see DeletePairingState
  57. */
  58. EpidStatus NewPairingState(EcGroup const* ga, EcGroup const* gb,
  59. FiniteField* ff, BigNumStr const* t, bool neg,
  60. PairingState** ps);
  61. /// Frees a previously allocated by PairingState.
  62. /*!
  63. Frees memory pointed to by pairing state. Nulls the pointer.
  64. \param[in] ps
  65. The pairing state. Can be NULL.
  66. \see NewPairingState
  67. */
  68. void DeletePairingState(PairingState** ps);
  69. /// Computes an Optimal Ate Pairing for two parameters.
  70. /*!
  71. \param[in] ps
  72. The pairing state.
  73. \param[in] a
  74. The first value to pair. Must be in ga used to create ps.
  75. \param[in] b
  76. The second value to pair. Must be in gb used to create ps
  77. \param[out] d
  78. The result of the pairing. Will be in ff used to create the pairing state.
  79. \returns ::EpidStatus
  80. */
  81. EpidStatus Pairing(PairingState* ps, EcPoint const* a, EcPoint const* b,
  82. FfElement* d);
  83. /*!
  84. @}
  85. */
  86. #endif // EPID_COMMON_MATH_PAIRING_H_