Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of wolfSSL by
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 #ifdef FREESCALE_LTC_ECC 00051 byte pointY[CURVE25519_KEYSIZE]; 00052 #endif 00053 }ECPoint; 00054 00055 /* A CURVE25519 Key */ 00056 typedef struct { 00057 int idx; /* Index into the ecc_sets[] for the parameters of 00058 this curve if -1, this key is using user supplied 00059 curve in dp */ 00060 const curve25519_set_type* dp; /* domain parameters, either points to 00061 curves (idx >= 0) or user supplied */ 00062 ECPoint p; /* public key */ 00063 ECPoint k; /* private key */ 00064 } curve25519_key; 00065 00066 enum { 00067 EC25519_LITTLE_ENDIAN=0, 00068 EC25519_BIG_ENDIAN=1 00069 }; 00070 00071 WOLFSSL_API 00072 int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key); 00073 00074 WOLFSSL_API 00075 int wc_curve25519_shared_secret(curve25519_key* private_key, 00076 curve25519_key* public_key, 00077 byte* out, word32* outlen); 00078 00079 WOLFSSL_API 00080 int wc_curve25519_shared_secret_ex(curve25519_key* private_key, 00081 curve25519_key* public_key, 00082 byte* out, word32* outlen, int endian); 00083 00084 WOLFSSL_API 00085 int wc_curve25519_init(curve25519_key* key); 00086 00087 WOLFSSL_API 00088 void wc_curve25519_free(curve25519_key* key); 00089 00090 00091 /* raw key helpers */ 00092 WOLFSSL_API 00093 int wc_curve25519_import_private(const byte* priv, word32 privSz, 00094 curve25519_key* key); 00095 WOLFSSL_API 00096 int wc_curve25519_import_private_ex(const byte* priv, word32 privSz, 00097 curve25519_key* key, int endian); 00098 00099 WOLFSSL_API 00100 int wc_curve25519_import_private_raw(const byte* priv, word32 privSz, 00101 const byte* pub, word32 pubSz, curve25519_key* key); 00102 WOLFSSL_API 00103 int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz, 00104 const byte* pub, word32 pubSz, 00105 curve25519_key* key, int endian); 00106 WOLFSSL_API 00107 int wc_curve25519_export_private_raw(curve25519_key* key, byte* out, 00108 word32* outLen); 00109 WOLFSSL_API 00110 int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out, 00111 word32* outLen, int endian); 00112 00113 WOLFSSL_API 00114 int wc_curve25519_import_public(const byte* in, word32 inLen, 00115 curve25519_key* key); 00116 WOLFSSL_API 00117 int wc_curve25519_import_public_ex(const byte* in, word32 inLen, 00118 curve25519_key* key, int endian); 00119 00120 WOLFSSL_API 00121 int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen); 00122 WOLFSSL_API 00123 int wc_curve25519_export_public_ex(curve25519_key* key, byte* out, 00124 word32* outLen, int endian); 00125 00126 WOLFSSL_API 00127 int wc_curve25519_export_key_raw(curve25519_key* key, 00128 byte* priv, word32 *privSz, 00129 byte* pub, word32 *pubSz); 00130 WOLFSSL_API 00131 int wc_curve25519_export_key_raw_ex(curve25519_key* key, 00132 byte* priv, word32 *privSz, 00133 byte* pub, word32 *pubSz, 00134 int endian); 00135 /* size helper */ 00136 WOLFSSL_API 00137 int wc_curve25519_size(curve25519_key* key); 00138 00139 #ifdef __cplusplus 00140 } /* extern "C" */ 00141 #endif 00142 00143 #endif /* HAVE_CURVE25519 */ 00144 #endif /* WOLF_CRYPT_CURVE25519_H */ 00145 00146
Generated on Tue Jul 12 2022 23:30:55 by
1.7.2
