-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filippo version of Ed25519 #462
base: master
Are you sure you want to change the base?
Conversation
A deal with a bogus signature would still get stored (before producing an error). That would prevent a properly signed deal coming later from being stored. This fixes the bug. The test was also written in a flawed way. It measured two failure situations ("wrong index" and "wrong deal") after a success situation. But written that far down, those measurements could well end up measuring failures due to a duplicate deal instead. This changeset also patches the test flaw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great work. There seem to be a few rough edges that still need taking care of, but I'm in no way a security expert... I'll gladly let my colleagues chime in if they spot other issues :)
} | ||
|
||
// NewKeyAndSeedWithInput returns a formatted Ed25519 key (avoid subgroup attack by | ||
// requiring it to be a multiple of 8). It also returns the input and the digest used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requiring it to be a multiple of 8
where is this check being done ?
If I understand correctly, lines 53-54 do not seem to guarantee a multiple of 8, counter example: 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am correct then zero would also be a valid output for what we are trying to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@si-co do you agree ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems to have different problems:
- It is not documented.
- I don't understand why it uses
sha512
when only 32 bytes are needed;. - I seems to try to implement clamping, but it is wrong.
- It uses
digest[:32]
to initialize the scalar, but returnsdigest[32:]
, which is not the digest used to generate the key.
IMHO the best way to implement this function would be to use SetBytesWithClamping
with sha256
to hash the buffer
, assuming that's what the function is trying to do. If @parinayc20 adds the appropriate documentation we can continue the discussion.
group/filippo_ed25519/point.go
Outdated
if data == nil { | ||
p.Mul(filippoCofactorScalar, p) | ||
if p.Equal(&filippoNullPoint) { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume there's an expectation here that we're just "unlucky", could you document that?
Also, should the for
loop provide guarantees that we're going to eventually come out of this loop ? (e.g. throw some kind of error if we've looped over N times)
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides minor issues, this code seems to be lacking tests.
@si-co do you think we can reuse the existing curve25519 test suite ? Is it sufficient ?
// If we're using the full group, | ||
// we just need any point on the curve, so we're done. | ||
// if c.full { | ||
// return P,data[dl:] | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented out code
} | ||
|
||
// NewKeyAndSeedWithInput returns a formatted Ed25519 key (avoid subgroup attack by | ||
// requiring it to be a multiple of 8). It also returns the input and the digest used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@si-co do you agree ?
} | ||
|
||
func (s *Scalar) String() string { | ||
b, _ := s.MarshalBinary() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we're not processing the error return ...
if s.scalar == nil { | ||
s.scalar = new(filippo_ed25519.Scalar) | ||
} | ||
_, err := s.scalar.SetCanonicalBytes(b[:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is SetCanonicalBytes
being used for here and elsewhere ? The (canonicalized) return value is ignored... 🤔
if s.scalar == nil { | ||
s.scalar = new(filippo_ed25519.Scalar) | ||
} | ||
_ = s.scalar.Set(a.(*Scalar).scalar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a legitimate use of _
, as s.scalar.Set
just returns s.scalar
. A comment would clarify it though.
To manually browse the doc start from sidebar.md. Otherwise visit https://dedis.github.io/kyber/
This PR deals with the addition of the Filippo version of ed25519. It includes wrappers for certain functions and Filippo based definition of others. The table below provides a summary of the functions of Kyber Point and Scalar, which were present in Filippo and which had to be defined.
Point.Equal()
Yes
Scalar.Equal()
Yes
Point.Null()
Yes
Scalar.Zero()
Yes
Point.Base()
Yes
Scalar.One()
No
Point.Pick()
No
Scalar.Pick()
No
Point.Set()
Yes
Scalar.Set()
Yes
Point.Clone()
No
Scalar.Clone()
No
Point.Add()
Yes
Scalar.Add()
Yes
Point.Sub()
Yes
Scalar.Sub()
Yes
Point.Neg()
Yes
Scalar.Neg()
Yes
Point.Mul()
Yes
Scalar.Mul()
Yes
Point.EmbedLen()
No
Scalar.Inv()
Yes
Point.Embed()
No
Scalar.Div()
No
Point.Data()
No
Scalar.SetInt64()
No
Point.MarshalBinary()
Yes
Scalar.MarshalBinary()
Yes
Point.UnmarshalBinary()
Yes
Scalar.UnmarshalBinary()
Yes
Point.String()
No
Scalar.String()
No
Point.MarshalSize()
No
Scalar.MarshalSize()
No
Point.MarshalTo()
No
Scalar.MarshalTo()
No
Point.UnmarshalFrom()
No
Scalar.UnmarshalFrom()
No
Scalar.SetBytes()
Yes
Scalar Addition
97.9
161
Scalar Substraction
90.0
167
Scalar Negation
87.0
172
Scalar Multiplication
173
181
Scalar Division
63035
50218
Scalar Inversion
57790
46310
Scalar Picking
7403
8269
Scalar Encoding
400
46.2
Scalar Decoding
7.19
17.0
Point Addition
865
395
Point Substraction
911
402
Point Negation
63.0
42.5
Point Multiplication
282672
72528
Point Base Multiplication
103998
25268
Point Picking
316953
89023
Point Encoding
12598
5171
Point Decoding
13357
5877
I would like to get it reviewed by the engineers before adding it to the main branch.
Thanks,
Parinay