Skip to content

Commit

Permalink
fixing convert methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Janis Erdmanis committed Oct 31, 2024
1 parent c7a3f91 commit 67eaa55
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CryptoGroups"
uuid = "bc997328-bedd-407e-bcd3-5758e064a52d"
authors = ["Janis Erdmanis <janiserdmanis@protonmail.ch>"]
version = "0.5.3"
version = "0.5.4"

[deps]
CryptoPRG = "d846c407-34c1-46cb-aa27-d51818cc05e2"
Expand Down
15 changes: 11 additions & 4 deletions src/Curves/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function decompress_weierstrass(x::BigInt, ỹ::Bool, (a, b)::Tuple{F, F}) where
end


function (::Type{P})(po::Vector{UInt8}) where P <: AbstractPoint
#function (::Type{P})(po::Vector{UInt8}) where P <: AbstractPoint

function Base.convert(::Type{P}, po::Vector{UInt8}) where P <: AbstractPoint

pc = po[1]

Expand Down Expand Up @@ -129,6 +131,10 @@ end
# This shall be considered internal as x, y can't be arbitrary!!!
function _octet(x::BigInt, y::BigInt, N::Int; mode::Symbol = :uncompressed) # N is bitlength(modulus(field()))

if iszero(x) && iszero(y)
return UInt8[0]
end

_x = int2octet(x, N)
_y = int2octet(y, N)

Expand Down Expand Up @@ -162,6 +168,10 @@ _octet(x::F, y::F; mode::Symbol = :uncompressed) where F <: PrimeField = _octet(

function _octet(x::F, y::F; mode::Symbol = :uncompressed) where F <: BinaryField

if iszero(x) && iszero(y)
return UInt8[0]
end

_x = octet(x)
_y = octet(y)

Expand All @@ -171,9 +181,6 @@ function _octet(x::F, y::F; mode::Symbol = :uncompressed) where F <: BinaryField

elseif mode in [:compressed, :hybrid]

#x_ = F(reverse(x))
#y_ = F(reverse(y))

if isstrict()
@warn "Calculation of ỹ could be wrong due to insufficient tests."
end
Expand Down
2 changes: 2 additions & 0 deletions src/Curves/ecpoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct ECPoint{P<:AbstractPoint, S} <: AbstractPoint # The same contract is sati
ECPoint{P, S}(x::F, y::F) where {P <: AbstractPoint, S, F <: Field} = ECPoint{P, S}(P(x, y))
end

ECPoint{P, S}(x; allow_zero=false, skip_validation=false) where {P <: AbstractPoint, S} = ECPoint{P, S}(convert(P, x); allow_zero, skip_validation)

"""
concretize_type(::Type{ECPoint{P}}, order::Integer, cofactor::Integer; name=nothing) where P <: AbstractPoint
Expand Down
2 changes: 1 addition & 1 deletion src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct ECGroup{P<:ECPoint} <: Group
end

ECGroup{P}(x, y) where {P <: ECPoint} = ECGroup{P}(P(x, y))
ECGroup{P}(x::Vector{UInt8}) where {P <: ECPoint} = ECGroup{P}(P(x))
ECGroup{P}(x::Union{Vector{UInt8}, NTuple{2, <:Union{Integer, BitVector}}}; allow_one=false, skip_validation=false) where {P <: ECPoint} = ECGroup{P}(P(x; allow_zero=allow_one, skip_validation))


"""
Expand Down

2 comments on commit 67eaa55

@JanisErdmanis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118467

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.4 -m "<description of version>" 67eaa55c8512edbf9d89280475dd826e4e7afd70
git push origin v0.5.4

Please sign in to comment.