Package net.i2p.crypto.eddsa.math.bigint
Class BigIntegerLittleEndianEncoding
- java.lang.Object
-
- net.i2p.crypto.eddsa.math.Encoding
-
- net.i2p.crypto.eddsa.math.bigint.BigIntegerLittleEndianEncoding
-
- All Implemented Interfaces:
Serializable
public class BigIntegerLittleEndianEncoding extends Encoding implements Serializable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BigIntegerLittleEndianEncoding()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FieldElement
decode(byte[] in)
Decode a FieldElement from its (b-1)-bit encoding.byte[]
encode(BigInteger x)
Convert x to little endian.byte[]
encode(FieldElement x)
Encode a FieldElement in its (b-1)-bit encoding.boolean
isNegative(FieldElement x)
From the Ed25519 paper:
x is negative if the (b-1)-bit encoding of x is lexicographically larger than the (b-1)-bit encoding of -x.void
setField(Field f)
BigInteger
toBigInteger(byte[] in)
Convert in to big endian
-
-
-
Method Detail
-
encode
public byte[] encode(FieldElement x)
Description copied from class:Encoding
Encode a FieldElement in its (b-1)-bit encoding.
-
encode
public byte[] encode(BigInteger x)
Convert x to little endian. Constant time.- Returns:
- array of length b/8
- Throws:
IllegalStateException
- if field not set
-
decode
public FieldElement decode(byte[] in)
Decode a FieldElement from its (b-1)-bit encoding. The highest bit is masked out.- Specified by:
decode
in classEncoding
- Parameters:
in
- the (b-1)-bit encoding of a FieldElement.- Returns:
- the FieldElement represented by 'val'.
- Throws:
IllegalStateException
- if field not setIllegalArgumentException
- if encoding is invalid
-
toBigInteger
public BigInteger toBigInteger(byte[] in)
Convert in to big endian
-
isNegative
public boolean isNegative(FieldElement x)
From the Ed25519 paper:
x is negative if the (b-1)-bit encoding of x is lexicographically larger than the (b-1)-bit encoding of -x. If q is an odd prime and the encoding is the little-endian representation of {0, 1,..., q-1} then the negative elements of F_q are {1, 3, 5,..., q-2}.- Specified by:
isNegative
in classEncoding
- Returns:
- true if negative
-
-