| 1 |
/* |
| 2 |
* Copyright 2009-2026 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 |
|
| 10 |
#include <openssl/crypto.h> |
| 11 |
#include <openssl/bn.h> |
| 12 |
#include "crypto/ppc_arch.h" |
| 13 |
#include "bn_local.h" |
| 14 |
|
| 15 |
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, |
| 16 |
const BN_ULONG *np, const BN_ULONG *n0, int num) |
| 17 |
{ |
| 18 |
int bn_mul_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_mul4x_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, |
| 21 |
const BN_ULONG *np, const BN_ULONG *n0, int num); |
| 22 |
int bn_mul_mont_fixed_n6(BN_ULONG *rp, const BN_ULONG *ap, |
| 23 |
const BN_ULONG *bp, const BN_ULONG *np, |
| 24 |
const BN_ULONG *n0, int num); |
| 25 |
int bn_mul_mont_300_fixed_n6(BN_ULONG *rp, const BN_ULONG *ap, |
| 26 |
const BN_ULONG *bp, const BN_ULONG *np, |
| 27 |
const BN_ULONG *n0, int num); |
| 28 |
|
| 29 |
if (num < 4) |
| 30 |
return 0; |
| 31 |
|
| 32 |
if ((num & 3) == 0) |
| 33 |
return bn_mul4x_mont_int(rp, ap, bp, np, n0, num); |
| 34 |
|
| 35 |
/* |
| 36 |
* There used to be [optional] call to bn_mul_mont_fpu64 here, |
| 37 |
* but above subroutine is faster on contemporary processors. |
| 38 |
* Formulation means that there might be old processors where |
| 39 |
* FPU code path would be faster, POWER6 perhaps, but there was |
| 40 |
* no opportunity to figure it out... |
| 41 |
*/ |
| 42 |
|
| 43 |
#if defined(_ARCH_PPC64) && !defined(__ILP32__) |
| 44 |
/* Minerva side-channel fix danny */ |
| 45 |
#if defined(USE_FIXED_N6) |
| 46 |
if (num == 6) { |
| 47 |
if (OPENSSL_ppccap_P & PPC_MADD300) |
| 48 |
return bn_mul_mont_300_fixed_n6(rp, ap, bp, np, n0, num); |
| 49 |
else |
| 50 |
return bn_mul_mont_fixed_n6(rp, ap, bp, np, n0, num); |
| 51 |
} |
| 52 |
#endif |
| 53 |
#endif |
| 54 |
|
| 55 |
return bn_mul_mont_int(rp, ap, bp, np, n0, num); |
| 56 |
} |