bn_mp_sqrmod.c 492 B

12345678910111213141516171819202122232425
  1. #include "tommath_private.h"
  2. #ifdef BN_MP_SQRMOD_C
  3. /* LibTomMath, multiple-precision integer library -- Tom St Denis */
  4. /* SPDX-License-Identifier: Unlicense */
  5. /* c = a * a (mod b) */
  6. mp_err mp_sqrmod(const mp_int *a, const mp_int *b, mp_int *c)
  7. {
  8. mp_err err;
  9. mp_int t;
  10. if ((err = mp_init(&t)) != MP_OKAY) {
  11. return err;
  12. }
  13. if ((err = mp_sqr(a, &t)) != MP_OKAY) {
  14. goto LBL_ERR;
  15. }
  16. err = mp_mod(&t, b, c);
  17. LBL_ERR:
  18. mp_clear(&t);
  19. return err;
  20. }
  21. #endif