bn_ppc.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/crypto.h>
  10. #include <openssl/bn.h>
  11. #include "crypto/ppc_arch.h"
  12. #include "bn_local.h"
  13. int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
  14. const BN_ULONG *np, const BN_ULONG *n0, int num)
  15. {
  16. int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
  17. const BN_ULONG *np, const BN_ULONG *n0, int num);
  18. int bn_mul4x_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
  19. const BN_ULONG *np, const BN_ULONG *n0, int num);
  20. int bn_mul_mont_fixed_n6(BN_ULONG *rp, const BN_ULONG *ap,
  21. const BN_ULONG *bp, const BN_ULONG *np,
  22. const BN_ULONG *n0, int num);
  23. int bn_mul_mont_300_fixed_n6(BN_ULONG *rp, const BN_ULONG *ap,
  24. const BN_ULONG *bp, const BN_ULONG *np,
  25. const BN_ULONG *n0, int num);
  26. if (num < 4)
  27. return 0;
  28. if ((num & 3) == 0)
  29. return bn_mul4x_mont_int(rp, ap, bp, np, n0, num);
  30. /*
  31. * There used to be [optional] call to bn_mul_mont_fpu64 here,
  32. * but above subroutine is faster on contemporary processors.
  33. * Formulation means that there might be old processors where
  34. * FPU code path would be faster, POWER6 perhaps, but there was
  35. * no opportunity to figure it out...
  36. */
  37. #if defined(_ARCH_PPC64) && !defined(__ILP32__)
  38. if (num == 6) {
  39. if (OPENSSL_ppccap_P & PPC_MADD300)
  40. return bn_mul_mont_300_fixed_n6(rp, ap, bp, np, n0, num);
  41. else
  42. return bn_mul_mont_fixed_n6(rp, ap, bp, np, n0, num);
  43. }
  44. #endif
  45. return bn_mul_mont_int(rp, ap, bp, np, n0, num);
  46. }