/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape security libraries.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Sheueling Chang Shantz <sheueling.chang@sun.com>,
* Stephen Fung <stephen.fung@sun.com>, and
* Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
*
* Oracle elects to use this software under the MPL license.
*/
/* This file implements moduluar exponentiation using Montgomery's
* method for modular reduction. This file implements the method
* described as "Improvement 1" in the paper "A Cryptogrpahic Library for
* the Motorola DSP56000" by Stephen R. Dusse' and Burton S. Kaliski Jr.
* published in "Advances in Cryptology: Proceedings of EUROCRYPT '90"
* "Lecture Notes in Computer Science" volume 473, 1991, pg 230-244,
* published by Springer Verlag.
*/
#ifndef _KERNEL
#include <string.h>
#include <stddef.h> /* ptrdiff_t */
#endif
#include "mpi-priv.h"
#include "mplogic.h"
#include "mpprime.h"
#ifdef YF_MONTMUL
#include "bignum.h"
#endif
/* if MP_CHAR_STORE_SLOW is defined, we */
/* need to know endianness of this platform. */
#ifdef MP_CHAR_STORE_SLOW
#if !defined(MP_IS_BIG_ENDIAN) && !defined(MP_IS_LITTLE_ENDIAN)
#error "You must define MP_IS_BIG_ENDIAN or MP_IS_LITTLE_ENDIAN\n" \
" if you define MP_CHAR_STORE_SLOW."
#endif
#endif
#ifndef STATIC
#define STATIC
#endif
#ifndef _KERNEL
#if defined(_WIN32_WCE)
#else
#endif
#else /* !_KERNEL */
#endif /* _KERNEL */
/* computes T = REDC(T), 2^b == R */
{
mp_size i;
MP_CHECKOK( s_mp_pad(T, i) );
/* T += N * m_i * (MP_RADIX ** i); */
}
s_mp_clamp(T);
/* T /= R */
s_mp_div_2d(T, mmm->b);
/* T = T - N */
#ifdef DEBUG
goto CLEANUP;
}
#endif
}
return res;
}
#ifdef YF_MONTMUL
void
{
int i, useda;
uint64_t *d;
#ifdef MP_USE_UINT_DIGIT
for (i = 0; i < useda / 2; i++) {
}
if (useda & 1) {
}
d[i] = 0;
}
#else
for (i = 0; i < useda; i++) {
d[i] = ad[i];
}
#endif /* MP_USE_UINT_DIGIT */
}
void
{
int i, useda;
uint64_t *d;
#ifdef MP_USE_UINT_DIGIT
for (i = 0; i < useda / 2; i++) {
}
USED(a)--;
}
#else
for (i = 0; i < useda; i++) {
ad[i] = d[i];
}
#endif /* MP_USE_UINT_DIGIT */
}
#endif /* YF_MONTMUL */
#if !defined(MP_ASSEMBLY_MUL_MONT) && !defined(MP_MONT_USE_MP_MUL)
{
#ifdef YF_MONTMUL
{
#if BIG_CHUNK_SIZE != 64
#endif
int nsize;
/* to make big_finish a no-op if an error happens */
MP_USED(c) = 1;
MP_DIGIT(c, 0) = 0;
goto CLEANUP;
}
#ifdef MP_USE_UINT_DIGIT
#else
#endif /* MP_USE_UINT_DIGIT */
!= BIG_OK) {
goto CLEANUP_bn;
}
mpi_to_bignum64(a, &a_bn);
if (a != b) {
!= BIG_OK) {
goto CLEANUP_bn;
}
mpi_to_bignum64(b, &b_bn);
}
!= BIG_OK) {
goto CLEANUP_bn;
}
!= BIG_OK) {
goto CLEANUP_bn;
}
if (a == b) {
} else {
}
bignum64_to_mpi(&c_bn, c);
big_finish(&n_bn);
big_finish(&c_bn);
big_finish(&b_bn);
big_finish(&a_bn);
return (res);
}
#else /* YF_MONTMUL */
b = a;
a = xch;
}
goto CLEANUP;
/* Outer loop: Digits of b */
/* Inner product: Digits of a */
if (b_i)
}
}
}
s_mp_clamp(c);
s_mp_div_2d(c, mmm->b);
}
#endif /* YF_MONTMUL */
return res;
}
#endif /* !defined(MP_ASSEMBLY_MUL_MONT) && !defined(MP_MONT_USE_MP_MUL) */