ecp_mont.c revision f9fbec18f5b458b560ecf45d3db8e8bd56bf6942
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * ***** BEGIN LICENSE BLOCK *****
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Version: MPL 1.1/GPL 2.0/LGPL 2.1
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * The contents of this file are subject to the Mozilla Public License Version
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * 1.1 (the "License"); you may not use this file except in compliance with
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * the License. You may obtain a copy of the License at
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Software distributed under the License is distributed on an "AS IS" basis,
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * for the specific language governing rights and limitations under the
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * The Original Code is the elliptic curve math library.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * The Initial Developer of the Original Code is
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Sun Microsystems, Inc.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Portions created by the Initial Developer are Copyright (C) 2003
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * the Initial Developer. All Rights Reserved.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Contributor(s):
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Alternatively, the contents of this file may be used under the terms of
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * either the GNU General Public License Version 2 or later (the "GPL"), or
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * in which case the provisions of the GPL or the LGPL are applicable instead
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * of those above. If you wish to allow use of your version of this file only
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * under the terms of either the GPL or the LGPL, and not to allow others to
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * use your version of this file under the terms of the MPL, indicate your
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * decision by deleting the provisions above and replace them with the notice
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * and other provisions required by the GPL or the LGPL. If you do not delete
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * the provisions above, a recipient may use your version of this file under
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * the terms of any one of the MPL, the GPL or the LGPL.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * ***** END LICENSE BLOCK ***** */
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Use is subject to license terms.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * Sun elects to use this software under the MPL license.
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings#pragma ident "%Z%%M% %I% %E% SMI"
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings/* Uses Montgomery reduction for field arithmetic. See mpi/mpmontg.c for
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * code implementation. */
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings/* Construct a generic GFMethod for arithmetic over prime fields with
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings * irreducible irr. */
9ebd9a731316dfd624ce3bcc4ea6519d10899936Ken Stubbings mmm = (mp_mont_modulus *) kmem_alloc(sizeof(mp_mont_modulus),
goto CLEANUP;
return NULL;
return meth;
#ifdef MP_MONT_USE_MP_MUL
mp_int s;
MP_DIGITS(&s) = 0;
mp_clear(&s);
return res;
if (a == NULL) {
return res;
return res;
return res;
#ifdef _KERNEL