You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
x25519 returns the result of the scalar multiplication (scalar * point), according to RFC 7748, Section 5. scalar, point and the return value are
86
+
slices of 32 bytes.
87
+
The functions take a scalar and a u-coordinate as inputs and produce a u-coordinate as output.
88
+
Although the functions work internally with integers, the inputs and outputs are 32-byte strings (for X25519) scalar can be generated at random, for example with `crypto.rand` and point should
89
+
be either base_point or the output of another `x25519` call.
90
+
91
+
[[Return to contents]](#Contents)
92
+
93
+
## Curve
94
+
```v
95
+
enum Curve {
96
+
secp256r1 = 0x0017
97
+
secp384r1 = 0x0018
98
+
secp521r1 = 0x0019
99
+
x25519 = 0x001D
100
+
x448 = 0x001E
101
+
ffdhe2048 = 0x0100
102
+
ffdhe3072 = 0x0101
103
+
ffdhe4096 = 0x0102
104
+
ffdhe6144 = 0x0103
105
+
ffdhe8192 = 0x0104
106
+
}
107
+
```
108
+
109
+
Basically, Curve is a TLS 1.3 NamedGroup.
110
+
its defined here for simplicity.
111
+
vfmt off
112
+
113
+
[[Return to contents]](#Contents)
114
+
115
+
## new_key_exchanger
116
+
```v
117
+
fn new_key_exchanger(c Curve) !KeyExchanger
118
+
```
119
+
120
+
new_key_exchanger creates new KeyExchanger for curve c, for this time, only curve25519 is supported
121
+
122
+
[[Return to contents]](#Contents)
123
+
124
+
## KeyExchanger
125
+
```v
126
+
interface KeyExchanger {
127
+
// curve_id tell the curve id
128
+
curve_id() Curve
129
+
// private_key_size should return underlying PrivateKey bytes size.
130
+
private_key_size() int
131
+
// public_key_size should return underlying PublicKey bytes size.
132
+
public_key_size() int
133
+
// generate_private_key generates random PrivateKey using entropy from secure crypto random generator.
134
+
generate_private_key() !PrivateKey
135
+
// private_key_from_key generates PrivateKey from some given key.
136
+
private_key_from_key(key []u8) !PrivateKey
137
+
// public_key returns public key corresponding to PrivateKey.
138
+
public_key(PrivateKey) !PublicKey
139
+
// shared_secret computes shared secret between alice PrivateKey and bob's PublicKey.
equal tell if two PublicKey is equal, its check if has the same curve and its also check
155
+
if underlying pubkey bytes has exactly the same length and contents.
156
+
157
+
[[Return to contents]](#Contents)
158
+
159
+
## bytes
160
+
```v
161
+
fn (pk PublicKey) bytes() ![]u8
162
+
```
163
+
164
+
bytes returns bytes content of PublicKey.
165
+
166
+
[[Return to contents]](#Contents)
167
+
168
+
## PrivateKey
169
+
## bytes
170
+
```v
171
+
fn (pv PrivateKey) bytes() ![]u8
172
+
```
173
+
174
+
bytes return PrivateKey as a bytes array
175
+
176
+
[[Return to contents]](#Contents)
177
+
178
+
## equal
179
+
```v
180
+
fn (pv PrivateKey) equal(oth PrivateKey) bool
181
+
```
182
+
183
+
equal whether two PrivateKey has equally identical (its not check pubkey part)
184
+
185
+
[[Return to contents]](#Contents)
186
+
187
+
## public_key
188
+
```v
189
+
fn (mut prv PrivateKey) public_key() !PublicKey
190
+
```
191
+
192
+
public_key is accessor for `privatekey.pubk` public key part, its does check if matching public key part or initializes PublicKey if not. Initialization is does under `sync.do_with_param`
193
+
to make sure its that a function is executed only once.
194
+
195
+
[[Return to contents]](#Contents)
196
+
197
+
## new_x25519_key_exchanger
198
+
```v
199
+
fn new_x25519_key_exchanger() KeyExchanger
200
+
```
201
+
202
+
new_x25519_key_exchanger creates new Curve25519 based ECDH key exchange protocol
203
+
204
+
[[Return to contents]](#Contents)
205
+
206
+
## Ecdh25519
207
+
## curve_id
208
+
```v
209
+
fn (ec Ecdh25519) curve_id() Curve
210
+
```
211
+
212
+
return underlying curve id
213
+
214
+
[[Return to contents]](#Contents)
215
+
216
+
## private_key_size
217
+
```v
218
+
fn (ec Ecdh25519) private_key_size() int
219
+
```
220
+
221
+
private_key_size returns private key size, in bytes
0 commit comments