Fields

CryptoGroups.Fields.BinaryFieldType
abstract type BinaryField <: Field end

An interface for a a binary field. Requires constructor for F(::BitVector) and convert(BitVector, ::BinaryField). Implements octet and coresponding constructor from octet. In addition implements a convinience constructor from integer by reinterpreting it first to bytes.

source
CryptoGroups.Fields.F2GNBType
struct F2GNB{N, T} <: BinaryField
    x::BitVector
end

Binary extension field in Gausian normal basis where N is a field degree and T is it's complexity type (an integer). Note that complexity type T is not an independent parameter but depends on N and may not exist. For generaration of complexity parameter see CryptoGroups.Specs.GNB constructor. Conversion between F2GNB and F2PB is not implemented, but is specified in ANSI X9.62 standard.

Example

# Direct type construction for degree 4
F = F2GNB{4, 1}

# Computing the type using `Specs.GNB`
(; m, T) = Specs.GNB(4)
F = F2GNB{m, T}

# Instantiation
a = F2GNB{4, 3}(bin"1000")
b = F2GNB{4, 3}(bin"1101")
a * b == F2GNB{4, 3}(bin"0010")
a + b == F2GNB{4, 3}(bin"0101")

# Conversions
a == F(octet(a)) == F(value(a))
source
CryptoGroups.Fields.F2PBType
struct F2PB{R} <: BinaryField
    x::BitVector
end

Binary extension field GF(2) with polynomial reducer that is encoded in a type parameter R. For type concretization a macro @F2PB is offered. The constructor from bitvector follows ANS X9.62 standart convention.

Example

# Concretizing binary field with bitvector
F = @F2PB{bin"10011"} # equals to a polynomial f(X) = X^4 + X + 1

# Passing polynomial directly
F = @F2PB{X^4 + X + 1}

# Instantiating a field element
a = F(bin"1101")
b = F(bin"1001")
a * b = F(bin"1111")
a + b = F(bin"0100")

# Conversions
α == F(octet(α)) == F(value(α))
source
CryptoGroups.Fields.FPType
struct FP{P} <: PrimeField
    x::BigInt 
end

Modular prime field where P is a modulus.

Example

# If modulus is a bitstype
x = FP{23}(2)

# For BigInt modulus use a static method from Utils
p = BigInt(23)
y = FP{static(p)}(2)
source
CryptoGroups.Fields.FieldType
abstract type Field end

An abstract field interface. Requires *, ^, +, -, one, zero and order, octet, value. Implements inv. The Field type must supports a constructor for an element e::Field with properties:

e == typeof(e)(octet(e)) == typeof(e)(value(e))
source
CryptoGroups.Fields.PrimeFieldType
abstract type PrimeField <: Field end

An interface for a a modulus prime field. Requires constructor for F(::BigInt) and convert(BigInt, ::PrimeField) as well as modulus. It is recomended to subtype it for implementation of Mersenne primes.

source
Base.:*Method
*(x::F, y::F)::F where F <: Field
*(x::F, y::Integer)::F where F <: Field
*(x::Integer, y::F)::F where F <: Field

Multiplies two field elements. If element is and integer it is first converted to the field element before used to multiply.

source
Base.:+Method
+(x::F, y::F)::F where F <: Field

Adds two field elements.

source
Base.:-Method
-(x::F)::F where F <: Field

Constructs a field element negative

source
Base.:^Method
^(x::F, n::Integer) where F <: Field

Computes an exponential of a field element.

source
Base.remMethod
rem(x::BinaryField, q::T)::T where T <: Integer

Converts field value to an octet and then to integer from which remainder is computed. This is in accord with FIPS 186-4 standart for making ECDSA signatures over binary fields.

source
Base.remMethod
rem(x::PrimeField, q::T)::T where T <: Integer

Computes a remainder of the field integer value.

source
CryptoGroups.valueFunction
value(x::PrimeField)::BigInt

Converts a prime field element to an integer representation

source
CryptoGroups.valueMethod
value(x::BinaryField)::BitVector

Converts a binary field elelement to a bitvector representation

source
CryptoPRG.bitlengthMethod
bitlength(::Union{F, Type{F}})::Int where F <: Field

Bitlength for field type. For BinaryFields returns field degree wheras for PrimeField it is bitlength of modulus.

source