/*
* ***** 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 elliptic curve math library for prime field curves.
*
* The Initial Developer of the Original Code is
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Stebila <douglas@stebila.ca>, Sun Microsystems 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 ***** */
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Sun elects to use this software under the MPL license.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef _KERNEL
#include <sys/sysmacros.h>
#else
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <assert.h>
#include <time.h>
#include <sys/resource.h>
#endif /* _KERNEL */
#include "mpi.h"
#include "mplogic.h"
#include "mpprime.h"
#include "ecl.h"
#include "ecl-curve.h"
#include "ecp.h"
#include "ecc_impl.h"
#include "ec.h"
#ifndef KM_SLEEP
#define KM_SLEEP 0
#endif
#ifndef _KERNEL
/* Time k repetitions of operation op. */
int i; \
for (i = 0; i < k; i++) { \
{ op; } \
}; \
}
#else
#endif
/* Test curve using generic field arithmetic. */
printf(" Error: could not construct params.\n"); \
goto CLEANUP; \
} \
ECGroup_free(group); \
printf(" Error: could not construct group.\n"); \
goto CLEANUP; \
} \
printf("... okay.\n");
/* Test curve using specific field arithmetic. */
ECGroup_free(group); \
printf(" Warning: could not construct group.\n"); \
printf("... failed; continuing with remaining tests.\n"); \
} else { \
printf("... okay.\n"); \
}
/* Performs basic tests of elliptic curve cryptography over prime fields.
* If tests fail, then it prints an error message, aborts, and returns an
* error code. Otherwise, returns 0. */
int
{
int size;
char s[1000];
/* initialize values */
/* encode base point */
} else {
}
if (ectestPrint) {
/* output base point */
printf(" base point P:\n");
printf(" %s\n", s);
printf(" %s\n", s);
printf(" base point P (encoded):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
}
#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
/* multiply base point by order - 1 and check for negative of base
* point */
if (ectestPrint) {
printf(" (order-1)*P (affine):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected (- base point)).\n");
goto CLEANUP;
}
#endif
#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
/* multiply base point by order - 1 and check for negative of base
* point */
if (ectestPrint) {
printf(" (order-1)*P (jacobian):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected (- base point)).\n");
goto CLEANUP;
}
#endif
/* multiply base point by order - 1 and check for negative of base
* point */
if (ectestPrint) {
printf(" (order-1)*P (ECPoint_mul):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected (- base point)).\n");
goto CLEANUP;
}
/* multiply base point by order - 1 and check for negative of base
* point */
if (ectestPrint) {
printf(" (order-1)*P (ECPoint_mul):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected (- base point)).\n");
goto CLEANUP;
}
#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
/* multiply base point by order and check for point at infinity */
group));
if (ectestPrint) {
printf(" (order)*P (affine):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected point at infinity).\n");
goto CLEANUP;
}
#endif
#ifdef ECL_ENABLE_GFP_PT_MUL_JAC
/* multiply base point by order and check for point at infinity */
group));
if (ectestPrint) {
printf(" (order)*P (jacobian):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected point at infinity).\n");
goto CLEANUP;
}
#endif
/* multiply base point by order and check for point at infinity */
if (ectestPrint) {
printf(" (order)*P (ECPoint_mul):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected point at infinity).\n");
goto CLEANUP;
}
/* multiply base point by order and check for point at infinity */
if (ectestPrint) {
printf(" (order)*P (ECPoint_mul):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected point at infinity).\n");
goto CLEANUP;
}
/* check that (order-1)P + (order-1)P + P == (order-1)P */
if (ectestPrint) {
(" (order-1)*P + (order-1)*P + P == (order-1)*P (ECPoints_mul):\n");
printf(" %s\n", s);
printf(" %s\n", s);
}
printf(" Error: invalid result (expected (- base point)).\n");
goto CLEANUP;
}
/* test validate_point function */
printf(" Error: validate point on base point failed.\n");
goto CLEANUP;
}
printf(" Error: validate point on invalid point passed.\n");
goto CLEANUP;
}
if (ectestTime) {
/* compute random scalar */
goto CLEANUP;
}
/* timed test */
if (generic) {
#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
group)), 100);
#endif
100);
} else {
100);
100);
}
}
mp_clear(&n);
#ifdef _KERNEL
#else
#endif
}
return res;
}
/* Performs tests of elliptic curve cryptography over prime fields If
* tests fail, then it prints an error message, aborts, and returns an
* error code. Otherwise, returns 0. */
int
ecp_test()
{
int ectestTime = 0;
int ectestPrint = 0;
int i;
/* generic arithmetic tests */
/* specific arithmetic tests */
#ifdef _KERNEL
#else
#endif
}
return res;
}