fp_mul_comba_4.i 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* fp_mul_comba_4.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_MUL4
  22. int fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C)
  23. {
  24. fp_digit c0, c1, c2;
  25. #ifndef WOLFSSL_SMALL_STACK
  26. fp_digit at[8];
  27. #else
  28. fp_digit *at;
  29. #endif
  30. #ifdef WOLFSSL_SMALL_STACK
  31. at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 8, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  32. if (at == NULL)
  33. return FP_MEM;
  34. #endif
  35. XMEMCPY(at, A->dp, 4 * sizeof(fp_digit));
  36. XMEMCPY(at+4, B->dp, 4 * sizeof(fp_digit));
  37. COMBA_START;
  38. COMBA_CLEAR;
  39. /* 0 */
  40. MULADD(at[0], at[4]);
  41. COMBA_STORE(C->dp[0]);
  42. /* 1 */
  43. COMBA_FORWARD;
  44. MULADD(at[0], at[5]); MULADD(at[1], at[4]);
  45. COMBA_STORE(C->dp[1]);
  46. /* 2 */
  47. COMBA_FORWARD;
  48. MULADD(at[0], at[6]); MULADD(at[1], at[5]); MULADD(at[2], at[4]);
  49. COMBA_STORE(C->dp[2]);
  50. /* 3 */
  51. COMBA_FORWARD;
  52. MULADD(at[0], at[7]); MULADD(at[1], at[6]); MULADD(at[2], at[5]); MULADD(at[3], at[4]);
  53. COMBA_STORE(C->dp[3]);
  54. /* 4 */
  55. COMBA_FORWARD;
  56. MULADD(at[1], at[7]); MULADD(at[2], at[6]); MULADD(at[3], at[5]);
  57. COMBA_STORE(C->dp[4]);
  58. /* 5 */
  59. COMBA_FORWARD;
  60. MULADD(at[2], at[7]); MULADD(at[3], at[6]);
  61. COMBA_STORE(C->dp[5]);
  62. /* 6 */
  63. COMBA_FORWARD;
  64. MULADD(at[3], at[7]);
  65. COMBA_STORE(C->dp[6]);
  66. COMBA_STORE2(C->dp[7]);
  67. C->used = 8;
  68. C->sign = A->sign ^ B->sign;
  69. fp_clamp(C);
  70. COMBA_FINI;
  71. #ifdef WOLFSSL_SMALL_STACK
  72. XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73. #endif
  74. return FP_OKAY;
  75. }
  76. #endif