Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ge_operations.h Source File

ge_operations.h

00001 /* ge_operations.h
00002  *
00003  * Copyright (C) 2006-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023  /* Based On Daniel J Bernstein's ed25519 Public Domain ref10 work. */
00024 
00025 #ifndef WOLF_CRYPT_GE_OPERATIONS_H
00026 #define WOLF_CRYPT_GE_OPERATIONS_H
00027 
00028 #include <wolfssl/wolfcrypt/settings.h>
00029 
00030 #ifdef HAVE_ED25519
00031 
00032 #ifndef CURVED25519_SMALL
00033     #include <stdint.h>
00034 #endif
00035 #include <wolfssl/wolfcrypt/fe_operations.h>
00036 
00037 /*
00038 ge means group element.
00039 
00040 Here the group is the set of pairs (x,y) of field elements (see fe.h)
00041 satisfying -x^2 + y^2 = 1 + d x^2y^2
00042 where d = -121665/121666.
00043 
00044 Representations:
00045   ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
00046   ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
00047   ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
00048   ge_precomp (Duif): (y+x,y-x,2dxy)
00049 */
00050 
00051 
00052 typedef struct {
00053   fe X;
00054   fe Y;
00055   fe Z;
00056 } ge_p2;
00057 
00058 typedef struct {
00059   fe X;
00060   fe Y;
00061   fe Z;
00062   fe T;
00063 } ge_p3;
00064 
00065 WOLFSSL_LOCAL int  ge_compress_key(byte* out, const byte* xIn, const byte* yIn,
00066                                                                 word32 keySz);
00067 WOLFSSL_LOCAL int  ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *);
00068 
00069 WOLFSSL_LOCAL int  ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *,
00070                                          const ge_p3 *,const unsigned char *);
00071 WOLFSSL_LOCAL void ge_scalarmult_base(ge_p3 *,const unsigned char *);
00072 WOLFSSL_LOCAL void sc_reduce(byte* s);
00073 WOLFSSL_LOCAL void sc_muladd(byte* s, const byte* a, const byte* b,
00074                              const byte* c);
00075 WOLFSSL_LOCAL void ge_tobytes(unsigned char *,const ge_p2 *);
00076 WOLFSSL_LOCAL void ge_p3_tobytes(unsigned char *,const ge_p3 *);
00077 
00078 #ifndef CURVED25519_SMALL
00079 typedef struct {
00080   fe X;
00081   fe Y;
00082   fe Z;
00083   fe T;
00084 } ge_p1p1;
00085 
00086 typedef struct {
00087   fe yplusx;
00088   fe yminusx;
00089   fe xy2d;
00090 } ge_precomp;
00091 
00092 typedef struct {
00093   fe YplusX;
00094   fe YminusX;
00095   fe Z;
00096   fe T2d;
00097 } ge_cached;
00098 
00099 WOLFSSL_LOCAL void ge_p2_0(ge_p2 *);
00100 WOLFSSL_LOCAL void ge_p3_0(ge_p3 *);
00101 WOLFSSL_LOCAL void ge_precomp_0(ge_precomp *);
00102 WOLFSSL_LOCAL void ge_p3_to_p2(ge_p2 *,const ge_p3 *);
00103 WOLFSSL_LOCAL void ge_p3_to_cached(ge_cached *,const ge_p3 *);
00104 WOLFSSL_LOCAL void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *);
00105 WOLFSSL_LOCAL void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *);
00106 WOLFSSL_LOCAL void ge_p2_dbl(ge_p1p1 *,const ge_p2 *);
00107 WOLFSSL_LOCAL void ge_p3_dbl(ge_p1p1 *,const ge_p3 *);
00108 
00109 WOLFSSL_LOCAL void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
00110 WOLFSSL_LOCAL void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
00111 WOLFSSL_LOCAL void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *);
00112 WOLFSSL_LOCAL void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *);
00113 #endif /* no CURVED25519_SMALL */
00114 #endif /* HAVE_ED25519 */
00115 #endif /* WOLF_CRYPT_GE_OPERATIONS_H */
00116 
00117