xref: /freebsd/crypto/openssl/crypto/bn/bn_ppc.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
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 
10 #include <openssl/crypto.h>
11 #include <openssl/bn.h>
12 #include "crypto/ppc_arch.h"
13 #include "bn_local.h"
14 
bn_mul_mont(BN_ULONG * rp,const BN_ULONG * ap,const BN_ULONG * bp,const BN_ULONG * np,const BN_ULONG * n0,int num)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 
23     if (num < 4)
24         return 0;
25 
26     if ((num & 3) == 0)
27         return bn_mul4x_mont_int(rp, ap, bp, np, n0, num);
28 
29     /*
30      * There used to be [optional] call to bn_mul_mont_fpu64 here,
31      * but above subroutine is faster on contemporary processors.
32      * Formulation means that there might be old processors where
33      * FPU code path would be faster, POWER6 perhaps, but there was
34      * no opportunity to figure it out...
35      */
36 
37     return bn_mul_mont_int(rp, ap, bp, np, n0, num);
38 }
39