pcpeccppublickeyca.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "pcpeccpmethod.h"
  35. #include "pcpeccpmethodcom.h"
  36. /*F*
  37. // Name: ippsECCPPublicKey
  38. //
  39. // Purpose: Calculate Public Key
  40. //
  41. // Returns: Reason:
  42. // ippStsNullPtrErr NULL == pECC
  43. // NULL == pPrivate
  44. // NULL == pPublic
  45. //
  46. // ippStsContextMatchErr illegal pECC->idCtx
  47. // illegal pPrivate->idCtx
  48. // illegal pPublic->idCtx
  49. //
  50. // ippStsIvalidPrivateKey !(0 < pPrivate < order)
  51. //
  52. // ippStsNoErr no errors
  53. //
  54. // Parameters:
  55. // pPrivate pointer to the private key
  56. // pPublic pointer to the resultant public key
  57. // pECC pointer to the ECCP context
  58. //
  59. *F*/
  60. IPPFUN(IppStatus, ippsECCPPublicKey, (const IppsBigNumState* pPrivate,
  61. IppsECCPPointState* pPublic,
  62. IppsECCPState* pECC))
  63. {
  64. /* test pECC */
  65. IPP_BAD_PTR1_RET(pECC);
  66. /* use aligned EC context */
  67. pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) );
  68. /* test ID */
  69. IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr);
  70. /* test public key */
  71. IPP_BAD_PTR1_RET(pPublic);
  72. pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) );
  73. IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr);
  74. /* test private keys */
  75. IPP_BAD_PTR1_RET(pPrivate);
  76. pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) );
  77. IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr);
  78. IPP_BADARG_RET(!((0<cpBN_tst(pPrivate)) && (0>cpBN_cmp(pPrivate, ECP_ORDER(pECC))) ), ippStsIvalidPrivateKey);
  79. /* calculates public key */
  80. ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC));
  81. return ippStsNoErr;
  82. }