pcpbnresourceca.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "pcpbnresource.h"
  34. #include "pcpbn.h"
  35. /*
  36. // Size of BigNum List Buffer
  37. */
  38. int cpBigNumListGetSize(int feBitSize, int nodes)
  39. {
  40. /* size of buffer per single big number */
  41. int bnSize;
  42. ippsBigNumGetSize(BITS2WORD32_SIZE(feBitSize), &bnSize);
  43. /* size of buffer for whole list */
  44. return (ALIGN_VAL-1) + (sizeof(BigNumNode) + bnSize) * nodes;
  45. }
  46. /*
  47. // Init list
  48. //
  49. // Note: buffer for BN list must have appropriate alignment
  50. */
  51. void cpBigNumListInit(int feBitSize, int nodes, BigNumNode* pList)
  52. {
  53. int itemSize;
  54. /* length of Big Num */
  55. int bnLen = BITS2WORD32_SIZE(feBitSize);
  56. /* size of buffer per single big number */
  57. ippsBigNumGetSize(bnLen, &itemSize);
  58. /* size of list item */
  59. itemSize += sizeof(BigNumNode);
  60. {
  61. int n;
  62. /* init all nodes */
  63. BigNumNode* pNode = (BigNumNode*)( (Ipp8u*)pList + (nodes-1)*itemSize );
  64. BigNumNode* pNext = NULL;
  65. for(n=0; n<nodes; n++) {
  66. Ipp8u* tbnPtr = (Ipp8u*)pNode + sizeof(BigNumNode);
  67. pNode->pNext = pNext;
  68. pNode->pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(tbnPtr, ALIGN_VAL) );
  69. ippsBigNumInit(bnLen, pNode->pBN);
  70. pNext = pNode;
  71. pNode = (BigNumNode*)( (Ipp8u*)pNode - itemSize);
  72. }
  73. }
  74. }
  75. /*
  76. // Get BigNum reference
  77. */
  78. IppsBigNumState* cpBigNumListGet(BigNumNode** ppList)
  79. {
  80. if(*ppList) {
  81. IppsBigNumState* ret = (*ppList)->pBN;
  82. *ppList = (BigNumNode*)((*ppList)->pNext);
  83. return ret;
  84. }
  85. else
  86. return NULL;
  87. }