Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from bytemare/lint
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
bytemare authored Apr 4, 2022
2 parents da84629 + 71003e0 commit 3630959
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
4 changes: 4 additions & 0 deletions group/curve25519/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (e *Element) Decode(in []byte) (internal.Point, error) {
return nil, fmt.Errorf("decoding element : %w", err)
}

if e.IsIdentity() {
return nil, internal.ErrIdentity
}

return e, nil
}

Expand Down
4 changes: 4 additions & 0 deletions group/edwards25519/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (e *Element) Decode(in []byte) (internal.Point, error) {
return nil, fmt.Errorf("decoding element : %w", err)
}

if e.IsIdentity() {
return nil, internal.ErrIdentity
}

return e, nil
}

Expand Down
5 changes: 0 additions & 5 deletions group/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ func (i Group) ElementLength() int {
return i.get().ElementLength()
}

// Identity returns the group's identity element.
func (i Group) Identity() *Point {
return newPoint(i.get().Identity())
}

// HashToGroup allows arbitrary input to be safely mapped to the curve of the Group.
func (i Group) HashToGroup(input, dst []byte) *Point {
return newPoint(i.get().HashToGroup(input, dst))
Expand Down
2 changes: 1 addition & 1 deletion group/internal/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Point interface {
// Copy returns a copy of the point.
Copy() Point

// Decode decodes the input an sets the current point to its value, and returns it.
// Decode decodes the input a sets the current point to its value, and returns it.
Decode(in []byte) (Point, error)

// Bytes returns the compressed byte encoding of the point.
Expand Down
13 changes: 13 additions & 0 deletions group/internal/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Group: MIT
//
// Copyright (C) 2021 Daniel Bourdrez. All Rights Reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree or at
// https://spdx.org/licenses/MIT.html

package internal

import "errors"

var ErrIdentity = errors.New("infinity/identity point")
3 changes: 0 additions & 3 deletions group/internal/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ type Group interface {
// ElementLength returns the byte size of an encoded element.
ElementLength() int

// Identity returns the group's identity element.
Identity() Point

// HashToGroup allows arbitrary input to be safely mapped to the curve of the Group.
HashToGroup(input, dst []byte) Point

Expand Down
8 changes: 7 additions & 1 deletion group/other/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
// LICENSE file in the root directory of this source tree or at
// https://spdx.org/licenses/MIT.html

// Package other wraps an hash-to-curve implementation and exposes functions for operations on points and scalars.
// Package other wraps a hash-to-curve implementation and exposes functions for operations on points and scalars.
package other

import (
"math/big"

"github.com/bytemare/crypto/group/internal"
)

func pointLen(bitLen int) int {
Expand Down Expand Up @@ -90,6 +92,10 @@ func (p *Point) recoverPoint(input []byte) (*Point, error) {
return nil, err
}

if p.point.IsIdentity() {
return nil, internal.ErrIdentity
}

return p, nil
}

Expand Down
5 changes: 5 additions & 0 deletions group/ristretto/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func (p *Point) Decode(in []byte) (internal.Point, error) {
return nil, err
}

// superfluous identity check
if el.Equal(ristretto255.NewElement().Zero()) == 1 {
return nil, internal.ErrIdentity
}

p.point = el

return p, nil
Expand Down

0 comments on commit 3630959

Please sign in to comment.