pcpeccpsetkeyca.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "pcpeccp.h"
  34. #include "pcpeccppoint.h"
  35. #include "pcpeccpmethod.h"
  36. #include "pcpeccpmethodcom.h"
  37. /*F*
  38. // Name: ippsECCPSetKeyPair
  39. //
  40. // Purpose: Generate (private,public) Key Pair
  41. //
  42. // Returns: Reason:
  43. // ippStsNullPtrErr NULL == pECC
  44. // NULL == pPrivate
  45. // NULL == pPublic
  46. //
  47. // ippStsContextMatchErr illegal pECC->idCtx
  48. // illegal pPrivate->idCtx
  49. // illegal pPublic->idCtx
  50. //
  51. // ippStsNoErr no errors
  52. //
  53. // Parameters:
  54. // pPrivate pointer to the private key
  55. // pPublic pointer to the public key
  56. // regular flag regular/ephemeral keys
  57. // pECC pointer to the ECCP context
  58. //
  59. *F*/
  60. IPPFUN(IppStatus, ippsECCPSetKeyPair, (const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic,
  61. IppBool regular,
  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. {
  71. IppsBigNumState* targetPrivate;
  72. IppsECCPPointState* targetPublic;
  73. if( regular ) {
  74. targetPrivate = ECP_PRIVATE(pECC);
  75. targetPublic = ECP_PUBLIC(pECC);
  76. }
  77. else {
  78. targetPrivate = ECP_PRIVATE_E(pECC);
  79. targetPublic = ECP_PUBLIC_E(pECC);
  80. }
  81. /* set up private key request */
  82. if( pPrivate ) {
  83. pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) );
  84. IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr);
  85. ippsSet_BN(ippBigNumPOS, BN_SIZE32(pPrivate), (Ipp32u*)BN_NUMBER(pPrivate), targetPrivate);
  86. }
  87. /* set up public key request */
  88. if( pPublic ) {
  89. pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) );
  90. IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr);
  91. ECP_METHOD(pECC)->GetPointAffine(ECP_POINT_X(targetPublic), ECP_POINT_Y(targetPublic), pPublic, pECC, ECP_BNCTX(pECC));
  92. ECP_METHOD(pECC)->SetPointAffine(ECP_POINT_X(targetPublic), ECP_POINT_Y(targetPublic), targetPublic, pECC);
  93. }
  94. return ippStsNoErr;
  95. }
  96. }