pcpbnsetca.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "pcpbn.h"
  34. /*F*
  35. // Name: ippsSetOctString_BN
  36. //
  37. // Purpose: Convert octet string into the BN value.
  38. //
  39. // Returns: Reason:
  40. // ippStsNullPtrErr NULL == pOctStr
  41. // NULL == pBN
  42. //
  43. // ippStsLengthErr 0>strLen
  44. //
  45. // ippStsSizeErr BN_ROOM() is enough for keep actual strLen
  46. //
  47. // ippStsNoErr no errors
  48. //
  49. // Parameters:
  50. // pOctStr pointer to the source octet string
  51. // strLen octet string length
  52. // pBN pointer to the target BN
  53. //
  54. *F*/
  55. IPPFUN(IppStatus, ippsSetOctString_BN,(const Ipp8u* pOctStr, cpSize strLen,
  56. IppsBigNumState* pBN))
  57. {
  58. IPP_BAD_PTR2_RET(pOctStr, pBN);
  59. pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) );
  60. IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr);
  61. IPP_BADARG_RET((0>strLen), ippStsLengthErr);
  62. /* remove leading zeros */
  63. while(strLen && (0==pOctStr[0])) {
  64. strLen--;
  65. pOctStr++;
  66. }
  67. /* test BN size */
  68. IPP_BADARG_RET((int)(sizeof(BNU_CHUNK_T)*BN_ROOM(pBN))<strLen, ippStsSizeErr);
  69. if(strLen)
  70. BN_SIZE(pBN) = cpFromOctStr_BNU(BN_NUMBER(pBN), pOctStr, strLen);
  71. else {
  72. BN_NUMBER(pBN)[0] = (BNU_CHUNK_T)0;
  73. BN_SIZE(pBN) = 1;
  74. }
  75. BN_SIGN(pBN) = ippBigNumPOS;
  76. return ippStsNoErr;
  77. }
  78. /*F*
  79. // Name: ippsGetOctString_BN
  80. //
  81. // Purpose: Convert BN value into the octet string.
  82. //
  83. // Returns: Reason:
  84. // ippStsNullPtrErr NULL == pOctStr
  85. // NULL == pBN
  86. //
  87. // ippStsRangeErr BN <0
  88. //
  89. // ippStsLengthErr strLen is enough for keep BN value
  90. //
  91. // ippStsNoErr no errors
  92. //
  93. // Parameters:
  94. // pBN pointer to the source BN
  95. // pOctStr pointer to the target octet string
  96. // strLen octet string length
  97. *F*/
  98. IPPFUN(IppStatus, ippsGetOctString_BN,(Ipp8u* pOctStr, cpSize strLen,
  99. const IppsBigNumState* pBN))
  100. {
  101. IPP_BAD_PTR2_RET(pOctStr, pBN);
  102. pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) );
  103. IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr);
  104. IPP_BADARG_RET(BN_NEGATIVE(pBN), ippStsRangeErr);
  105. IPP_BADARG_RET((0>strLen), ippStsLengthErr);
  106. return cpToOctStr_BNU(pOctStr,strLen, BN_NUMBER(pBN),BN_SIZE(pBN))? ippStsNoErr : ippStsLengthErr;
  107. }