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