wolfSSL 3.11.1 for TLS1.3 beta
Fork of wolfSSL by
wolfssl/wolfcrypt/ge_operations.h@0:d92f9d21154c, 2015-06-26 (annotated)
- Committer:
- wolfSSL
- Date:
- Fri Jun 26 00:39:20 2015 +0000
- Revision:
- 0:d92f9d21154c
wolfSSL 3.6.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 0:d92f9d21154c | 1 | /* ge_operations.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 | /* Based On Daniel J Bernstein's ed25519 Public Domain ref10 work. */ |
wolfSSL | 0:d92f9d21154c | 23 | |
wolfSSL | 0:d92f9d21154c | 24 | #ifndef WOLF_CRYPT_GE_OPERATIONS_H |
wolfSSL | 0:d92f9d21154c | 25 | #define WOLF_CRYPT_GE_OPERATIONS_H |
wolfSSL | 0:d92f9d21154c | 26 | |
wolfSSL | 0:d92f9d21154c | 27 | #include <wolfssl/wolfcrypt/settings.h> |
wolfSSL | 0:d92f9d21154c | 28 | |
wolfSSL | 0:d92f9d21154c | 29 | #ifdef HAVE_ED25519 |
wolfSSL | 0:d92f9d21154c | 30 | |
wolfSSL | 0:d92f9d21154c | 31 | #ifndef CURVED25519_SMALL |
wolfSSL | 0:d92f9d21154c | 32 | #include <stdint.h> |
wolfSSL | 0:d92f9d21154c | 33 | #endif |
wolfSSL | 0:d92f9d21154c | 34 | #include <wolfssl/wolfcrypt/fe_operations.h> |
wolfSSL | 0:d92f9d21154c | 35 | |
wolfSSL | 0:d92f9d21154c | 36 | /* |
wolfSSL | 0:d92f9d21154c | 37 | ge means group element. |
wolfSSL | 0:d92f9d21154c | 38 | |
wolfSSL | 0:d92f9d21154c | 39 | Here the group is the set of pairs (x,y) of field elements (see fe.h) |
wolfSSL | 0:d92f9d21154c | 40 | satisfying -x^2 + y^2 = 1 + d x^2y^2 |
wolfSSL | 0:d92f9d21154c | 41 | where d = -121665/121666. |
wolfSSL | 0:d92f9d21154c | 42 | |
wolfSSL | 0:d92f9d21154c | 43 | Representations: |
wolfSSL | 0:d92f9d21154c | 44 | ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z |
wolfSSL | 0:d92f9d21154c | 45 | ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT |
wolfSSL | 0:d92f9d21154c | 46 | ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T |
wolfSSL | 0:d92f9d21154c | 47 | ge_precomp (Duif): (y+x,y-x,2dxy) |
wolfSSL | 0:d92f9d21154c | 48 | */ |
wolfSSL | 0:d92f9d21154c | 49 | |
wolfSSL | 0:d92f9d21154c | 50 | |
wolfSSL | 0:d92f9d21154c | 51 | typedef struct { |
wolfSSL | 0:d92f9d21154c | 52 | fe X; |
wolfSSL | 0:d92f9d21154c | 53 | fe Y; |
wolfSSL | 0:d92f9d21154c | 54 | fe Z; |
wolfSSL | 0:d92f9d21154c | 55 | } ge_p2; |
wolfSSL | 0:d92f9d21154c | 56 | |
wolfSSL | 0:d92f9d21154c | 57 | typedef struct { |
wolfSSL | 0:d92f9d21154c | 58 | fe X; |
wolfSSL | 0:d92f9d21154c | 59 | fe Y; |
wolfSSL | 0:d92f9d21154c | 60 | fe Z; |
wolfSSL | 0:d92f9d21154c | 61 | fe T; |
wolfSSL | 0:d92f9d21154c | 62 | } ge_p3; |
wolfSSL | 0:d92f9d21154c | 63 | |
wolfSSL | 0:d92f9d21154c | 64 | WOLFSSL_LOCAL int ge_compress_key(byte* out, const byte* xIn, const byte* yIn, |
wolfSSL | 0:d92f9d21154c | 65 | word32 keySz); |
wolfSSL | 0:d92f9d21154c | 66 | WOLFSSL_LOCAL int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *); |
wolfSSL | 0:d92f9d21154c | 67 | |
wolfSSL | 0:d92f9d21154c | 68 | WOLFSSL_LOCAL int ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *, |
wolfSSL | 0:d92f9d21154c | 69 | const ge_p3 *,const unsigned char *); |
wolfSSL | 0:d92f9d21154c | 70 | WOLFSSL_LOCAL void ge_scalarmult_base(ge_p3 *,const unsigned char *); |
wolfSSL | 0:d92f9d21154c | 71 | WOLFSSL_LOCAL void sc_reduce(byte* s); |
wolfSSL | 0:d92f9d21154c | 72 | WOLFSSL_LOCAL void sc_muladd(byte* s, const byte* a, const byte* b, |
wolfSSL | 0:d92f9d21154c | 73 | const byte* c); |
wolfSSL | 0:d92f9d21154c | 74 | WOLFSSL_LOCAL void ge_tobytes(unsigned char *,const ge_p2 *); |
wolfSSL | 0:d92f9d21154c | 75 | WOLFSSL_LOCAL void ge_p3_tobytes(unsigned char *,const ge_p3 *); |
wolfSSL | 0:d92f9d21154c | 76 | |
wolfSSL | 0:d92f9d21154c | 77 | #ifndef CURVED25519_SMALL |
wolfSSL | 0:d92f9d21154c | 78 | typedef struct { |
wolfSSL | 0:d92f9d21154c | 79 | fe X; |
wolfSSL | 0:d92f9d21154c | 80 | fe Y; |
wolfSSL | 0:d92f9d21154c | 81 | fe Z; |
wolfSSL | 0:d92f9d21154c | 82 | fe T; |
wolfSSL | 0:d92f9d21154c | 83 | } ge_p1p1; |
wolfSSL | 0:d92f9d21154c | 84 | |
wolfSSL | 0:d92f9d21154c | 85 | typedef struct { |
wolfSSL | 0:d92f9d21154c | 86 | fe yplusx; |
wolfSSL | 0:d92f9d21154c | 87 | fe yminusx; |
wolfSSL | 0:d92f9d21154c | 88 | fe xy2d; |
wolfSSL | 0:d92f9d21154c | 89 | } ge_precomp; |
wolfSSL | 0:d92f9d21154c | 90 | |
wolfSSL | 0:d92f9d21154c | 91 | typedef struct { |
wolfSSL | 0:d92f9d21154c | 92 | fe YplusX; |
wolfSSL | 0:d92f9d21154c | 93 | fe YminusX; |
wolfSSL | 0:d92f9d21154c | 94 | fe Z; |
wolfSSL | 0:d92f9d21154c | 95 | fe T2d; |
wolfSSL | 0:d92f9d21154c | 96 | } ge_cached; |
wolfSSL | 0:d92f9d21154c | 97 | |
wolfSSL | 0:d92f9d21154c | 98 | WOLFSSL_LOCAL void ge_p2_0(ge_p2 *); |
wolfSSL | 0:d92f9d21154c | 99 | WOLFSSL_LOCAL void ge_p3_0(ge_p3 *); |
wolfSSL | 0:d92f9d21154c | 100 | WOLFSSL_LOCAL void ge_precomp_0(ge_precomp *); |
wolfSSL | 0:d92f9d21154c | 101 | WOLFSSL_LOCAL void ge_p3_to_p2(ge_p2 *,const ge_p3 *); |
wolfSSL | 0:d92f9d21154c | 102 | WOLFSSL_LOCAL void ge_p3_to_cached(ge_cached *,const ge_p3 *); |
wolfSSL | 0:d92f9d21154c | 103 | WOLFSSL_LOCAL void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *); |
wolfSSL | 0:d92f9d21154c | 104 | WOLFSSL_LOCAL void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *); |
wolfSSL | 0:d92f9d21154c | 105 | WOLFSSL_LOCAL void ge_p2_dbl(ge_p1p1 *,const ge_p2 *); |
wolfSSL | 0:d92f9d21154c | 106 | WOLFSSL_LOCAL void ge_p3_dbl(ge_p1p1 *,const ge_p3 *); |
wolfSSL | 0:d92f9d21154c | 107 | |
wolfSSL | 0:d92f9d21154c | 108 | WOLFSSL_LOCAL void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *); |
wolfSSL | 0:d92f9d21154c | 109 | WOLFSSL_LOCAL void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *); |
wolfSSL | 0:d92f9d21154c | 110 | WOLFSSL_LOCAL void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *); |
wolfSSL | 0:d92f9d21154c | 111 | WOLFSSL_LOCAL void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *); |
wolfSSL | 0:d92f9d21154c | 112 | #endif /* no CURVED25519_SMALL */ |
wolfSSL | 0:d92f9d21154c | 113 | #endif /* HAVE_ED25519 */ |
wolfSSL | 0:d92f9d21154c | 114 | #endif /* WOLF_CRYPT_GE_OPERATIONS_H */ |
wolfSSL | 0:d92f9d21154c | 115 | |
wolfSSL | 0:d92f9d21154c | 116 |