Line data Source code
1 : #ifndef HEADER_fd_src_ballet_bn254_fd_bn254_h
2 : #define HEADER_fd_src_ballet_bn254_fd_bn254_h
3 :
4 : /* fd_bn254 implements utility functions for the bn254 (alt_bn128) curve. */
5 :
6 : #include "../fd_ballet_base.h"
7 : #include "../bigint/fd_uint256.h"
8 : #include "./fd_bn254_scalar.h"
9 :
10 876 : #define FD_BN254_PAIRING_BATCH_MAX 16UL
11 1078902 : #define FD_BIG_ENDIAN_LIKELY FD_LIKELY
12 :
13 : FD_PROTOTYPES_BEGIN
14 :
15 : int
16 : fd_bn254_g1_add_syscall( uchar out[64],
17 : uchar const in[],
18 : ulong in_sz,
19 : int big_endian );
20 :
21 : int
22 : fd_bn254_g1_scalar_mul_syscall( uchar out[64],
23 : uchar const in[],
24 : ulong in_sz,
25 : int big_endian );
26 :
27 : int
28 : fd_bn254_g2_add_syscall( uchar out[128],
29 : uchar const in[],
30 : ulong in_sz,
31 : int big_endian );
32 :
33 : int
34 : fd_bn254_g2_scalar_mul_syscall( uchar out[128],
35 : uchar const in[],
36 : ulong in_sz,
37 : int big_endian );
38 :
39 : int
40 : fd_bn254_pairing_is_one_syscall( uchar out[32],
41 : uchar const in[],
42 : ulong in_sz,
43 : int big_endian );
44 :
45 : /* fd_bn254_g1_compress compresses a point in G1.
46 : Input in is a 64-byte big endian buffer representing the point (x, y),
47 : with additional flags.
48 : Output out will contain x, serialized as 32-byte big endian buffer,
49 : with proper flags set.
50 : Returns out on success, NULL on failure.
51 : Note: this function does NOT check that (x, y) is in G1. */
52 : uchar *
53 : fd_bn254_g1_compress( uchar out[32],
54 : uchar const in [64],
55 : int big_endian );
56 :
57 : /* fd_bn254_g1_decompress decompresses a point in G1.
58 : Input in is a 32-byte big endian buffer representing the x coord of a point,
59 : with additional flags.
60 : Output out will contain (x, y), serialized as 64-byte big endian buffer,
61 : with no flags set.
62 : Returns out on success, NULL on failure.
63 : (Success implies that (x, y) is in G1.) */
64 : uchar *
65 : fd_bn254_g1_decompress( uchar out[64],
66 : uchar const in [32],
67 : int big_endian );
68 :
69 : /* fd_bn254_g2_compress compresses a point in G2.
70 : Same as fd_bn254_g1_compress, but x, y are in Fp2, so twice as long.
71 : Input in is a 128-byte big endian buffer representing the point (x, y),
72 : with additional flags.
73 : Output out will contain x, serialized as 64-byte big endian buffer,
74 : with proper flags set.
75 : Returns out on success, NULL on failure.
76 : Note: this function does NOT check that (x, y) is in G2. */
77 : uchar *
78 : fd_bn254_g2_compress( uchar out[64],
79 : uchar const in[128],
80 : int big_endian );
81 :
82 : /* fd_bn254_g2_decompress decompresses a point in G2.
83 : Same as fd_bn254_g1_decompress, but x, y are in Fp2, so twice as long.
84 : Input in is a 64-byte big endian buffer representing the x coord of a point,
85 : with additional flags.
86 : Output out will contain (x, y), serialized as 128-byte big endian buffer,
87 : with no flags set.
88 : Returns out on success, NULL on failure.
89 : Note: this function does NOT check that (x, y) is in G2 (success does NOT
90 : imply that). */
91 : uchar *
92 : fd_bn254_g2_decompress( uchar out[128],
93 : uchar const in [64],
94 : int big_endian );
95 :
96 : FD_PROTOTYPES_END
97 :
98 : #endif /* HEADER_fd_src_ballet_bn254_fd_bn254_h */
|