Skip to content
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

Adapt existing ristretto225 implementation to the CIRCL Group interfaces() #216

Merged
merged 6 commits into from
Feb 17, 2021

Conversation

chris-wood
Copy link
Contributor

This change wraps @bwesterb's ristretto225 implementation. I'm opening it up as a draft PR to start, since there are some questions I'd like to work through regarding the Order() function (see #214). Once we agree on the general design, I'll add tests along the lines of group_test.go.

cc @claucece, @wbl

}
}

// Note(caw): this does NOT implement HashToElement as specified in the hash-to-curve draft
Copy link
Member

Choose a reason for hiding this comment

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

I'm happy to make changes to go-ristretto to accommodate the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a new API. Derive is basically FromUniformBytes, but this is a wrapper around that interface.

Copy link
Member

Choose a reason for hiding this comment

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

Could you be a bit more specific what functionality you need?

}

func (e *ristrettoElement) Dbl(x Element) Element {
return e.Add(x, x)
Copy link
Member

Choose a reason for hiding this comment

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

I could expose a more efficient double in go-ristretto, if desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, please. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Done.

@chris-wood chris-wood marked this pull request as ready for review February 17, 2021 15:13
@chris-wood
Copy link
Contributor Author

Promoting for full review after adding test vectors. I'll investigate the build failures in a bit.

@chris-wood
Copy link
Contributor Author

Hmm, the "verifying code" stage is failing in CI, due to a new external library:

# github.com/stretchr/testify/assert
Error: ../../../go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:1704:5: undefined: errors.Is
Error: ../../../go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:1727:6: undefined: errors.Is
Error: ../../../go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:1750:5: undefined: errors.As
Error: ../../../go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:1767:7: undefined: errors.Unwrap
Error: ../../../go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:1771:7: undefined: errors.Unwrap

@armfazh, what does this stage do?

go.mod Show resolved Hide resolved
Copy link
Contributor

@armfazh armfazh left a comment

Choose a reason for hiding this comment

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

also add ristretto to the batch of tests.

func TestGroup(t *testing.T) {
	for _, g := range []group.Group{
		group.P256,
		group.P384,
		group.P521,
		group.Ristretto255,

@chris-wood
Copy link
Contributor Author

@armfazh done -- good catch! I had to fix the identity serialization test. The change makes me wonder if Marshal() should ever return an encoded element whose byte length is less than the expected size. (For example, 32 zeroes instead of 1 zero.) I can see arguments for either or, but here I went with the former.

@armfazh
Copy link
Contributor

armfazh commented Feb 17, 2021

@armfazh done -- good catch! I had to fix the identity serialization test. The change makes me wonder if Marshal() should ever return an encoded element whose byte length is less than the expected size. (For example, 32 zeroes instead of 1 zero.) I can see arguments for either or, but here I went with the former.

I think it is ok to check for all-zeros, but how many of them?

There should be some field in Group that tells you the encoding size. This works well with groups that have fixed-size encodings, but for NIST groups we have variable length encoding, say 1 byte, n+1 bytes, or 2n+1 bytes.
-- btw, a similar discussion in the hpke list.

@chris-wood
Copy link
Contributor Author

I think it is ok to check for all-zeros, but how many of them?

My take: the number of zeroes should match the size of an encoded element. (That means the existing group implementations should change, since the identity encoding is []byte{0x00}.)

Can we address this in a future issue?

@armfazh
Copy link
Contributor

armfazh commented Feb 17, 2021

My take: the number of zeroes should match the size of an encoded element. (That means the existing group implementations should change, since the identity encoding is []byte{0x00}.)

1-byte encoding for identity follows the SEC specification.

Can we address this in a future issue?

sure, this is not a blocker for this pr.

@claucece
Copy link
Contributor

LGTM.

@chris-wood
Copy link
Contributor Author

@armfazh what additional changes would you like to see?

@armfazh armfazh added the new feature New functionality or module label Feb 17, 2021
@armfazh armfazh merged commit 878fc41 into cloudflare:master Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New functionality or module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants