blob: 9487a6c13607e07c7e975add47bf9d8839a93480 [file] [log] [blame]
Adam Langley77a173e2015-11-20 14:41:50 -08001/* 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)
19extern "C" {
20#endif
21
22
23#if defined(OPENSSL_X86_64) && !defined(OPENSSL_SMALL) && \
Adam Langleye6c54022015-12-22 08:32:08 -080024 !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_ASM)
Adam Langley77a173e2015-11-20 14:41:50 -080025#define BORINGSSL_X25519_X86_64
26
27void x25519_x86_64(uint8_t out[32], const uint8_t scalar[32],
28 const uint8_t point[32]);
29#endif
30
31
David Benjaminaff72a32017-04-06 23:26:04 -040032#if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
Adam Langleye6c54022015-12-22 08:32:08 -080033#define BORINGSSL_X25519_NEON
34
David Benjamin808f8322017-08-18 14:06:02 -040035// x25519_NEON is defined in asm/x25519-arm.S.
Adam Langley77a173e2015-11-20 14:41:50 -080036void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
37 const uint8_t point[32]);
38#endif
39
David Benjamin808f8322017-08-18 14:06:02 -040040// 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.
Arnar Birgissonf27459e2016-02-09 18:09:00 -080044typedef 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
58typedef struct {
59 fe X;
60 fe Y;
61 fe Z;
62} ge_p2;
63
64typedef struct {
65 fe X;
66 fe Y;
67 fe Z;
68 fe T;
69} ge_p3;
70
71typedef struct {
72 fe X;
73 fe Y;
74 fe Z;
75 fe T;
76} ge_p1p1;
77
78typedef struct {
79 fe yplusx;
80 fe yminusx;
81 fe xy2d;
82} ge_precomp;
83
84typedef struct {
85 fe YplusX;
86 fe YminusX;
87 fe Z;
88 fe T2d;
89} ge_cached;
90
91void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h);
92int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
93void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
94void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
95void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
96void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
97void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
98void x25519_ge_scalarmult_small_precomp(
99 ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
100void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
101void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
102void x25519_sc_reduce(uint8_t *s);
103
Adam Langley77a173e2015-11-20 14:41:50 -0800104
105#if defined(__cplusplus)
David Benjamin808f8322017-08-18 14:06:02 -0400106} // extern C
Adam Langley77a173e2015-11-20 14:41:50 -0800107#endif
108
David Benjamin808f8322017-08-18 14:06:02 -0400109#endif // OPENSSL_HEADER_CURVE25519_INTERNAL_H