cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:59:36 2013 +0000
Revision:
1:b211d97b0068
Parent:
0:e979170e02e7
nothing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:e979170e02e7 1 /* ecc.h
ashleymills 0:e979170e02e7 2 *
ashleymills 0:e979170e02e7 3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
ashleymills 0:e979170e02e7 4 *
ashleymills 0:e979170e02e7 5 * This file is part of CyaSSL.
ashleymills 0:e979170e02e7 6 *
ashleymills 0:e979170e02e7 7 * CyaSSL is free software; you can redistribute it and/or modify
ashleymills 0:e979170e02e7 8 * it under the terms of the GNU General Public License as published by
ashleymills 0:e979170e02e7 9 * the Free Software Foundation; either version 2 of the License, or
ashleymills 0:e979170e02e7 10 * (at your option) any later version.
ashleymills 0:e979170e02e7 11 *
ashleymills 0:e979170e02e7 12 * CyaSSL is distributed in the hope that it will be useful,
ashleymills 0:e979170e02e7 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ashleymills 0:e979170e02e7 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ashleymills 0:e979170e02e7 15 * GNU General Public License for more details.
ashleymills 0:e979170e02e7 16 *
ashleymills 0:e979170e02e7 17 * You should have received a copy of the GNU General Public License
ashleymills 0:e979170e02e7 18 * along with this program; if not, write to the Free Software
ashleymills 0:e979170e02e7 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ashleymills 0:e979170e02e7 20 */
ashleymills 0:e979170e02e7 21
ashleymills 0:e979170e02e7 22 #ifdef HAVE_ECC
ashleymills 0:e979170e02e7 23
ashleymills 0:e979170e02e7 24 #ifndef CTAO_CRYPT_ECC_H
ashleymills 0:e979170e02e7 25 #define CTAO_CRYPT_ECC_H
ashleymills 0:e979170e02e7 26
ashleymills 0:e979170e02e7 27 #include <cyassl/ctaocrypt/types.h>
ashleymills 0:e979170e02e7 28 #include <cyassl/ctaocrypt/integer.h>
ashleymills 0:e979170e02e7 29 #include <cyassl/ctaocrypt/random.h>
ashleymills 0:e979170e02e7 30
ashleymills 0:e979170e02e7 31 #ifdef __cplusplus
ashleymills 0:e979170e02e7 32 extern "C" {
ashleymills 0:e979170e02e7 33 #endif
ashleymills 0:e979170e02e7 34
ashleymills 0:e979170e02e7 35
ashleymills 0:e979170e02e7 36 enum {
ashleymills 0:e979170e02e7 37 ECC_PUBLICKEY = 1,
ashleymills 0:e979170e02e7 38 ECC_PRIVATEKEY = 2,
ashleymills 0:e979170e02e7 39 ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */
ashleymills 0:e979170e02e7 40 SIG_HEADER_SZ = 6, /* ECC signature header size */
ashleymills 0:e979170e02e7 41 ECC_BUFSIZE = 256, /* for exported keys temp buffer */
ashleymills 0:e979170e02e7 42 ECC_MINSIZE = 20, /* MIN Private Key size */
ashleymills 0:e979170e02e7 43 ECC_MAXSIZE = 66 /* MAX Private Key size */
ashleymills 0:e979170e02e7 44 };
ashleymills 0:e979170e02e7 45
ashleymills 0:e979170e02e7 46
ashleymills 0:e979170e02e7 47 /* ECC set type defined a NIST GF(p) curve */
ashleymills 0:e979170e02e7 48 typedef struct {
ashleymills 0:e979170e02e7 49 int size; /* The size of the curve in octets */
ashleymills 0:e979170e02e7 50 const char* name; /* name of this curve */
ashleymills 0:e979170e02e7 51 const char* prime; /* prime that defines the field, curve is in (hex) */
ashleymills 0:e979170e02e7 52 const char* B; /* fields B param (hex) */
ashleymills 0:e979170e02e7 53 const char* order; /* order of the curve (hex) */
ashleymills 0:e979170e02e7 54 const char* Gx; /* x coordinate of the base point on curve (hex) */
ashleymills 0:e979170e02e7 55 const char* Gy; /* y coordinate of the base point on curve (hex) */
ashleymills 0:e979170e02e7 56 } ecc_set_type;
ashleymills 0:e979170e02e7 57
ashleymills 0:e979170e02e7 58
ashleymills 0:e979170e02e7 59 /* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) =>
ashleymills 0:e979170e02e7 60 (x/z^2, y/z^3, 1) when interpreted as affine */
ashleymills 0:e979170e02e7 61 typedef struct {
ashleymills 0:e979170e02e7 62 mp_int x; /* The x coordinate */
ashleymills 0:e979170e02e7 63 mp_int y; /* The y coordinate */
ashleymills 0:e979170e02e7 64 mp_int z; /* The z coordinate */
ashleymills 0:e979170e02e7 65 } ecc_point;
ashleymills 0:e979170e02e7 66
ashleymills 0:e979170e02e7 67
ashleymills 0:e979170e02e7 68 /* An ECC Key */
ashleymills 0:e979170e02e7 69 typedef struct {
ashleymills 0:e979170e02e7 70 int type; /* Public or Private */
ashleymills 0:e979170e02e7 71 int idx; /* Index into the ecc_sets[] for the parameters of
ashleymills 0:e979170e02e7 72 this curve if -1, this key is using user supplied
ashleymills 0:e979170e02e7 73 curve in dp */
ashleymills 0:e979170e02e7 74 const ecc_set_type* dp; /* domain parameters, either points to NIST
ashleymills 0:e979170e02e7 75 curves (idx >= 0) or user supplied */
ashleymills 0:e979170e02e7 76 ecc_point pubkey; /* public key */
ashleymills 0:e979170e02e7 77 mp_int k; /* private key */
ashleymills 0:e979170e02e7 78 } ecc_key;
ashleymills 0:e979170e02e7 79
ashleymills 0:e979170e02e7 80
ashleymills 0:e979170e02e7 81 /* ECC predefined curve sets */
ashleymills 0:e979170e02e7 82 extern const ecc_set_type ecc_sets[];
ashleymills 0:e979170e02e7 83
ashleymills 0:e979170e02e7 84
ashleymills 0:e979170e02e7 85 CYASSL_API
ashleymills 0:e979170e02e7 86 int ecc_make_key(RNG* rng, int keysize, ecc_key* key);
ashleymills 0:e979170e02e7 87 CYASSL_API
ashleymills 0:e979170e02e7 88 int ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
ashleymills 0:e979170e02e7 89 word32* outlen);
ashleymills 0:e979170e02e7 90 CYASSL_API
ashleymills 0:e979170e02e7 91 int ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
ashleymills 0:e979170e02e7 92 RNG* rng, ecc_key* key);
ashleymills 0:e979170e02e7 93 CYASSL_API
ashleymills 0:e979170e02e7 94 int ecc_verify_hash(const byte* sig, word32 siglen, byte* hash, word32 hashlen,
ashleymills 0:e979170e02e7 95 int* stat, ecc_key* key);
ashleymills 0:e979170e02e7 96 CYASSL_API
ashleymills 0:e979170e02e7 97 void ecc_init(ecc_key* key);
ashleymills 0:e979170e02e7 98 CYASSL_API
ashleymills 0:e979170e02e7 99 void ecc_free(ecc_key* key);
ashleymills 0:e979170e02e7 100
ashleymills 0:e979170e02e7 101
ashleymills 0:e979170e02e7 102 /* ASN key helpers */
ashleymills 0:e979170e02e7 103 CYASSL_API
ashleymills 0:e979170e02e7 104 int ecc_export_x963(ecc_key*, byte* out, word32* outLen);
ashleymills 0:e979170e02e7 105 CYASSL_API
ashleymills 0:e979170e02e7 106 int ecc_import_x963(const byte* in, word32 inLen, ecc_key* key);
ashleymills 0:e979170e02e7 107 CYASSL_API
ashleymills 0:e979170e02e7 108 int ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub,
ashleymills 0:e979170e02e7 109 word32 pubSz, ecc_key* key);
ashleymills 0:e979170e02e7 110
ashleymills 0:e979170e02e7 111 /* size helper */
ashleymills 0:e979170e02e7 112 CYASSL_API
ashleymills 0:e979170e02e7 113 int ecc_size(ecc_key* key);
ashleymills 0:e979170e02e7 114 CYASSL_API
ashleymills 0:e979170e02e7 115 int ecc_sig_size(ecc_key* key);
ashleymills 0:e979170e02e7 116
ashleymills 0:e979170e02e7 117 /* TODO: fix mutex types */
ashleymills 0:e979170e02e7 118 #define MUTEX_GLOBAL(x) int (x);
ashleymills 0:e979170e02e7 119 #define MUTEX_LOCK(x)
ashleymills 0:e979170e02e7 120 #define MUTEX_UNLOCK(x)
ashleymills 0:e979170e02e7 121
ashleymills 0:e979170e02e7 122
ashleymills 0:e979170e02e7 123
ashleymills 0:e979170e02e7 124 #ifdef __cplusplus
ashleymills 0:e979170e02e7 125 } /* extern "C" */
ashleymills 0:e979170e02e7 126 #endif
ashleymills 0:e979170e02e7 127
ashleymills 0:e979170e02e7 128 #endif /* CTAO_CRYPT_ECC_H */
ashleymills 0:e979170e02e7 129 #endif /* HAVE_ECC */