third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h
Go to the documentation of this file.
1 /* Copyright (c) 2020, 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 #include <openssl/base.h>
23 
24 #include "../internal.h"
25 
26 
27 #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
28 #define BORINGSSL_X25519_NEON
29 
30 // x25519_NEON is defined in asm/x25519-arm.S.
31 void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
32  const uint8_t point[32]);
33 #endif
34 
35 #if defined(BORINGSSL_HAS_UINT128)
36 #define BORINGSSL_CURVE25519_64BIT
37 #endif
38 
39 #if defined(BORINGSSL_CURVE25519_64BIT)
40 // fe means field element. Here the field is \Z/(2^255-19). An element t,
41 // entries t[0]...t[4], represents the integer t[0]+2^51 t[1]+2^102 t[2]+2^153
42 // t[3]+2^204 t[4].
43 // fe limbs are bounded by 1.125*2^51.
44 // Multiplication and carrying produce fe from fe_loose.
45 typedef struct fe { uint64_t v[5]; } fe;
46 
47 // fe_loose limbs are bounded by 3.375*2^51.
48 // Addition and subtraction produce fe_loose from (fe, fe).
49 typedef struct fe_loose { uint64_t v[5]; } fe_loose;
50 #else
51 // fe means field element. Here the field is \Z/(2^255-19). An element t,
52 // entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
53 // t[3]+2^102 t[4]+...+2^230 t[9].
54 // fe limbs are bounded by 1.125*2^26,1.125*2^25,1.125*2^26,1.125*2^25,etc.
55 // Multiplication and carrying produce fe from fe_loose.
56 typedef struct fe { uint32_t v[10]; } fe;
57 
58 // fe_loose limbs are bounded by 3.375*2^26,3.375*2^25,3.375*2^26,3.375*2^25,etc.
59 // Addition and subtraction produce fe_loose from (fe, fe).
60 typedef struct fe_loose { uint32_t v[10]; } fe_loose;
61 #endif
62 
63 // ge means group element.
64 //
65 // Here the group is the set of pairs (x,y) of field elements (see fe.h)
66 // satisfying -x^2 + y^2 = 1 + d x^2y^2
67 // where d = -121665/121666.
68 //
69 // Representations:
70 // ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
71 // ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
72 // ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
73 // ge_precomp (Duif): (y+x,y-x,2dxy)
74 
75 typedef struct {
76  fe X;
77  fe Y;
78  fe Z;
79 } ge_p2;
80 
81 typedef struct {
82  fe X;
83  fe Y;
84  fe Z;
85  fe T;
86 } ge_p3;
87 
88 typedef struct {
93 } ge_p1p1;
94 
95 typedef struct {
99 } ge_precomp;
100 
101 typedef struct {
106 } ge_cached;
107 
108 void x25519_ge_tobytes(uint8_t s[32], const ge_p2 *h);
109 int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]);
110 void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
111 void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
112 void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
113 void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
114 void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
116  ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
117 void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
118 void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
119 void x25519_sc_reduce(uint8_t s[64]);
120 
125 };
126 
133  size_t my_name_len;
139 };
140 
141 
142 #if defined(__cplusplus)
143 } // extern C
144 #endif
145 
146 #endif // OPENSSL_HEADER_CURVE25519_INTERNAL_H
x25519_ge_p1p1_to_p2
void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p)
Definition: curve25519.c:591
x25519_ge_p3_to_cached
void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p)
Definition: curve25519.c:583
x25519_ge_p1p1_to_p3
void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p)
Definition: curve25519.c:598
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
ge_p3::Z
fe Z
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:84
spake2_ctx_st::my_name
uint8_t * my_name
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:132
spake2_state_t
spake2_state_t
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:121
spake2_ctx_st::their_name
uint8_t * their_name
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:134
fe_loose::v
uint32_t v[10]
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:60
ge_p1p1
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:88
scalar
Definition: spake25519.c:317
ge_p1p1::Z
fe_loose Z
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:91
x25519_sc_reduce
void x25519_sc_reduce(uint8_t s[64])
Definition: curve25519.c:1057
spake2_ctx_st::disable_password_scalar_hack
char disable_password_scalar_hack
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:138
ge_p2::Y
fe Y
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:77
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
xds_manager.p
p
Definition: xds_manager.py:60
ge_precomp::yplusx
fe_loose yplusx
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:96
ge_cached
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:101
fe
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:56
ge_cached::T2d
fe_loose T2d
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:105
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
base.h
x25519_ge_scalarmult_base
void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32])
Definition: curve25519.c:823
ge_p3::Y
fe Y
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:83
spake2_state_msg_generated
@ spake2_state_msg_generated
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:123
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
spake2_ctx_st::their_name_len
size_t their_name_len
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:135
spake2_state_init
@ spake2_state_init
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:122
ge_precomp
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:95
x25519_ge_add
void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: curve25519.c:673
fe_loose
struct fe_loose fe_loose
spake2_role_t
spake2_role_t
Definition: curve25519.h:116
ge_p3
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:81
ge_p1p1::T
fe_loose T
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:92
ge_p1p1::Y
fe_loose Y
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:90
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
ge_p2
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:75
spake2_ctx_st::password_hash
uint8_t password_hash[64]
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:131
ge_cached::YplusX
fe_loose YplusX
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:102
fe_loose
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:60
spake2_ctx_st::my_name_len
size_t my_name_len
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:133
x25519_ge_scalarmult_small_precomp
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:724
ge_precomp::xy2d
fe_loose xy2d
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:98
ge_p1p1::X
fe_loose X
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:89
spake2_state_key_generated
@ spake2_state_key_generated
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:124
x25519_ge_scalarmult
void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A)
Definition: curve25519.c:882
point
Definition: bloaty/third_party/zlib/examples/zran.c:67
fe::v
uint32_t v[10]
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:56
spake2_ctx_st::my_role
enum spake2_role_t my_role
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:136
ge_p3::X
fe X
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:82
ge_p2::Z
fe Z
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:78
x25519_ge_tobytes
void x25519_ge_tobytes(uint8_t s[32], const ge_p2 *h)
Definition: curve25519.c:479
ge_cached::Z
fe_loose Z
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:104
private_key
Definition: hrss.c:1885
fix_build_deps.r
r
Definition: fix_build_deps.py:491
ge_p3::T
fe T
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:85
A
Definition: miscompile_with_no_unique_address_test.cc:23
spake2_ctx_st
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:127
fe
struct fe fe
spake2_ctx_st::password_scalar
uint8_t password_scalar[32]
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:130
x25519_ge_sub
void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
Definition: curve25519.c:691
x25519_ge_frombytes_vartime
int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32])
Definition: curve25519.c:503
ge_p2::X
fe X
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:76
ge_precomp::yminusx
fe_loose yminusx
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:97
spake2_ctx_st::state
enum spake2_state_t state
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:137
ge_cached::YminusX
fe_loose YminusX
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:103
spake2_ctx_st::my_msg
uint8_t my_msg[32]
Definition: third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h:129


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:07