bls12381_algebra - [devnet]
此内容尚不支持你的语言。
This module defines marker types, constants and test cases for working with BLS12-381 curves
using the generic API defined in algebra.move.
See https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-11#name-bls-curves-for-the-128-bit-
for the full specification of BLS12-381 curves.
Currently-supported BLS12-381 structures include Fq12, Fr, G1, G2 and Gt,
along with their widely-used serialization formats,
the pairing between G1, G2 and Gt,
and the hash-to-curve operations for G1 and G2 defined in https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16.
Other unimplemented BLS12-381 structures and serialization formats are also listed here, as they help define some of the currently supported structures. Their implementation may also be added in the future.
Fq: the finite field used in BLS12-381 curves with a prime order equal to
0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab.
FormatFqLsb: a serialization format for Fq elements,
where an element is represented by a byte array b[] of size 48 with the least significant byte (LSB) coming first.
FormatFqMsb: a serialization format for Fq elements,
where an element is represented by a byte array b[] of size 48 with the most significant byte (MSB) coming first.
Fq2: the finite field used in BLS12-381 curves,
which is an extension field of Fq, constructed as .
FormatFq2LscLsb: a serialization format for Fq2 elements,
where an element in the form is represented by a byte array b[] of size 96,
which is a concatenation of its coefficients serialized, with the least significant coefficient (LSC) coming first:
b[0..48]is serialized usingFormatFqLsb.b[48..96]is serialized usingFormatFqLsb.
FormatFq2MscMsb: a serialization format for Fq2 elements,
where an element in the form is represented by a byte array b[] of size 96,
which is a concatenation of its coefficients serialized, with the most significant coefficient (MSC) coming first:
b[0..48]is serialized usingFormatFqLsb.b[48..96]is serialized usingFormatFqLsb.
Fq6: the finite field used in BLS12-381 curves,
which is an extension field of Fq2, constructed as .
FormatFq6LscLsb: a serialization scheme for Fq6 elements,
where an element in the form is represented by a byte array b[] of size 288,
which is a concatenation of its coefficients serialized, with the least significant coefficient (LSC) coming first:
b[0..96]is serialized usingFormatFq2LscLsb.b[96..192]is serialized usingFormatFq2LscLsb.b[192..288]is serialized usingFormatFq2LscLsb.
G1Full: a group constructed by the points on the BLS12-381 curve and the point at infinity,
under the elliptic curve point addition.
It contains the prime-order subgroup used in pairing.
G2Full: a group constructed by the points on a curve and the point at infinity,
under the elliptic curve point addition.
It contains the prime-order subgroup used in pairing.
Structs
Fq12
The finite field used in BLS12-381 curves,
which is an extension field of Fq6 (defined in the module documentation), constructed as .
struct Fq12Fields
-
dummy_field: bool
FormatFq12LscLsb
A serialization scheme for Fq12 elements,
where an element is represented by a byte array b[] of size 576,
which is a concatenation of its coefficients serialized, with the least significant coefficient (LSC) coming first.
b[0..288]is serialized usingFormatFq6LscLsb(defined in the module documentation).b[288..576]is serialized usingFormatFq6LscLsb.
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0.
struct FormatFq12LscLsbFields
-
dummy_field: bool
G1
The group in BLS12-381-based pairing .
It is a subgroup of G1Full (defined in the module documentation) with a prime order
equal to 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001.
(so Fr is the associated scalar field).
struct G1Fields
-
dummy_field: bool
FormatG1Uncompr
A serialization scheme for G1 elements derived from
https://www.ietf.org/archive/id/draft-irtf-cfrg-pairing-friendly-curves-11.html#name-zcash-serialization-format-.
Below is the serialization procedure that takes a G1 element p and outputs a byte array of size 96.
- Let
(x,y)be the coordinates ofpifpis on the curve, or(0,0)otherwise. - Serialize
xandyintob_x[]andb_y[]respectively usingFormatFqMsb(defined in the module documentation). - Concatenate
b_x[]andb_y[]intob[]. - If
pis the point at infinity, set the infinity bit:b[0]: = b[0] | 0x40. - Return
b[].
Below is the deserialization procedure that takes a byte array b[] and outputs either a G1 element or none.
- If the size of
b[]is not 96, return none. - Compute the compression flag as
b[0] & 0x80 != 0. - If the compression flag is true, return none.
- Compute the infinity flag as
b[0] & 0x40 != 0. - If the infinity flag is set, return the point at infinity.
- Deserialize
[b[0] & 0x1f, b[1], …, b[47]]toxusingFormatFqMsb. Ifxis none, return none. - Deserialize
[b[48], …, b[95]]toyusingFormatFqMsb. Ifyis none, return none. - Check if
(x,y)is on curveE. If not, return none. - Check if
(x,y)is in the subgroup of orderr. If not, return none. - Return
(x,y).
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0.
struct FormatG1UncomprFields
-
dummy_field: bool
FormatG1Compr
A serialization scheme for G1 elements derived from
https://www.ietf.org/archive/id/draft-irtf-cfrg-pairing-friendly-curves-11.html#name-zcash-serialization-format-.
Below is the serialization procedure that takes a G1 element p and outputs a byte array of size 48.
- Let
(x,y)be the coordinates ofpifpis on the curve, or(0,0)otherwise. - Serialize
xintob[]usingFormatFqMsb(defined in the module documentation). - Set the compression bit:
b[0] := b[0] | 0x80. - If
pis the point at infinity, set the infinity bit:b[0]: = b[0] | 0x40. - If
y > -y, set the lexicographical flag:b[0] := b[0] | 0x20. - Return
b[].
Below is the deserialization procedure that takes a byte array b[] and outputs either a G1 element or none.
- If the size of
b[]is not 48, return none. - Compute the compression flag as
b[0] & 0x80 != 0. - If the compression flag is false, return none.
- Compute the infinity flag as
b[0] & 0x40 != 0. - If the infinity flag is set, return the point at infinity.
- Compute the lexicographical flag as
b[0] & 0x20 != 0. - Deserialize
[b[0] & 0x1f, b[1], …, b[47]]toxusingFormatFqMsb. Ifxis none, return none. - Solve the curve equation with
xfory. If no suchyexists, return none. - Let
y’bemax(y,-y)if the lexicographical flag is set, ormin(y,-y)otherwise. - Check if
(x,y’)is in the subgroup of orderr. If not, return none. - Return
(x,y’).
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0.
struct FormatG1ComprFields
-
dummy_field: bool
G2
The group in BLS12-381-based pairing .
It is a subgroup of G2Full (defined in the module documentation) with a prime order equal to
0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001.
(so Fr is the scalar field).
struct G2Fields
-
dummy_field: bool
FormatG2Uncompr
A serialization scheme for G2 elements derived from
https://www.ietf.org/archive/id/draft-irtf-cfrg-pairing-friendly-curves-11.html#name-zcash-serialization-format-.
Below is the serialization procedure that takes a G2 element p and outputs a byte array of size 192.
- Let
(x,y)be the coordinates ofpifpis on the curve, or(0,0)otherwise. - Serialize
xandyintob_x[]andb_y[]respectively usingFormatFq2MscMsb(defined in the module documentation). - Concatenate
b_x[]andb_y[]intob[]. - If
pis the point at infinity, set the infinity bit inb[]:b[0]: = b[0] | 0x40. - Return
b[].
Below is the deserialization procedure that takes a byte array b[] and outputs either a G2 element or none.
- If the size of
b[]is not 192, return none. - Compute the compression flag as
b[0] & 0x80 != 0. - If the compression flag is true, return none.
- Compute the infinity flag as
b[0] & 0x40 != 0. - If the infinity flag is set, return the point at infinity.
- Deserialize
[b[0] & 0x1f, …, b[95]]toxusingFormatFq2MscMsb. Ifxis none, return none. - Deserialize
[b[96], …, b[191]]toyusingFormatFq2MscMsb. Ifyis none, return none. - Check if
(x,y)is on the curveE’. If not, return none. - Check if
(x,y)is in the subgroup of orderr. If not, return none. - Return
(x,y).
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0.
struct FormatG2UncomprFields
-
dummy_field: bool
FormatG2Compr
A serialization scheme for G2 elements derived from
https://www.ietf.org/archive/id/draft-irtf-cfrg-pairing-friendly-curves-11.html#name-zcash-serialization-format-.
Below is the serialization procedure that takes a G2 element p and outputs a byte array of size 96.
- Let
(x,y)be the coordinates ofpifpis on the curve, or(0,0)otherwise. - Serialize
xintob[]usingFormatFq2MscMsb(defined in the module documentation). - Set the compression bit:
b[0] := b[0] | 0x80. - If
pis the point at infinity, set the infinity bit:b[0]: = b[0] | 0x40. - If
y > -y, set the lexicographical flag:b[0] := b[0] | 0x20. - Return
b[].
Below is the deserialization procedure that takes a byte array b[] and outputs either a G2 element or none.
- If the size of
b[]is not 96, return none. - Compute the compression flag as
b[0] & 0x80 != 0. - If the compression flag is false, return none.
- Compute the infinity flag as
b[0] & 0x40 != 0. - If the infinity flag is set, return the point at infinity.
- Compute the lexicographical flag as
b[0] & 0x20 != 0. - Deserialize
[b[0] & 0x1f, b[1], …, b[95]]toxusingFormatFq2MscMsb. Ifxis none, return none. - Solve the curve equation with
xfory. If no suchyexists, return none. - Let
y’bemax(y,-y)if the lexicographical flag is set, ormin(y,-y)otherwise. - Check if
(x,y’)is in the subgroup of orderr. If not, return none. - Return
(x,y’).
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0.
struct FormatG2ComprFields
-
dummy_field: bool
Gt
The group in BLS12-381-based pairing .
It is a multiplicative subgroup of Fq12,
with a prime order equal to 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001.
(so Fr is the scalar field).
The identity of Gt is 1.
struct GtFields
-
dummy_field: bool
FormatGt
A serialization scheme for Gt elements.
To serialize, it treats a Gt element p as an Fq12 element and serialize it using FormatFq12LscLsb.
To deserialize, it uses FormatFq12LscLsb to try deserializing to an Fq12 element then test the membership in Gt.
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0.
struct FormatGtFields
-
dummy_field: bool
Fr
The finite field that can be used as the scalar fields associated with the groups , , in BLS12-381-based pairing.
struct FrFields
-
dummy_field: bool
FormatFrLsb
A serialization format for Fr elements,
where an element is represented by a byte array b[] of size 32 with the least significant byte (LSB) coming first.
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0, blst-0.3.7.
struct FormatFrLsbFields
-
dummy_field: bool
FormatFrMsb
A serialization scheme for Fr elements,
where an element is represented by a byte array b[] of size 32 with the most significant byte (MSB) coming first.
NOTE: other implementation(s) using this format: ark-bls12-381-0.4.0, blst-0.3.7.
struct FormatFrMsbFields
-
dummy_field: bool
HashG1XmdSha256SswuRo
The hash-to-curve suite BLS12381G1_XMD:SHA-256_SSWU_RO_ that hashes a byte array into G1 elements.
Full specification is defined in https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#name-bls12-381-g1.
struct HashG1XmdSha256SswuRoFields
-
dummy_field: bool
HashG2XmdSha256SswuRo
The hash-to-curve suite BLS12381G2_XMD:SHA-256_SSWU_RO_ that hashes a byte array into G2 elements.
Full specification is defined in https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#name-bls12-381-g2.
struct HashG2XmdSha256SswuRoFields
-
dummy_field: bool