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 1752 : #define FD_BN254_PAIRING_BATCH_MAX 16UL
11 403851 : #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 : int check_len );
45 :
46 : /* fd_bn254_g1_compress compresses a point in G1.
47 : Input in is a 64-byte big endian buffer representing the point (x, y),
48 : with additional flags.
49 : Output out will contain x, serialized as 32-byte big endian buffer,
50 : with proper flags set.
51 : Returns out on success, NULL on failure.
52 : Note: this function does NOT check that (x, y) is in G1. */
53 : uchar *
54 : fd_bn254_g1_compress( uchar out[32],
55 : uchar const in [64],
56 : int big_endian );
57 :
58 : /* fd_bn254_g1_decompress decompresses a point in G1.
59 : Input in is a 32-byte big endian buffer representing the x coord of a point,
60 : with additional flags.
61 : Output out will contain (x, y), serialized as 64-byte big endian buffer,
62 : with no flags set.
63 : Returns out on success, NULL on failure.
64 : (Success implies that (x, y) is in G1.) */
65 : uchar *
66 : fd_bn254_g1_decompress( uchar out[64],
67 : uchar const in [32],
68 : int big_endian );
69 :
70 : /* fd_bn254_g2_compress compresses a point in G2.
71 : Same as fd_bn254_g1_compress, but x, y are in Fp2, so twice as long.
72 : Input in is a 128-byte big endian buffer representing the point (x, y),
73 : with additional flags.
74 : Output out will contain x, serialized as 64-byte big endian buffer,
75 : with proper flags set.
76 : Returns out on success, NULL on failure.
77 : Note: this function does NOT check that (x, y) is in G2. */
78 : uchar *
79 : fd_bn254_g2_compress( uchar out[64],
80 : uchar const in[128],
81 : int big_endian );
82 :
83 : /* fd_bn254_g2_decompress decompresses a point in G2.
84 : Same as fd_bn254_g1_decompress, but x, y are in Fp2, so twice as long.
85 : Input in is a 64-byte big endian buffer representing the x coord of a point,
86 : with additional flags.
87 : Output out will contain (x, y), serialized as 128-byte big endian buffer,
88 : with no flags set.
89 : Returns out on success, NULL on failure.
90 : Note: this function does NOT check that (x, y) is in G2 (success does NOT
91 : imply that). */
92 : uchar *
93 : fd_bn254_g2_decompress( uchar out[128],
94 : uchar const in [64],
95 : int big_endian );
96 :
97 : FD_PROTOTYPES_END
98 :
99 : #endif /* HEADER_fd_src_ballet_bn254_fd_bn254_h */
|