fp_sqr_comba_8.i 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* fp_sqr_comba_8.i
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef TFM_SQR8
  22. int fp_sqr_comba8(fp_int *A, fp_int *B)
  23. {
  24. fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
  25. #ifdef TFM_ISO
  26. fp_word tt;
  27. #endif
  28. #ifndef WOLFSSL_SMALL_STACK
  29. fp_digit b[16];
  30. #else
  31. fp_digit *b;
  32. #endif
  33. #ifdef WOLFSSL_SMALL_STACK
  34. b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  35. if (b == NULL)
  36. return FP_MEM;
  37. #endif
  38. a = A->dp;
  39. COMBA_START;
  40. /* clear carries */
  41. CLEAR_CARRY;
  42. /* output 0 */
  43. SQRADD(a[0],a[0]);
  44. COMBA_STORE(b[0]);
  45. /* output 1 */
  46. CARRY_FORWARD;
  47. SQRADD2(a[0], a[1]);
  48. COMBA_STORE(b[1]);
  49. /* output 2 */
  50. CARRY_FORWARD;
  51. SQRADD2(a[0], a[2]); SQRADD(a[1], a[1]);
  52. COMBA_STORE(b[2]);
  53. /* output 3 */
  54. CARRY_FORWARD;
  55. SQRADD2(a[0], a[3]); SQRADD2(a[1], a[2]);
  56. COMBA_STORE(b[3]);
  57. /* output 4 */
  58. CARRY_FORWARD;
  59. SQRADD2(a[0], a[4]); SQRADD2(a[1], a[3]); SQRADD(a[2], a[2]);
  60. COMBA_STORE(b[4]);
  61. /* output 5 */
  62. CARRY_FORWARD;
  63. SQRADDSC(a[0], a[5]); SQRADDAC(a[1], a[4]); SQRADDAC(a[2], a[3]); SQRADDDB;
  64. COMBA_STORE(b[5]);
  65. /* output 6 */
  66. CARRY_FORWARD;
  67. SQRADDSC(a[0], a[6]); SQRADDAC(a[1], a[5]); SQRADDAC(a[2], a[4]); SQRADDDB; SQRADD(a[3], a[3]);
  68. COMBA_STORE(b[6]);
  69. /* output 7 */
  70. CARRY_FORWARD;
  71. SQRADDSC(a[0], a[7]); SQRADDAC(a[1], a[6]); SQRADDAC(a[2], a[5]); SQRADDAC(a[3], a[4]); SQRADDDB;
  72. COMBA_STORE(b[7]);
  73. /* output 8 */
  74. CARRY_FORWARD;
  75. SQRADDSC(a[1], a[7]); SQRADDAC(a[2], a[6]); SQRADDAC(a[3], a[5]); SQRADDDB; SQRADD(a[4], a[4]);
  76. COMBA_STORE(b[8]);
  77. /* output 9 */
  78. CARRY_FORWARD;
  79. SQRADDSC(a[2], a[7]); SQRADDAC(a[3], a[6]); SQRADDAC(a[4], a[5]); SQRADDDB;
  80. COMBA_STORE(b[9]);
  81. /* output 10 */
  82. CARRY_FORWARD;
  83. SQRADD2(a[3], a[7]); SQRADD2(a[4], a[6]); SQRADD(a[5], a[5]);
  84. COMBA_STORE(b[10]);
  85. /* output 11 */
  86. CARRY_FORWARD;
  87. SQRADD2(a[4], a[7]); SQRADD2(a[5], a[6]);
  88. COMBA_STORE(b[11]);
  89. /* output 12 */
  90. CARRY_FORWARD;
  91. SQRADD2(a[5], a[7]); SQRADD(a[6], a[6]);
  92. COMBA_STORE(b[12]);
  93. /* output 13 */
  94. CARRY_FORWARD;
  95. SQRADD2(a[6], a[7]);
  96. COMBA_STORE(b[13]);
  97. /* output 14 */
  98. CARRY_FORWARD;
  99. SQRADD(a[7], a[7]);
  100. COMBA_STORE(b[14]);
  101. COMBA_STORE2(b[15]);
  102. COMBA_FINI;
  103. B->used = 16;
  104. B->sign = FP_ZPOS;
  105. XMEMCPY(B->dp, b, 16 * sizeof(fp_digit));
  106. fp_clamp(B);
  107. #ifdef WOLFSSL_SMALL_STACK
  108. XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  109. #endif
  110. return FP_OKAY;
  111. }
  112. #endif