1 /* *********************************************************************
   2  *
   3  * Sun elects to have this file available under and governed by the
   4  * Mozilla Public License Version 1.1 ("MPL") (see
   5  * http://www.mozilla.org/MPL/ for full license text). For the avoidance
   6  * of doubt and subject to the following, Sun also elects to allow
   7  * licensees to use this file under the MPL, the GNU General Public
   8  * License version 2 only or the Lesser General Public License version
   9  * 2.1 only. Any references to the "GNU General Public License version 2
  10  * or later" or "GPL" in the following shall be construed to mean the
  11  * GNU General Public License version 2 only. Any references to the "GNU
  12  * Lesser General Public License version 2.1 or later" or "LGPL" in the
  13  * following shall be construed to mean the GNU Lesser General Public
  14  * License version 2.1 only. However, the following notice accompanied
  15  * the original version of this file:
  16  *
  17  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  18  *
  19  * The contents of this file are subject to the Mozilla Public License Version
  20  * 1.1 (the "License"); you may not use this file except in compliance with
  21  * the License. You may obtain a copy of the License at
  22  * http://www.mozilla.org/MPL/
  23  *
  24  * Software distributed under the License is distributed on an "AS IS" basis,
  25  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  26  * for the specific language governing rights and limitations under the
  27  * License.
  28  *
  29  * The Original Code is the elliptic curve math library.
  30  *
  31  * The Initial Developer of the Original Code is
  32  * Sun Microsystems, Inc.
  33  * Portions created by the Initial Developer are Copyright (C) 2003
  34  * the Initial Developer. All Rights Reserved.
  35  *
  36  * Contributor(s):
  37  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
  38  *
  39  * Alternatively, the contents of this file may be used under the terms of
  40  * either the GNU General Public License Version 2 or later (the "GPL"), or
  41  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  42  * in which case the provisions of the GPL or the LGPL are applicable instead
  43  * of those above. If you wish to allow use of your version of this file only
  44  * under the terms of either the GPL or the LGPL, and not to allow others to
  45  * use your version of this file under the terms of the MPL, indicate your
  46  * decision by deleting the provisions above and replace them with the notice
  47  * and other provisions required by the GPL or the LGPL. If you do not delete
  48  * the provisions above, a recipient may use your version of this file under
  49  * the terms of any one of the MPL, the GPL or the LGPL.
  50  *
  51  *********************************************************************** */
  52 /*
  53  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
  54  * Use is subject to license terms.
  55  */
  56 
  57 #ifndef _ECL_H
  58 #define _ECL_H
  59 
  60 /* Although this is not an exported header file, code which uses elliptic
  61  * curve point operations will need to include it. */
  62 
  63 #include "ecl-exp.h"
  64 #include "mpi.h"
  65 
  66 struct ECGroupStr;
  67 typedef struct ECGroupStr ECGroup;
  68 
  69 /* Construct ECGroup from hexadecimal representations of parameters. */
  70 ECGroup *ECGroup_fromHex(const ECCurveParams * params, int kmflag);
  71 
  72 /* Construct ECGroup from named parameters. */
  73 ECGroup *ECGroup_fromName(const ECCurveName name, int kmflag);
  74 
  75 /* Free an allocated ECGroup. */
  76 void ECGroup_free(ECGroup *group);
  77 
  78 /* Construct ECCurveParams from an ECCurveName */
  79 ECCurveParams *EC_GetNamedCurveParams(const ECCurveName name, int kmflag);
  80 
  81 /* Duplicates an ECCurveParams */
  82 ECCurveParams *ECCurveParams_dup(const ECCurveParams * params, int kmflag);
  83 
  84 /* Free an allocated ECCurveParams */
  85 void EC_FreeCurveParams(ECCurveParams * params);
  86 
  87 /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k * P(x,
  88  * y).  If x, y = NULL, then P is assumed to be the generator (base point)
  89  * of the group of points on the elliptic curve. Input and output values
  90  * are assumed to be NOT field-encoded. */
  91 mp_err ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px,
  92                                    const mp_int *py, mp_int *qx, mp_int *qy);
  93 
  94 /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k1 * G +
  95  * k2 * P(x, y), where G is the generator (base point) of the group of
  96  * points on the elliptic curve. Input and output values are assumed to
  97  * be NOT field-encoded. */
  98 mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1,
  99                                         const mp_int *k2, const mp_int *px, const mp_int *py,
 100                                         mp_int *qx, mp_int *qy);
 101 
 102 /* Validates an EC public key as described in Section 5.2.2 of X9.62.
 103  * Returns MP_YES if the public key is valid, MP_NO if the public key
 104  * is invalid, or an error code if the validation could not be
 105  * performed. */
 106 mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const
 107                                         mp_int *py);
 108 
 109 #endif /* _ECL_H */