fp_sqr_comba_3.i 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* fp_sqr_comba_3.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_SQR3
  22. int fp_sqr_comba3(fp_int *A, fp_int *B)
  23. {
  24. fp_digit *a, b[6], c0, c1, c2;
  25. #ifdef TFM_ISO
  26. fp_word tt;
  27. #endif
  28. a = A->dp;
  29. COMBA_START;
  30. /* clear carries */
  31. CLEAR_CARRY;
  32. /* output 0 */
  33. SQRADD(a[0],a[0]);
  34. COMBA_STORE(b[0]);
  35. /* output 1 */
  36. CARRY_FORWARD;
  37. SQRADD2(a[0], a[1]);
  38. COMBA_STORE(b[1]);
  39. /* output 2 */
  40. CARRY_FORWARD;
  41. SQRADD2(a[0], a[2]); SQRADD(a[1], a[1]);
  42. COMBA_STORE(b[2]);
  43. /* output 3 */
  44. CARRY_FORWARD;
  45. SQRADD2(a[1], a[2]);
  46. COMBA_STORE(b[3]);
  47. /* output 4 */
  48. CARRY_FORWARD;
  49. SQRADD(a[2], a[2]);
  50. COMBA_STORE(b[4]);
  51. COMBA_STORE2(b[5]);
  52. COMBA_FINI;
  53. B->used = 6;
  54. B->sign = FP_ZPOS;
  55. XMEMCPY(B->dp, b, 6 * sizeof(fp_digit));
  56. fp_clamp(B);
  57. return FP_OKAY;
  58. }
  59. #endif