Interface SecpFieldElement
- All Known Implementing Classes:
SecpFieldElementImpl
public interface SecpFieldElement
A number that is a valid element of the P256K1 field. We use this instead of
BigInteger
so we can use a fixed-length, unsigned representation for simplicity and performance.-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]checkInRange(byte[] e) ThrowIllegalArgumentExceptionif the byte array is not the length.static BigIntegerThrowIllegalArgumentExceptionif an integer is not in the inclusive range0toP - 1, wherePis the prime of the SECP256K1 prime finite field.static byte[]Convert a BigInteger to a fixed-length byte arraystatic booleanCheck if an integer is in the inclusive range0toP - 1, wherePis the prime of the SECG P256K1 prime finite field.booleanisOdd()Get the parity of the field valuestatic SecpFieldElementof(byte[] bytes) Construct a field element from a byte-array of 32 bytesstatic SecpFieldElementof(BigInteger i) Construct aSecpFieldElementfrom a BigIntegerbyte[]Get serialized field element (32 bytes unsigned)Get the field element as aBigInteger
-
Method Details
-
toBigInteger
-
serialize
byte[] serialize()Get serialized field element (32 bytes unsigned)- Returns:
- serialized field element
-
isOdd
boolean isOdd()Get the parity of the field value- Returns:
trueif odd,falseif even
-
of
Construct aSecpFieldElementfrom a BigInteger- Parameters:
i- integer- Returns:
- valid element
-
of
Construct a field element from a byte-array of 32 bytes- Parameters:
bytes- array containing a valid field element- Returns:
- field element
-
isInRange
Check if an integer is in the inclusive range0toP - 1, wherePis the prime of the SECG P256K1 prime finite field.- Parameters:
e- A possible field element to validate- Returns:
- true if valid
-
checkInRange
ThrowIllegalArgumentExceptionif an integer is not in the inclusive range0toP - 1, wherePis the prime of the SECP256K1 prime finite field.- Parameters:
e- unvalidated integer- Returns:
- a validated integer
-
checkInRange
static byte[] checkInRange(byte[] e) ThrowIllegalArgumentExceptionif the byte array is not the length.NOTE: We are not currently validating for value less than
P- Parameters:
e- unvalidated integer- Returns:
- a validated integer
-
integerTo32Bytes
Convert a BigInteger to a fixed-length byte array- Parameters:
i- an unsigned BigInteger containing a valid Secp256k1 field value- Returns:
- a 32-byte, big-endian unsigned integer value
-