ecp_384.c revision 1
2N/A * ***** BEGIN LICENSE BLOCK ***** 2N/A * Version: MPL 1.1/GPL 2.0/LGPL 2.1 2N/A * The contents of this file are subject to the Mozilla Public License Version 2N/A * 1.1 (the "License"); you may not use this file except in compliance with 2N/A * the License. You may obtain a copy of the License at 2N/A * Software distributed under the License is distributed on an "AS IS" basis, 2N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 2N/A * for the specific language governing rights and limitations under the 2N/A * The Original Code is the elliptic curve math library for prime field curves. 2N/A * The Initial Developer of the Original Code is 2N/A * Sun Microsystems, Inc. 2N/A * Portions created by the Initial Developer are Copyright (C) 2003 2N/A * the Initial Developer. All Rights Reserved. 2N/A * Douglas Stebila <douglas@stebila.ca> 2N/A * Alternatively, the contents of this file may be used under the terms of 2N/A * either the GNU General Public License Version 2 or later (the "GPL"), or 2N/A * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 2N/A * in which case the provisions of the GPL or the LGPL are applicable instead 2N/A * 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 ***** */ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Sun elects to use this software under the MPL license. /* Fast modular reduction for p384 = 2^384 - 2^128 - 2^96 + 2^32 - 1. a can be r. * Uses algorithm 2.30 from Hankerson, Menezes, Vanstone. Guide to * Elliptic Curve Cryptography. */ /* m1, m2 are statically-allocated mp_int of exactly the size we need */ for (i = 0; i <
10; i++) {
for (i = 0; i <
10; i++) {
/* for polynomials larger than twice the field size or polynomials * not using all words, use regular reduction */ for (i = 0; i <
12; i++) {
for (i = 0; i <
12; i++) {
for (i =
3; i <
12; i++) {
for (i =
4; i <
12; i++) {
for (i =
1; i <
12; i++) {
/* for polynomials larger than twice the field size or polynomials * not using all words, use regular reduction */ for (i = 0; i <
6; i++) {
for (i = 0; i <
6; i++) {
for (i =
2; i <
6; i++) {
s[
4][0] = (
MP_DIGIT(a,
11) >>
32) <<
32;
for (i =
2; i <
6; i++) {
s[
6][0] = (
MP_DIGIT(a,
10) <<
32) >>
32;
s[
6][
1] = (
MP_DIGIT(a,
10) >>
32) <<
32;
for (i =
1; i <
6; i++) {
s[
9][
1] = (
MP_DIGIT(a,
11) >>
32) <<
32;
/* Compute the square of polynomial a, reduce modulo p384. Store the * result in r. r could be a. Uses optimized modular reduction for p384. /* Compute the product of two polynomials a and b, reduce modulo p384. * Store the result in r. r could be a or b; a could be b. Uses * optimized modular reduction for p384. */ /* Wire in fast field arithmetic and precomputation of base point for