fp_sqr_comba_4.i 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* fp_sqr_comba_4.i
  2. *
  3. * Copyright (C) 2006-2020 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_SQR4
  22. int fp_sqr_comba4(fp_int *A, fp_int *B)
  23. {
  24. fp_digit *a, c0, c1, c2;
  25. #ifdef TFM_ISO
  26. fp_word tt;
  27. #endif
  28. #ifndef WOLFSSL_SMALL_STACK
  29. fp_digit b[8];
  30. #else
  31. fp_digit *b;
  32. #endif
  33. #ifdef WOLFSSL_SMALL_STACK
  34. b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 8, 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[1], a[3]); SQRADD(a[2], a[2]);
  60. COMBA_STORE(b[4]);
  61. /* output 5 */
  62. CARRY_FORWARD;
  63. SQRADD2(a[2], a[3]);
  64. COMBA_STORE(b[5]);
  65. /* output 6 */
  66. CARRY_FORWARD;
  67. SQRADD(a[3], a[3]);
  68. COMBA_STORE(b[6]);
  69. COMBA_STORE2(b[7]);
  70. COMBA_FINI;
  71. B->used = 8;
  72. B->sign = FP_ZPOS;
  73. XMEMCPY(B->dp, b, 8 * sizeof(fp_digit));
  74. fp_clamp(B);
  75. #ifdef WOLFSSL_SMALL_STACK
  76. XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77. #endif
  78. return FP_OKAY;
  79. }
  80. #endif