Debian Codegraph @

external/boringssl/crypto/curve25519/internal.h

raw
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);
92 int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
93 void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
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);
98 void x25519_ge_scalarmult_small_precomp(
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 */