wolfSSL 3.11.1 for TLS1.3 beta
Fork of wolfSSL by
wolfssl/wolfcrypt/ge_operations.h@4:1b0d80432c79, 2016-04-28 (annotated)
- Committer:
- wolfSSL
- Date:
- Thu Apr 28 00:57:21 2016 +0000
- Revision:
- 4:1b0d80432c79
wolfSSL 3.9.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 4:1b0d80432c79 | 1 | /* ge_operations.h |
wolfSSL | 4:1b0d80432c79 | 2 | * |
wolfSSL | 4:1b0d80432c79 | 3 | * Copyright (C) 2006-2016 wolfSSL Inc. |
wolfSSL | 4:1b0d80432c79 | 4 | * |
wolfSSL | 4:1b0d80432c79 | 5 | * This file is part of wolfSSL. |
wolfSSL | 4:1b0d80432c79 | 6 | * |
wolfSSL | 4:1b0d80432c79 | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 4:1b0d80432c79 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 4:1b0d80432c79 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 4:1b0d80432c79 | 10 | * (at your option) any later version. |
wolfSSL | 4:1b0d80432c79 | 11 | * |
wolfSSL | 4:1b0d80432c79 | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 4:1b0d80432c79 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 4:1b0d80432c79 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 4:1b0d80432c79 | 15 | * GNU General Public License for more details. |
wolfSSL | 4:1b0d80432c79 | 16 | * |
wolfSSL | 4:1b0d80432c79 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 4:1b0d80432c79 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 4:1b0d80432c79 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 4:1b0d80432c79 | 20 | */ |
wolfSSL | 4:1b0d80432c79 | 21 | |
wolfSSL | 4:1b0d80432c79 | 22 | |
wolfSSL | 4:1b0d80432c79 | 23 | /* Based On Daniel J Bernstein's ed25519 Public Domain ref10 work. */ |
wolfSSL | 4:1b0d80432c79 | 24 | |
wolfSSL | 4:1b0d80432c79 | 25 | #ifndef WOLF_CRYPT_GE_OPERATIONS_H |
wolfSSL | 4:1b0d80432c79 | 26 | #define WOLF_CRYPT_GE_OPERATIONS_H |
wolfSSL | 4:1b0d80432c79 | 27 | |
wolfSSL | 4:1b0d80432c79 | 28 | #include <wolfssl/wolfcrypt/settings.h> |
wolfSSL | 4:1b0d80432c79 | 29 | |
wolfSSL | 4:1b0d80432c79 | 30 | #ifdef HAVE_ED25519 |
wolfSSL | 4:1b0d80432c79 | 31 | |
wolfSSL | 4:1b0d80432c79 | 32 | #ifndef CURVED25519_SMALL |
wolfSSL | 4:1b0d80432c79 | 33 | #include <stdint.h> |
wolfSSL | 4:1b0d80432c79 | 34 | #endif |
wolfSSL | 4:1b0d80432c79 | 35 | #include <wolfssl/wolfcrypt/fe_operations.h> |
wolfSSL | 4:1b0d80432c79 | 36 | |
wolfSSL | 4:1b0d80432c79 | 37 | /* |
wolfSSL | 4:1b0d80432c79 | 38 | ge means group element. |
wolfSSL | 4:1b0d80432c79 | 39 | |
wolfSSL | 4:1b0d80432c79 | 40 | Here the group is the set of pairs (x,y) of field elements (see fe.h) |
wolfSSL | 4:1b0d80432c79 | 41 | satisfying -x^2 + y^2 = 1 + d x^2y^2 |
wolfSSL | 4:1b0d80432c79 | 42 | where d = -121665/121666. |
wolfSSL | 4:1b0d80432c79 | 43 | |
wolfSSL | 4:1b0d80432c79 | 44 | Representations: |
wolfSSL | 4:1b0d80432c79 | 45 | ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z |
wolfSSL | 4:1b0d80432c79 | 46 | ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT |
wolfSSL | 4:1b0d80432c79 | 47 | ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T |
wolfSSL | 4:1b0d80432c79 | 48 | ge_precomp (Duif): (y+x,y-x,2dxy) |
wolfSSL | 4:1b0d80432c79 | 49 | */ |
wolfSSL | 4:1b0d80432c79 | 50 | |
wolfSSL | 4:1b0d80432c79 | 51 | |
wolfSSL | 4:1b0d80432c79 | 52 | typedef struct { |
wolfSSL | 4:1b0d80432c79 | 53 | fe X; |
wolfSSL | 4:1b0d80432c79 | 54 | fe Y; |
wolfSSL | 4:1b0d80432c79 | 55 | fe Z; |
wolfSSL | 4:1b0d80432c79 | 56 | } ge_p2; |
wolfSSL | 4:1b0d80432c79 | 57 | |
wolfSSL | 4:1b0d80432c79 | 58 | typedef struct { |
wolfSSL | 4:1b0d80432c79 | 59 | fe X; |
wolfSSL | 4:1b0d80432c79 | 60 | fe Y; |
wolfSSL | 4:1b0d80432c79 | 61 | fe Z; |
wolfSSL | 4:1b0d80432c79 | 62 | fe T; |
wolfSSL | 4:1b0d80432c79 | 63 | } ge_p3; |
wolfSSL | 4:1b0d80432c79 | 64 | |
wolfSSL | 4:1b0d80432c79 | 65 | WOLFSSL_LOCAL int ge_compress_key(byte* out, const byte* xIn, const byte* yIn, |
wolfSSL | 4:1b0d80432c79 | 66 | word32 keySz); |
wolfSSL | 4:1b0d80432c79 | 67 | WOLFSSL_LOCAL int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *); |
wolfSSL | 4:1b0d80432c79 | 68 | |
wolfSSL | 4:1b0d80432c79 | 69 | WOLFSSL_LOCAL int ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *, |
wolfSSL | 4:1b0d80432c79 | 70 | const ge_p3 *,const unsigned char *); |
wolfSSL | 4:1b0d80432c79 | 71 | WOLFSSL_LOCAL void ge_scalarmult_base(ge_p3 *,const unsigned char *); |
wolfSSL | 4:1b0d80432c79 | 72 | WOLFSSL_LOCAL void sc_reduce(byte* s); |
wolfSSL | 4:1b0d80432c79 | 73 | WOLFSSL_LOCAL void sc_muladd(byte* s, const byte* a, const byte* b, |
wolfSSL | 4:1b0d80432c79 | 74 | const byte* c); |
wolfSSL | 4:1b0d80432c79 | 75 | WOLFSSL_LOCAL void ge_tobytes(unsigned char *,const ge_p2 *); |
wolfSSL | 4:1b0d80432c79 | 76 | WOLFSSL_LOCAL void ge_p3_tobytes(unsigned char *,const ge_p3 *); |
wolfSSL | 4:1b0d80432c79 | 77 | |
wolfSSL | 4:1b0d80432c79 | 78 | #ifndef CURVED25519_SMALL |
wolfSSL | 4:1b0d80432c79 | 79 | typedef struct { |
wolfSSL | 4:1b0d80432c79 | 80 | fe X; |
wolfSSL | 4:1b0d80432c79 | 81 | fe Y; |
wolfSSL | 4:1b0d80432c79 | 82 | fe Z; |
wolfSSL | 4:1b0d80432c79 | 83 | fe T; |
wolfSSL | 4:1b0d80432c79 | 84 | } ge_p1p1; |
wolfSSL | 4:1b0d80432c79 | 85 | |
wolfSSL | 4:1b0d80432c79 | 86 | typedef struct { |
wolfSSL | 4:1b0d80432c79 | 87 | fe yplusx; |
wolfSSL | 4:1b0d80432c79 | 88 | fe yminusx; |
wolfSSL | 4:1b0d80432c79 | 89 | fe xy2d; |
wolfSSL | 4:1b0d80432c79 | 90 | } ge_precomp; |
wolfSSL | 4:1b0d80432c79 | 91 | |
wolfSSL | 4:1b0d80432c79 | 92 | typedef struct { |
wolfSSL | 4:1b0d80432c79 | 93 | fe YplusX; |
wolfSSL | 4:1b0d80432c79 | 94 | fe YminusX; |
wolfSSL | 4:1b0d80432c79 | 95 | fe Z; |
wolfSSL | 4:1b0d80432c79 | 96 | fe T2d; |
wolfSSL | 4:1b0d80432c79 | 97 | } ge_cached; |
wolfSSL | 4:1b0d80432c79 | 98 | |
wolfSSL | 4:1b0d80432c79 | 99 | WOLFSSL_LOCAL void ge_p2_0(ge_p2 *); |
wolfSSL | 4:1b0d80432c79 | 100 | WOLFSSL_LOCAL void ge_p3_0(ge_p3 *); |
wolfSSL | 4:1b0d80432c79 | 101 | WOLFSSL_LOCAL void ge_precomp_0(ge_precomp *); |
wolfSSL | 4:1b0d80432c79 | 102 | WOLFSSL_LOCAL void ge_p3_to_p2(ge_p2 *,const ge_p3 *); |
wolfSSL | 4:1b0d80432c79 | 103 | WOLFSSL_LOCAL void ge_p3_to_cached(ge_cached *,const ge_p3 *); |
wolfSSL | 4:1b0d80432c79 | 104 | WOLFSSL_LOCAL void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *); |
wolfSSL | 4:1b0d80432c79 | 105 | WOLFSSL_LOCAL void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *); |
wolfSSL | 4:1b0d80432c79 | 106 | WOLFSSL_LOCAL void ge_p2_dbl(ge_p1p1 *,const ge_p2 *); |
wolfSSL | 4:1b0d80432c79 | 107 | WOLFSSL_LOCAL void ge_p3_dbl(ge_p1p1 *,const ge_p3 *); |
wolfSSL | 4:1b0d80432c79 | 108 | |
wolfSSL | 4:1b0d80432c79 | 109 | WOLFSSL_LOCAL void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *); |
wolfSSL | 4:1b0d80432c79 | 110 | WOLFSSL_LOCAL void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *); |
wolfSSL | 4:1b0d80432c79 | 111 | WOLFSSL_LOCAL void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *); |
wolfSSL | 4:1b0d80432c79 | 112 | WOLFSSL_LOCAL void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *); |
wolfSSL | 4:1b0d80432c79 | 113 | #endif /* no CURVED25519_SMALL */ |
wolfSSL | 4:1b0d80432c79 | 114 | #endif /* HAVE_ED25519 */ |
wolfSSL | 4:1b0d80432c79 | 115 | #endif /* WOLF_CRYPT_GE_OPERATIONS_H */ |
wolfSSL | 4:1b0d80432c79 | 116 | |
wolfSSL | 4:1b0d80432c79 | 117 |