Fields
CryptoGroups.Fields.BinaryField — Typeabstract type BinaryField <: Field endAn 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.
CryptoGroups.Fields.F2GNB — Typestruct F2GNB{N, T} <: BinaryField
x::BitVector
endBinary 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))CryptoGroups.Fields.F2PB — Typestruct F2PB{R} <: BinaryField
x::BitVector
endBinary 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(α))CryptoGroups.Fields.FP — Typestruct FP{P} <: PrimeField
x::BigInt
endModular 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)CryptoGroups.Fields.Field — Typeabstract type Field endAn 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))CryptoGroups.Fields.PrimeField — Typeabstract type PrimeField <: Field endAn 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.
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 <: FieldMultiplies two field elements. If element is and integer it is first converted to the field element before used to multiply.
Base.:+ — Method+(x::F, y::F)::F where F <: FieldAdds two field elements.
Base.:- — Method-(x::F)::F where F <: FieldConstructs a field element negative
Base.:^ — Method^(x::F, n::Integer) where F <: FieldComputes an exponential of a field element.
Base.rem — Methodrem(x::BinaryField, q::T)::T where T <: IntegerConverts 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.
Base.rem — Methodrem(x::PrimeField, q::T)::T where T <: IntegerComputes a remainder of the field integer value.
CryptoGroups.Fields.modulus — Functionmodulus(::Union{F, Type{F}})::BigInt where F <: PrimeFieldGets a prime modulus of a
CryptoGroups.Fields.octet — Methodoctet(x::Field)Returns a byte representation of a field element according to FIPS 186-4 standart.
CryptoGroups.value — Functionvalue(x::PrimeField)::BigIntConverts a prime field element to an integer representation
CryptoGroups.value — Methodvalue(x::BinaryField)::BitVectorConverts a binary field elelement to a bitvector representation
CryptoPRG.bitlength — Methodbitlength(::Union{F, Type{F}})::Int where F <: FieldBitlength for field type. For BinaryFields returns field degree wheras for PrimeField it is bitlength of modulus.