Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers curve25519.h Source File

curve25519.h

00001 /* curve25519.h
00002  *
00003  * Copyright (C) 2006-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023 #ifndef WOLF_CRYPT_CURVE25519_H
00024 #define WOLF_CRYPT_CURVE25519_H
00025 
00026 #include <wolfssl/wolfcrypt/types.h>
00027 
00028 #ifdef HAVE_CURVE25519
00029 
00030 #include <wolfssl/wolfcrypt/fe_operations.h>
00031 #include <wolfssl/wolfcrypt/random.h>
00032 
00033 #ifdef __cplusplus
00034     extern "C" {
00035 #endif
00036 
00037 #define CURVE25519_KEYSIZE 32
00038 
00039 /* curve25519 set type */
00040 typedef struct {
00041     int size;       /* The size of the curve in octets */
00042     const char* name;     /* name of this curve */
00043 } curve25519_set_type;
00044 
00045 
00046 /* ECC point, the internal structure is Little endian
00047  * the mathematical functions used the endianess */
00048 typedef struct {
00049     byte point[CURVE25519_KEYSIZE];
00050 }ECPoint;
00051 
00052 /* A CURVE25519 Key */
00053 typedef struct {
00054     int idx;            /* Index into the ecc_sets[] for the parameters of
00055                            this curve if -1, this key is using user supplied
00056                            curve in dp */
00057     const curve25519_set_type* dp;   /* domain parameters, either points to
00058                                    curves (idx >= 0) or user supplied */
00059     ECPoint   p;        /* public key  */
00060     ECPoint   k;        /* private key */
00061 } curve25519_key;
00062 
00063 enum {
00064     EC25519_LITTLE_ENDIAN=0,
00065     EC25519_BIG_ENDIAN=1
00066 };
00067 
00068 WOLFSSL_API
00069 int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
00070 
00071 WOLFSSL_API
00072 int wc_curve25519_shared_secret(curve25519_key* private_key,
00073                                 curve25519_key* public_key,
00074                                 byte* out, word32* outlen);
00075 
00076 WOLFSSL_API
00077 int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
00078                                    curve25519_key* public_key,
00079                                    byte* out, word32* outlen, int endian);
00080 
00081 WOLFSSL_API
00082 int wc_curve25519_init(curve25519_key* key);
00083 
00084 WOLFSSL_API
00085 void wc_curve25519_free(curve25519_key* key);
00086 
00087 
00088 /* raw key helpers */
00089 WOLFSSL_API
00090 int wc_curve25519_import_private(const byte* priv, word32 privSz,
00091                                  curve25519_key* key);
00092 WOLFSSL_API
00093 int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
00094                                     curve25519_key* key, int endian);
00095 
00096 WOLFSSL_API
00097 int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
00098                             const byte* pub, word32 pubSz, curve25519_key* key);
00099 WOLFSSL_API
00100 int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
00101                                         const byte* pub, word32 pubSz,
00102                                         curve25519_key* key, int endian);
00103 WOLFSSL_API
00104 int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
00105                                      word32* outLen);
00106 WOLFSSL_API
00107 int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
00108                                         word32* outLen, int endian);
00109 
00110 WOLFSSL_API
00111 int wc_curve25519_import_public(const byte* in, word32 inLen,
00112                                 curve25519_key* key);
00113 WOLFSSL_API
00114 int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
00115                                    curve25519_key* key, int endian);
00116 
00117 WOLFSSL_API
00118 int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
00119 WOLFSSL_API
00120 int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
00121                                    word32* outLen, int endian);
00122 
00123 WOLFSSL_API
00124 int wc_curve25519_export_key_raw(curve25519_key* key,
00125                                  byte* priv, word32 *privSz,
00126                                  byte* pub, word32 *pubSz);
00127 WOLFSSL_API
00128 int wc_curve25519_export_key_raw_ex(curve25519_key* key,
00129                                     byte* priv, word32 *privSz,
00130                                     byte* pub, word32 *pubSz,
00131                                     int endian);
00132 /* size helper */
00133 WOLFSSL_API
00134 int wc_curve25519_size(curve25519_key* key);
00135 
00136 #ifdef __cplusplus
00137     }    /* extern "C" */
00138 #endif
00139 
00140 #endif /* HAVE_CURVE25519 */
00141 #endif /* WOLF_CRYPT_CURVE25519_H */
00142 
00143