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 MiniTLS-GPL by
crypto_ecc.h
00001 /* 00002 MiniTLS - A super trimmed down TLS/SSL Library for embedded devices 00003 Author: Donatien Garnier 00004 Copyright (C) 2013-2014 AppNearMe Ltd 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *//** 00020 * \file crypto_ecc.h 00021 * \copyright Copyright (c) AppNearMe Ltd 2013 00022 * \author Donatien Garnier 00023 */ 00024 00025 //This module has been adapted from libtomcrypt (http://libtom.org/) 00026 00027 #ifndef CRYPTO_ECC_H_ 00028 #define CRYPTO_ECC_H_ 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif 00033 00034 #include "core/fwk.h" 00035 #include "inc/minitls_errors.h" 00036 #include "inc/minitls_config.h" 00037 #include "crypto_prng.h" 00038 #include "crypto_math.h" 00039 00040 typedef enum __crypto_ecc_curve_type 00041 { 00042 sect163k1 = 1, sect163r1 = 2, sect163r2 = 3, 00043 sect193r1 = 4, sect193r2 = 5, sect233k1 = 6, 00044 sect233r1 = 7, sect239k1 = 8, sect283k1 = 9, 00045 sect283r1 = 10, sect409k1 = 11, sect409r1 = 12, 00046 sect571k1 = 13, sect571r1 = 14, secp160k1 = 15, 00047 secp160r1 = 16, secp160r2 = 17, secp192k1 = 18, 00048 secp192r1 = 19, secp224k1 = 20, secp224r1 = 21, 00049 secp256k1 = 22, secp256r1 = 23, secp384r1 = 24, 00050 secp521r1 = 25, 00051 //reserved = 0xFE00..0xFEFF, 00052 arbitrary_explicit_prime_curves = 0xFF01, 00053 arbitrary_explicit_char2_curves = 0xFF02, 00054 __crypto_ecc = 0xFFFF 00055 } crypto_ecc_curve_type_t; 00056 00057 typedef struct __crypto_ecc_curve 00058 { 00059 /** The size of the curve in octets */ 00060 int size; 00061 00062 /** Curve type */ 00063 crypto_ecc_curve_type_t type; 00064 00065 /** The prime that defines the field the curve is in (encoded in hex) */ 00066 char *prime; 00067 00068 /** The fields B param (hex) */ 00069 char *B; 00070 00071 /** The order of the curve (hex) */ 00072 char *order; 00073 00074 /** The x co-ordinate of the base point on the curve (hex) */ 00075 char *Gx; 00076 00077 /** The y co-ordinate of the base point on the curve (hex) */ 00078 char *Gy; 00079 } crypto_ecc_curve_t; 00080 00081 /** A point on a ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpretted as affine */ 00082 typedef struct { 00083 /** The x co-ordinate */ 00084 //void *x; 00085 fp_int x; 00086 00087 /** The y co-ordinate */ 00088 //void *y; 00089 fp_int y; 00090 00091 /** The z co-ordinate */ 00092 //void *z; 00093 fp_int z; 00094 } crypto_ecc_point_t; 00095 00096 typedef struct __crypto_ecc_public_key 00097 { 00098 const crypto_ecc_curve_t* curve; 00099 00100 crypto_ecc_point_t pubkey; 00101 } crypto_ecc_public_key_t; 00102 00103 typedef struct __crypto_ecc_private_key 00104 { 00105 crypto_ecc_public_key_t pub; 00106 fp_int privkey; 00107 } crypto_ecc_private_key_t; 00108 00109 minitls_err_t crypto_ecc_curve_get(const crypto_ecc_curve_t** curve, crypto_ecc_curve_type_t type); 00110 minitls_err_t crypto_ecc_ansi_x963_import(crypto_ecc_public_key_t* key, const crypto_ecc_curve_t* curve, const uint8_t* x963, size_t size); 00111 minitls_err_t crypto_ecc_ansi_x963_export(const crypto_ecc_public_key_t* key, /*const crypto_ecc_curve_t* curve,*/ uint8_t* x963, size_t max_size, size_t* size); 00112 minitls_err_t crypto_ecc_generate_key(crypto_ecc_private_key_t* key, const crypto_ecc_curve_t* curve, crypto_prng_t* prng); 00113 size_t crypto_ecc_get_key_size_for_curve(const crypto_ecc_curve_t* curve); 00114 00115 const crypto_ecc_public_key_t* crypto_ecc_get_public_key(const crypto_ecc_private_key_t* private_key); 00116 00117 minitls_err_t crypto_ecc_dsa_check(const crypto_ecc_public_key_t* key, const uint8_t* hash, size_t hash_size, const uint8_t* signature, size_t signature_size); 00118 00119 minitls_err_t crypto_ecc_dh_generate_shared_secret(const crypto_ecc_private_key_t* private_key, const crypto_ecc_public_key_t* public_key, uint8_t* secret, size_t max_secret_size, size_t* secret_size); 00120 00121 #ifdef __cplusplus 00122 } 00123 #endif 00124 00125 #endif /* CRYPTO_ECC_H_ */
Generated on Tue Jul 12 2022 19:20:10 by
1.7.2
