pcpeccppointca.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2016 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  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
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include "owndefs.h"
  32. #include "owncp.h"
  33. #include "pcpeccppoint.h"
  34. /*F*
  35. // Name: ippsECCPPointGetSize
  36. //
  37. // Purpose: Returns size of EC Point context (bytes).
  38. //
  39. // Returns: Reason:
  40. // ippStsNullPtrErr NULL == pSzie
  41. // ippStsSizeErr 2>feBitSize
  42. // ippStsNoErr no errors
  43. //
  44. // Parameters:
  45. // feBitSize size of field element (bits)
  46. // pSize pointer to the size of EC Point context
  47. //
  48. *F*/
  49. IPPFUN(IppStatus, ippsECCPPointGetSize, (int feBitSize, int* pSize))
  50. {
  51. /* test size's pointer */
  52. IPP_BAD_PTR1_RET(pSize);
  53. /* test size of field element */
  54. IPP_BADARG_RET((2>feBitSize), ippStsSizeErr);
  55. {
  56. int bnSize;
  57. ippsBigNumGetSize(BITS2WORD32_SIZE(feBitSize), &bnSize);
  58. *pSize = sizeof(IppsECCPPointState)
  59. + bnSize /* X coodinate */
  60. + bnSize /* Y coodinate */
  61. + bnSize /* Z coodinate */
  62. +(ALIGN_VAL-1);
  63. }
  64. return ippStsNoErr;
  65. }
  66. /*F*
  67. // Name: ippsECCPPointInit
  68. //
  69. // Purpose: Init EC Point context.
  70. //
  71. // Returns: Reason:
  72. // ippStsNullPtrErr NULL == pPoint
  73. // ippStsSizeErr 2>feBitSize
  74. // ippStsNoErr no errors
  75. //
  76. // Parameters:
  77. // feBitSize size of field element (bits)
  78. // pECC pointer to ECC context
  79. //
  80. *F*/
  81. IPPFUN(IppStatus, ippsECCPPointInit, (int feBitSize, IppsECCPPointState* pPoint))
  82. {
  83. /* test pEC pointer */
  84. IPP_BAD_PTR1_RET(pPoint);
  85. /* use aligned context */
  86. pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) );
  87. /* test size of field element */
  88. IPP_BADARG_RET((2>feBitSize), ippStsSizeErr);
  89. /* context ID */
  90. ECP_POINT_ID(pPoint) = idCtxECCPPoint;
  91. /* meaning: point was not set */
  92. ECP_POINT_AFFINE(pPoint) =-1;
  93. /*
  94. // init other context fields
  95. */
  96. {
  97. Ipp8u* ptr = (Ipp8u*)pPoint;
  98. int bnLen = BITS2WORD32_SIZE(feBitSize);
  99. int bnSize;
  100. ippsBigNumGetSize(bnLen, &bnSize);
  101. /* allocate coordinate buffers */
  102. ptr += sizeof(IppsECCPPointState);
  103. ECP_POINT_X(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
  104. ptr += bnSize;
  105. ECP_POINT_Y(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
  106. ptr += bnSize;
  107. ECP_POINT_Z(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
  108. /* init coordinate buffers */
  109. ippsBigNumInit(bnLen, ECP_POINT_X(pPoint));
  110. ippsBigNumInit(bnLen, ECP_POINT_Y(pPoint));
  111. ippsBigNumInit(bnLen, ECP_POINT_Z(pPoint));
  112. }
  113. return ippStsNoErr;
  114. }