summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/curve25519/curve25519_internal.h
diff options
context:
space:
mode:
authorjsing <>2016-11-05 14:57:29 +0000
committerjsing <>2016-11-05 14:57:29 +0000
commit48cb83237520da9f806c7eb78b6b85778a0b02bc (patch)
treef489c520039d048388d278c2cd2c9d40a3d62afe /src/lib/libcrypto/curve25519/curve25519_internal.h
parent9f0d9655f66e938c7327e31562e13e2a11e81838 (diff)
downloadopenbsd-48cb83237520da9f806c7eb78b6b85778a0b02bc.tar.gz
openbsd-48cb83237520da9f806c7eb78b6b85778a0b02bc.tar.bz2
openbsd-48cb83237520da9f806c7eb78b6b85778a0b02bc.zip
Add support for X25519.
This brings in code from BoringSSL, which is mostly taken from SUPERCOP. ok beck@ bcook@
Diffstat (limited to 'src/lib/libcrypto/curve25519/curve25519_internal.h')
-rw-r--r--src/lib/libcrypto/curve25519/curve25519_internal.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/lib/libcrypto/curve25519/curve25519_internal.h b/src/lib/libcrypto/curve25519/curve25519_internal.h
new file mode 100644
index 0000000000..09306b9ce8
--- /dev/null
+++ b/src/lib/libcrypto/curve25519/curve25519_internal.h
@@ -0,0 +1,102 @@
1/*
2 * Copyright (c) 2015, Google Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef HEADER_CURVE25519_INTERNAL_H
18#define HEADER_CURVE25519_INTERNAL_H
19
20#include <stdint.h>
21
22#if defined(__cplusplus)
23extern "C" {
24#endif
25
26/* fe means field element. Here the field is \Z/(2^255-19). An element t,
27 * entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
28 * t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on
29 * context. */
30typedef int32_t fe[10];
31
32/* ge means group element.
33
34 * Here the group is the set of pairs (x,y) of field elements (see fe.h)
35 * satisfying -x^2 + y^2 = 1 + d x^2y^2
36 * where d = -121665/121666.
37 *
38 * Representations:
39 * ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
40 * ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
41 * ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
42 * ge_precomp (Duif): (y+x,y-x,2dxy) */
43
44typedef struct {
45 fe X;
46 fe Y;
47 fe Z;
48} ge_p2;
49
50typedef struct {
51 fe X;
52 fe Y;
53 fe Z;
54 fe T;
55} ge_p3;
56
57typedef struct {
58 fe X;
59 fe Y;
60 fe Z;
61 fe T;
62} ge_p1p1;
63
64typedef struct {
65 fe yplusx;
66 fe yminusx;
67 fe xy2d;
68} ge_precomp;
69
70typedef struct {
71 fe YplusX;
72 fe YminusX;
73 fe Z;
74 fe T2d;
75} ge_cached;
76
77void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h);
78int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
79void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
80void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
81void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
82void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
83void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
84void x25519_ge_scalarmult_small_precomp(ge_p3 *h, const uint8_t a[32],
85 const uint8_t precomp_table[15 * 2 * 32]);
86void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
87void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
88void x25519_sc_reduce(uint8_t *s);
89
90void x25519_public_from_private(uint8_t out_public_value[32],
91 const uint8_t private_key[32]);
92
93void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
94 const uint8_t point[32]);
95void x25519_scalar_mult_generic(uint8_t out[32], const uint8_t scalar[32],
96 const uint8_t point[32]);
97
98#if defined(__cplusplus)
99} /* extern C */
100#endif
101
102#endif /* HEADER_CURVE25519_INTERNAL_H */