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