public class Ed25519FieldElement extends FieldElement
An element $t$, entries $t[0] \dots t[9]$, represents the integer $t[0]+2^{26} t[1]+2^{51} t[2]+2^{77} t[3]+2^{102} t[4]+\dots+2^{230} t[9]$. Bounds on each $t[i]$ vary depending on context.
Reviewed/commented by Bloody Rookie (nemproject@gmx.de)
f| 构造器和说明 |
|---|
Ed25519FieldElement(Field f,
int[] t)
Creates a field element.
|
| 限定符和类型 | 方法和说明 |
|---|---|
FieldElement |
add(FieldElement val)
$h = f + g$
TODO-CR BR: $h$ is allocated via new, probably not a good idea.
|
FieldElement |
cmov(FieldElement val,
int b)
Constant-time conditional move.
|
boolean |
equals(Object obj) |
int |
hashCode() |
FieldElement |
invert()
Invert this field element.
|
boolean |
isNonZero()
Gets a value indicating whether or not the field element is non-zero.
|
FieldElement |
multiply(FieldElement val)
$h = f * g$
Can overlap $h$ with $f$ or $g$.
|
FieldElement |
negate()
$h = -f$
TODO-CR BR: see above.
|
FieldElement |
pow22523()
Gets this field element to the power of $(2^{252} - 3)$.
|
FieldElement |
square()
$h = f * f$
Can overlap $h$ with $f$.
|
FieldElement |
squareAndDouble()
$h = 2 * f * f$
Can overlap $h$ with $f$.
|
FieldElement |
subtract(FieldElement val)
$h = f - g$
Can overlap $h$ with $f$ or $g$.
|
String |
toString() |
addOne, divide, isNegative, subtractOne, toByteArraypublic Ed25519FieldElement(Field f, int[] t)
f - The underlying field, must be the finite field with $p = 2^{255} - 19$ elementst - The $2^{25.5}$ bit representation of the field element.public boolean isNonZero()
isNonZero 在类中 FieldElementpublic FieldElement add(FieldElement val)
TODO-CR BR: $h$ is allocated via new, probably not a good idea. Do we need the copying into temp variables if we do that?
Preconditions:
Postconditions:
add 在类中 FieldElementval - The field element to add.public FieldElement subtract(FieldElement val)
Can overlap $h$ with $f$ or $g$.
TODO-CR BR: See above.
Preconditions:
Postconditions:
subtract 在类中 FieldElementval - The field element to subtract.public FieldElement negate()
TODO-CR BR: see above.
Preconditions:
Postconditions:
negate 在类中 FieldElementpublic FieldElement multiply(FieldElement val)
Can overlap $h$ with $f$ or $g$.
Preconditions:
Postconditions:
Notes on implementation strategy:
Using schoolbook multiplication. Karatsuba would save a little in some cost models.
Most multiplications by 2 and 19 are 32-bit precomputations; cheaper than 64-bit postcomputations.
There is one remaining multiplication by 19 in the carry chain; one *19 precomputation can be merged into this, but the resulting data flow is considerably less clean.
There are 12 carries below. 10 of them are 2-way parallelizable and vectorizable. Can get away with 11 carries, but then data flow is much deeper.
With tighter constraints on inputs can squeeze carries into int32.
multiply 在类中 FieldElementval - The field element to multiply.public FieldElement square()
Can overlap $h$ with $f$.
Preconditions:
Postconditions:
See multiply(FieldElement) for discussion of implementation strategy.
square 在类中 FieldElementpublic FieldElement squareAndDouble()
Can overlap $h$ with $f$.
Preconditions:
Postconditions:
See multiply(FieldElement) for discussion of implementation strategy.
squareAndDouble 在类中 FieldElementpublic FieldElement invert()
The inverse is found via Fermat's little theorem:
$a^p \cong a \mod p$ and therefore $a^{(p-2)} \cong a^{-1} \mod p$
invert 在类中 FieldElementpublic FieldElement pow22523()
TODO-CR BR: I think it makes sense to have a sqrt function.
pow22523 在类中 FieldElementpublic FieldElement cmov(FieldElement val, int b)
cmov 在类中 FieldElementval - the other field element.b - must be 0 or 1, otherwise results are undefined.Copyright © 2024 oceanbase.com. All rights reserved.