wolf SSL / wolfSSL

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:d92f9d21154c 1 /* curve25519.h
wolfSSL 0:d92f9d21154c 2 *
wolfSSL 0:d92f9d21154c 3 * Copyright (C) 2006-2015 wolfSSL Inc.
wolfSSL 0:d92f9d21154c 4 *
wolfSSL 0:d92f9d21154c 5 * This file is part of wolfSSL. (formerly known as CyaSSL)
wolfSSL 0:d92f9d21154c 6 *
wolfSSL 0:d92f9d21154c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 0:d92f9d21154c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:d92f9d21154c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:d92f9d21154c 10 * (at your option) any later version.
wolfSSL 0:d92f9d21154c 11 *
wolfSSL 0:d92f9d21154c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 0:d92f9d21154c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:d92f9d21154c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:d92f9d21154c 15 * GNU General Public License for more details.
wolfSSL 0:d92f9d21154c 16 *
wolfSSL 0:d92f9d21154c 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:d92f9d21154c 18 * along with this program; if not, write to the Free Software
wolfSSL 0:d92f9d21154c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:d92f9d21154c 20 */
wolfSSL 0:d92f9d21154c 21
wolfSSL 0:d92f9d21154c 22 #ifndef WOLF_CRYPT_CURVE25519_H
wolfSSL 0:d92f9d21154c 23 #define WOLF_CRYPT_CURVE25519_H
wolfSSL 0:d92f9d21154c 24
wolfSSL 0:d92f9d21154c 25 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 0:d92f9d21154c 26
wolfSSL 0:d92f9d21154c 27 #ifdef HAVE_CURVE25519
wolfSSL 0:d92f9d21154c 28
wolfSSL 0:d92f9d21154c 29 #include <wolfssl/wolfcrypt/fe_operations.h>
wolfSSL 0:d92f9d21154c 30 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 0:d92f9d21154c 31
wolfSSL 0:d92f9d21154c 32 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 33 extern "C" {
wolfSSL 0:d92f9d21154c 34 #endif
wolfSSL 0:d92f9d21154c 35
wolfSSL 0:d92f9d21154c 36 #define CURVE25519_KEYSIZE 32
wolfSSL 0:d92f9d21154c 37
wolfSSL 0:d92f9d21154c 38 /* curve25519 set type */
wolfSSL 0:d92f9d21154c 39 typedef struct {
wolfSSL 0:d92f9d21154c 40 int size; /* The size of the curve in octets */
wolfSSL 0:d92f9d21154c 41 const char* name; /* name of this curve */
wolfSSL 0:d92f9d21154c 42 } curve25519_set_type;
wolfSSL 0:d92f9d21154c 43
wolfSSL 0:d92f9d21154c 44
wolfSSL 0:d92f9d21154c 45 /* ECC point */
wolfSSL 0:d92f9d21154c 46 typedef struct {
wolfSSL 0:d92f9d21154c 47 byte point[CURVE25519_KEYSIZE];
wolfSSL 0:d92f9d21154c 48 }ECPoint;
wolfSSL 0:d92f9d21154c 49
wolfSSL 0:d92f9d21154c 50 /* A CURVE25519 Key */
wolfSSL 0:d92f9d21154c 51 typedef struct {
wolfSSL 0:d92f9d21154c 52 int idx; /* Index into the ecc_sets[] for the parameters of
wolfSSL 0:d92f9d21154c 53 this curve if -1, this key is using user supplied
wolfSSL 0:d92f9d21154c 54 curve in dp */
wolfSSL 0:d92f9d21154c 55 const curve25519_set_type* dp; /* domain parameters, either points to
wolfSSL 0:d92f9d21154c 56 curves (idx >= 0) or user supplied */
wolfSSL 0:d92f9d21154c 57 ECPoint p; /* public key */
wolfSSL 0:d92f9d21154c 58 ECPoint k; /* private key */
wolfSSL 0:d92f9d21154c 59 } curve25519_key;
wolfSSL 0:d92f9d21154c 60
wolfSSL 0:d92f9d21154c 61 WOLFSSL_API
wolfSSL 0:d92f9d21154c 62 int wc_curve25519_make_key(RNG* rng, int keysize, curve25519_key* key);
wolfSSL 0:d92f9d21154c 63
wolfSSL 0:d92f9d21154c 64 WOLFSSL_API
wolfSSL 0:d92f9d21154c 65 int wc_curve25519_shared_secret(curve25519_key* private_key,
wolfSSL 0:d92f9d21154c 66 curve25519_key* public_key,
wolfSSL 0:d92f9d21154c 67 byte* out, word32* outlen);
wolfSSL 0:d92f9d21154c 68
wolfSSL 0:d92f9d21154c 69 WOLFSSL_API
wolfSSL 0:d92f9d21154c 70 int wc_curve25519_init(curve25519_key* key);
wolfSSL 0:d92f9d21154c 71
wolfSSL 0:d92f9d21154c 72 WOLFSSL_API
wolfSSL 0:d92f9d21154c 73 void wc_curve25519_free(curve25519_key* key);
wolfSSL 0:d92f9d21154c 74
wolfSSL 0:d92f9d21154c 75
wolfSSL 0:d92f9d21154c 76 /* raw key helpers */
wolfSSL 0:d92f9d21154c 77 WOLFSSL_API
wolfSSL 0:d92f9d21154c 78 int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
wolfSSL 0:d92f9d21154c 79 const byte* pub, word32 pubSz, curve25519_key* key);
wolfSSL 0:d92f9d21154c 80 WOLFSSL_API
wolfSSL 0:d92f9d21154c 81 int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
wolfSSL 0:d92f9d21154c 82 word32* outLen);
wolfSSL 0:d92f9d21154c 83
wolfSSL 0:d92f9d21154c 84 WOLFSSL_API
wolfSSL 0:d92f9d21154c 85 int wc_curve25519_import_public(const byte* in, word32 inLen,
wolfSSL 0:d92f9d21154c 86 curve25519_key* key);
wolfSSL 0:d92f9d21154c 87
wolfSSL 0:d92f9d21154c 88 WOLFSSL_API
wolfSSL 0:d92f9d21154c 89 int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
wolfSSL 0:d92f9d21154c 90
wolfSSL 0:d92f9d21154c 91
wolfSSL 0:d92f9d21154c 92 /* size helper */
wolfSSL 0:d92f9d21154c 93 WOLFSSL_API
wolfSSL 0:d92f9d21154c 94 int wc_curve25519_size(curve25519_key* key);
wolfSSL 0:d92f9d21154c 95
wolfSSL 0:d92f9d21154c 96 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 97 } /* extern "C" */
wolfSSL 0:d92f9d21154c 98 #endif
wolfSSL 0:d92f9d21154c 99
wolfSSL 0:d92f9d21154c 100 #endif /* HAVE_CURVE25519 */
wolfSSL 0:d92f9d21154c 101 #endif /* WOLF_CRYPT_CURVE25519_H */
wolfSSL 0:d92f9d21154c 102
wolfSSL 0:d92f9d21154c 103