webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
internal.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
16 #define OPENSSL_HEADER_CURVE25519_INTERNAL_H
17 
18 #if defined(__cplusplus)
19 extern "C" {
20 #endif
21 
22 
23 #if defined(OPENSSL_X86_64) && !defined(OPENSSL_SMALL) && \
24  !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_ASM)
25 #define BORINGSSL_X25519_X86_64
26 
27 void x25519_x86_64(uint8_t out[32], const uint8_t scalar[32],
28  const uint8_t point[32]);
29 #endif
30 
31 
32 #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
33 #define BORINGSSL_X25519_NEON
34 
35 /* x25519_NEON is defined in asm/x25519-arm.S. */
36 void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
37  const uint8_t point[32]);
38 #endif
39 
40 /* fe means field element. Here the field is \Z/(2^255-19). An element t,
41  * entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
42  * t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on
43  * context. */
44 typedef int32_t fe[10];
45 
46 /* ge means group element.
47 
48  * Here the group is the set of pairs (x,y) of field elements (see fe.h)
49  * satisfying -x^2 + y^2 = 1 + d x^2y^2
50  * where d = -121665/121666.
51  *
52  * Representations:
53  * ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
54  * ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
55  * ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
56  * ge_precomp (Duif): (y+x,y-x,2dxy) */
57 
58 typedef struct {
59  fe X;
60  fe Y;
61  fe Z;
62 } ge_p2;
63 
64 typedef struct {
65  fe X;
66  fe Y;
67  fe Z;
68  fe T;
69 } ge_p3;
70 
71 typedef struct {
72  fe X;
73  fe Y;
74  fe Z;
75  fe T;
76 } ge_p1p1;
77 
78 typedef struct {
79  fe yplusx;
80  fe yminusx;
81  fe xy2d;
82 } ge_precomp;
83 
84 typedef struct {
85  fe YplusX;
86  fe YminusX;
87  fe Z;
88  fe T2d;
89 } ge_cached;
90 
91 void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h);
94 void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
95 void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
96 void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
97 void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
99  ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
100 void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
101 void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
102 void x25519_sc_reduce(uint8_t *s);
103 
104 
105 #if defined(__cplusplus)
106 } /* extern C */
107 #endif
108 
109 #endif /* OPENSSL_HEADER_CURVE25519_INTERNAL_H */
fe YplusX
Definition: internal.h:85
void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p)
Definition: curve25519.c:1076
fe Y
Definition: internal.h:73
Definition: internal.h:71
DOMString p
Definition: WebCryptoAPI.idl:116
void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: curve25519.c:1160
Definition: internal.h:58
signed int int32_t
Definition: ptypes.h:101
fe T
Definition: internal.h:75
fe yminusx
Definition: internal.h:80
Definition: internal.h:64
void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p)
Definition: curve25519.c:1084
int32_t fe[10]
Definition: internal.h:44
void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: curve25519.c:1177
fe Z
Definition: internal.h:67
void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h)
Definition: curve25519.c:966
void x25519_ge_scalarmult_small_precomp(ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 *2 *32])
Definition: curve25519.c:1209
fe yplusx
Definition: internal.h:79
void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p)
Definition: curve25519.c:1091
Definition: internal.h:78
Definition: gcc-loops.cpp:33
DOMString q
Definition: WebCryptoAPI.idl:117
int int * out
Definition: gcc-loops.cpp:206
fe X
Definition: internal.h:72
Definition: internal.h:84
unsigned char uint8_t
Definition: ptypes.h:89
fe T2d
Definition: internal.h:88
fe Z
Definition: internal.h:61
fe Y
Definition: internal.h:60
void x25519_sc_reduce(uint8_t *s)
Definition: curve25519.c:3803
fe Z
Definition: internal.h:87
fe Z
Definition: internal.h:74
fe xy2d
Definition: internal.h:81
GLboolean GLboolean GLboolean GLboolean a
Definition: gl2ext.h:306
void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A)
Definition: curve25519.c:3567
GLfloat GLfloat GLfloat GLfloat h
Definition: gl2ext.h:3060
int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s)
Definition: curve25519.c:996
struct A s
fe T
Definition: internal.h:68
fe X
Definition: internal.h:65
fe Y
Definition: internal.h:66
fe YminusX
Definition: internal.h:86
fe X
Definition: internal.h:59
void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32])
GLboolean r
Definition: gl2ext.h:306