fp_mul_comba_3.i 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* fp_mul_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_MUL3
  22. int fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C)
  23. {
  24. fp_digit c0, c1, c2, at[6];
  25. XMEMCPY(at, A->dp, 3 * sizeof(fp_digit));
  26. XMEMCPY(at+3, B->dp, 3 * sizeof(fp_digit));
  27. COMBA_START;
  28. COMBA_CLEAR;
  29. /* 0 */
  30. MULADD(at[0], at[3]);
  31. COMBA_STORE(C->dp[0]);
  32. /* 1 */
  33. COMBA_FORWARD;
  34. MULADD(at[0], at[4]); MULADD(at[1], at[3]);
  35. COMBA_STORE(C->dp[1]);
  36. /* 2 */
  37. COMBA_FORWARD;
  38. MULADD(at[0], at[5]); MULADD(at[1], at[4]); MULADD(at[2], at[3]);
  39. COMBA_STORE(C->dp[2]);
  40. /* 3 */
  41. COMBA_FORWARD;
  42. MULADD(at[1], at[5]); MULADD(at[2], at[4]);
  43. COMBA_STORE(C->dp[3]);
  44. /* 4 */
  45. COMBA_FORWARD;
  46. MULADD(at[2], at[5]);
  47. COMBA_STORE(C->dp[4]);
  48. COMBA_STORE2(C->dp[5]);
  49. C->used = 6;
  50. C->sign = A->sign ^ B->sign;
  51. fp_clamp(C);
  52. COMBA_FINI;
  53. return FP_OKAY;
  54. }
  55. #endif