aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2019-02-04 13:31:50 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2019-02-04 13:31:50 +0800
commit2666a886306766e826f036fd0a23dddb468ec148 (patch)
tree8132df77028541ea88bcdb3013fdeffe462e2bd7
parent5c91aa450fc3403658e00ef060559c62f2b235ce (diff)
downloadtangerine-mcl-2666a886306766e826f036fd0a23dddb468ec148.tar.gz
tangerine-mcl-2666a886306766e826f036fd0a23dddb468ec148.tar.zst
tangerine-mcl-2666a886306766e826f036fd0a23dddb468ec148.zip
serialization format
-rw-r--r--readme.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/readme.md b/readme.md
index 8d0b7b5..7c11fc9 100644
--- a/readme.md
+++ b/readme.md
@@ -352,6 +352,32 @@ getStr() method gets
* `2 <x>` ; compressed format for even y
* `3 <x>` ; compressed format for odd y
+## Serialization format of G1 and G2
+
+pseudo-code to serialize of p
+```
+if bit-length(p) % 8 != 0:
+ size = Fp::getByteSize()
+ if p is zero:
+ return [0] * size
+ else:
+ s = x.serialize()
+ # x in Fp2 is odd <=> x.a is odd
+ if y is odd:
+ s[byte-length(s) - 1] |= 0x80
+ return s
+else:
+ size = Fp::getByteSize() + 1
+ if p is zero:
+ return [0] * size
+ else:
+ s = x.serialize()
+ if y is odd:
+ return 2:s
+ else:
+ return 3:s
+```
+
## Verify an element in G2
`G2::isValid()` checks that the element is in the curve of G2 and the order of it is r for subgroup attack.
`G2::set()`, `G2::setStr` and `operator<<` also check the order.