| 1 | /* |
| 2 | * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. |
| 3 | * Use is subject to license terms. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public License |
| 16 | * along with this library; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | */ |
| 23 | |
| 24 | /* ********************************************************************* |
| 25 | * |
| 26 | * The Original Code is the elliptic curve math library. |
| 27 | * |
| 28 | * The Initial Developer of the Original Code is |
| 29 | * Sun Microsystems, Inc. |
| 30 | * Portions created by the Initial Developer are Copyright (C) 2003 |
| 31 | * the Initial Developer. All Rights Reserved. |
| 32 | * |
| 33 | * Contributor(s): |
| 34 | * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories |
| 35 | * |
| 36 | * Last Modified Date from the Original Code: May 2017 |
| 37 | *********************************************************************** */ |
| 38 | |
| 39 | #ifndef _ECL_H |
| 40 | #define _ECL_H |
| 41 | |
| 42 | /* Although this is not an exported header file, code which uses elliptic |
| 43 | * curve point operations will need to include it. */ |
| 44 | |
| 45 | #include "ecl-exp.h" |
| 46 | #include "mpi.h" |
| 47 | |
| 48 | struct ECGroupStr; |
| 49 | typedef struct ECGroupStr ECGroup; |
| 50 | |
| 51 | /* Construct ECGroup from hexadecimal representations of parameters. */ |
| 52 | ECGroup *ECGroup_fromHex(const ECCurveParams * params, int kmflag); |
| 53 | |
| 54 | /* Construct ECGroup from named parameters. */ |
| 55 | ECGroup *ECGroup_fromName(const ECCurveName name, int kmflag); |
| 56 | |
| 57 | /* Free an allocated ECGroup. */ |
| 58 | void ECGroup_free(ECGroup *group); |
| 59 | |
| 60 | /* Construct ECCurveParams from an ECCurveName */ |
| 61 | ECCurveParams *EC_GetNamedCurveParams(const ECCurveName name, int kmflag); |
| 62 | |
| 63 | /* Duplicates an ECCurveParams */ |
| 64 | ECCurveParams *ECCurveParams_dup(const ECCurveParams * params, int kmflag); |
| 65 | |
| 66 | /* Free an allocated ECCurveParams */ |
| 67 | void EC_FreeCurveParams(ECCurveParams * params); |
| 68 | |
| 69 | /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k * P(x, |
| 70 | * y). If x, y = NULL, then P is assumed to be the generator (base point) |
| 71 | * of the group of points on the elliptic curve. Input and output values |
| 72 | * are assumed to be NOT field-encoded. */ |
| 73 | mp_err ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px, |
| 74 | const mp_int *py, mp_int *qx, mp_int *qy, |
| 75 | int timing); |
| 76 | |
| 77 | /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k1 * G + |
| 78 | * k2 * P(x, y), where G is the generator (base point) of the group of |
| 79 | * points on the elliptic curve. Input and output values are assumed to |
| 80 | * be NOT field-encoded. */ |
| 81 | mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1, |
| 82 | const mp_int *k2, const mp_int *px, const mp_int *py, |
| 83 | mp_int *qx, mp_int *qy, int timing); |
| 84 | |
| 85 | /* Validates an EC public key as described in Section 5.2.2 of X9.62. |
| 86 | * Returns MP_YES if the public key is valid, MP_NO if the public key |
| 87 | * is invalid, or an error code if the validation could not be |
| 88 | * performed. */ |
| 89 | mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const |
| 90 | mp_int *py); |
| 91 | |
| 92 | #endif /* _ECL_H */ |
| 93 | |