| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* mpihelp-mul.c - MPI helper functions |
|---|
| 2 | 3 | * Copyright (C) 1994, 1996, 1998, 1999, |
|---|
| 3 | 4 | * 2000 Free Software Foundation, Inc. |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * This file is part of GnuPG. |
|---|
| 6 | | - * |
|---|
| 7 | | - * GnuPG is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 9 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | | - * (at your option) any later version. |
|---|
| 11 | | - * |
|---|
| 12 | | - * GnuPG is distributed in the hope that it will be useful, |
|---|
| 13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | | - * GNU General Public License for more details. |
|---|
| 16 | | - * |
|---|
| 17 | | - * You should have received a copy of the GNU General Public License |
|---|
| 18 | | - * along with this program; if not, write to the Free Software |
|---|
| 19 | | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|---|
| 20 | 7 | * |
|---|
| 21 | 8 | * Note: This code is heavily based on the GNU MP Library. |
|---|
| 22 | 9 | * Actually it's the same code with only minor changes in the |
|---|
| .. | .. |
|---|
| 330 | 317 | } |
|---|
| 331 | 318 | } |
|---|
| 332 | 319 | |
|---|
| 320 | + |
|---|
| 321 | +void mpihelp_mul_n(mpi_ptr_t prodp, |
|---|
| 322 | + mpi_ptr_t up, mpi_ptr_t vp, mpi_size_t size) |
|---|
| 323 | +{ |
|---|
| 324 | + if (up == vp) { |
|---|
| 325 | + if (size < KARATSUBA_THRESHOLD) |
|---|
| 326 | + mpih_sqr_n_basecase(prodp, up, size); |
|---|
| 327 | + else { |
|---|
| 328 | + mpi_ptr_t tspace; |
|---|
| 329 | + tspace = mpi_alloc_limb_space(2 * size); |
|---|
| 330 | + mpih_sqr_n(prodp, up, size, tspace); |
|---|
| 331 | + mpi_free_limb_space(tspace); |
|---|
| 332 | + } |
|---|
| 333 | + } else { |
|---|
| 334 | + if (size < KARATSUBA_THRESHOLD) |
|---|
| 335 | + mul_n_basecase(prodp, up, vp, size); |
|---|
| 336 | + else { |
|---|
| 337 | + mpi_ptr_t tspace; |
|---|
| 338 | + tspace = mpi_alloc_limb_space(2 * size); |
|---|
| 339 | + mul_n(prodp, up, vp, size, tspace); |
|---|
| 340 | + mpi_free_limb_space(tspace); |
|---|
| 341 | + } |
|---|
| 342 | + } |
|---|
| 343 | +} |
|---|
| 344 | + |
|---|
| 333 | 345 | int |
|---|
| 334 | 346 | mpihelp_mul_karatsuba_case(mpi_ptr_t prodp, |
|---|
| 335 | 347 | mpi_ptr_t up, mpi_size_t usize, |
|---|