diff --git a/ecc/bls12-377/fp/hash_to_field/doc.go b/ecc/bls12-377/fp/hash_to_field/doc.go new file mode 100644 index 000000000..9bb000c8c --- /dev/null +++ b/ecc/bls12-377/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls12-377/fp" +) diff --git a/ecc/bls12-377/fp/hash_to_field/hash_to_field.go b/ecc/bls12-377/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..97557a7d4 --- /dev/null +++ b/ecc/bls12-377/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls12-377/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bls12-377/fp/hash_to_field/hash_to_field_test.go b/ecc/bls12-377/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..53f250d11 --- /dev/null +++ b/ecc/bls12-377/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls12-377/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls12-377/fr/hash_to_field/doc.go b/ecc/bls12-377/fr/hash_to_field/doc.go new file mode 100644 index 000000000..18904fe7a --- /dev/null +++ b/ecc/bls12-377/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls12-377/fr" +) diff --git a/ecc/bls12-377/fr/hash_to_field/hash_to_field.go b/ecc/bls12-377/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..d9511f8b9 --- /dev/null +++ b/ecc/bls12-377/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls12-377/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bls12-377/fr/hash_to_field/hash_to_field_test.go b/ecc/bls12-377/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..34d59c231 --- /dev/null +++ b/ecc/bls12-377/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls12-377/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls12-378/fp/hash_to_field/doc.go b/ecc/bls12-378/fp/hash_to_field/doc.go new file mode 100644 index 000000000..f29458a50 --- /dev/null +++ b/ecc/bls12-378/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls12-378/fp" +) diff --git a/ecc/bls12-378/fp/hash_to_field/hash_to_field.go b/ecc/bls12-378/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..7a1e30c0a --- /dev/null +++ b/ecc/bls12-378/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls12-378/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bls12-378/fp/hash_to_field/hash_to_field_test.go b/ecc/bls12-378/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..6384d7ae8 --- /dev/null +++ b/ecc/bls12-378/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls12-378/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls12-378/fr/hash_to_field/doc.go b/ecc/bls12-378/fr/hash_to_field/doc.go new file mode 100644 index 000000000..132d9980f --- /dev/null +++ b/ecc/bls12-378/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls12-378/fr" +) diff --git a/ecc/bls12-378/fr/hash_to_field/hash_to_field.go b/ecc/bls12-378/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..879356702 --- /dev/null +++ b/ecc/bls12-378/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls12-378/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bls12-378/fr/hash_to_field/hash_to_field_test.go b/ecc/bls12-378/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..dfb242544 --- /dev/null +++ b/ecc/bls12-378/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls12-378/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls12-381/fp/hash_to_field/doc.go b/ecc/bls12-381/fp/hash_to_field/doc.go new file mode 100644 index 000000000..62985095c --- /dev/null +++ b/ecc/bls12-381/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls12-381/fp" +) diff --git a/ecc/bls12-381/fp/hash_to_field/hash_to_field.go b/ecc/bls12-381/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..e93aad9b8 --- /dev/null +++ b/ecc/bls12-381/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls12-381/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bls12-381/fp/hash_to_field/hash_to_field_test.go b/ecc/bls12-381/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..0caad4c59 --- /dev/null +++ b/ecc/bls12-381/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls12-381/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls12-381/fr/hash_to_field/doc.go b/ecc/bls12-381/fr/hash_to_field/doc.go new file mode 100644 index 000000000..1f8351d2a --- /dev/null +++ b/ecc/bls12-381/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls12-381/fr" +) diff --git a/ecc/bls12-381/fr/hash_to_field/hash_to_field.go b/ecc/bls12-381/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..6febcadd1 --- /dev/null +++ b/ecc/bls12-381/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls12-381/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bls12-381/fr/hash_to_field/hash_to_field_test.go b/ecc/bls12-381/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..3558a524f --- /dev/null +++ b/ecc/bls12-381/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls12-381/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls24-315/fp/hash_to_field/doc.go b/ecc/bls24-315/fp/hash_to_field/doc.go new file mode 100644 index 000000000..ed0207f2e --- /dev/null +++ b/ecc/bls24-315/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls24-315/fp" +) diff --git a/ecc/bls24-315/fp/hash_to_field/hash_to_field.go b/ecc/bls24-315/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..85f1df744 --- /dev/null +++ b/ecc/bls24-315/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls24-315/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bls24-315/fp/hash_to_field/hash_to_field_test.go b/ecc/bls24-315/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..09e50dd6c --- /dev/null +++ b/ecc/bls24-315/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls24-315/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls24-315/fr/hash_to_field/doc.go b/ecc/bls24-315/fr/hash_to_field/doc.go new file mode 100644 index 000000000..6423272af --- /dev/null +++ b/ecc/bls24-315/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls24-315/fr" +) diff --git a/ecc/bls24-315/fr/hash_to_field/hash_to_field.go b/ecc/bls24-315/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..60883ba31 --- /dev/null +++ b/ecc/bls24-315/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls24-315/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bls24-315/fr/hash_to_field/hash_to_field_test.go b/ecc/bls24-315/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..4df406f34 --- /dev/null +++ b/ecc/bls24-315/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls24-315/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls24-317/fp/hash_to_field/doc.go b/ecc/bls24-317/fp/hash_to_field/doc.go new file mode 100644 index 000000000..68ee4656c --- /dev/null +++ b/ecc/bls24-317/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls24-317/fp" +) diff --git a/ecc/bls24-317/fp/hash_to_field/hash_to_field.go b/ecc/bls24-317/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..32d5d8de9 --- /dev/null +++ b/ecc/bls24-317/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls24-317/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bls24-317/fp/hash_to_field/hash_to_field_test.go b/ecc/bls24-317/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..45873b268 --- /dev/null +++ b/ecc/bls24-317/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls24-317/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bls24-317/fr/hash_to_field/doc.go b/ecc/bls24-317/fr/hash_to_field/doc.go new file mode 100644 index 000000000..b1c77a2e4 --- /dev/null +++ b/ecc/bls24-317/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bls24-317/fr" +) diff --git a/ecc/bls24-317/fr/hash_to_field/hash_to_field.go b/ecc/bls24-317/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..fa1f7700e --- /dev/null +++ b/ecc/bls24-317/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bls24-317/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bls24-317/fr/hash_to_field/hash_to_field_test.go b/ecc/bls24-317/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..5445fcef9 --- /dev/null +++ b/ecc/bls24-317/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bls24-317/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bn254/fp/hash_to_field/doc.go b/ecc/bn254/fp/hash_to_field/doc.go new file mode 100644 index 000000000..3f658d71d --- /dev/null +++ b/ecc/bn254/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bn254/fp" +) diff --git a/ecc/bn254/fp/hash_to_field/hash_to_field.go b/ecc/bn254/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..582315f2d --- /dev/null +++ b/ecc/bn254/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bn254/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bn254/fp/hash_to_field/hash_to_field_test.go b/ecc/bn254/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..c22acb3d1 --- /dev/null +++ b/ecc/bn254/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bn254/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bn254/fr/hash_to_field/doc.go b/ecc/bn254/fr/hash_to_field/doc.go new file mode 100644 index 000000000..34ead0afd --- /dev/null +++ b/ecc/bn254/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bn254/fr" +) diff --git a/ecc/bn254/fr/hash_to_field/hash_to_field.go b/ecc/bn254/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..191f03c77 --- /dev/null +++ b/ecc/bn254/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bn254/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bn254/fr/hash_to_field/hash_to_field_test.go b/ecc/bn254/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..690eca914 --- /dev/null +++ b/ecc/bn254/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bn254/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bw6-633/fp/hash_to_field/doc.go b/ecc/bw6-633/fp/hash_to_field/doc.go new file mode 100644 index 000000000..91716313b --- /dev/null +++ b/ecc/bw6-633/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bw6-633/fp" +) diff --git a/ecc/bw6-633/fp/hash_to_field/hash_to_field.go b/ecc/bw6-633/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..c04f3fdba --- /dev/null +++ b/ecc/bw6-633/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bw6-633/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bw6-633/fp/hash_to_field/hash_to_field_test.go b/ecc/bw6-633/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..f7e4e191d --- /dev/null +++ b/ecc/bw6-633/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bw6-633/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bw6-633/fr/hash_to_field/doc.go b/ecc/bw6-633/fr/hash_to_field/doc.go new file mode 100644 index 000000000..15a766391 --- /dev/null +++ b/ecc/bw6-633/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bw6-633/fr" +) diff --git a/ecc/bw6-633/fr/hash_to_field/hash_to_field.go b/ecc/bw6-633/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..fcc3357c3 --- /dev/null +++ b/ecc/bw6-633/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bw6-633/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bw6-633/fr/hash_to_field/hash_to_field_test.go b/ecc/bw6-633/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..a7c8a0307 --- /dev/null +++ b/ecc/bw6-633/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bw6-633/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bw6-756/fp/hash_to_field/doc.go b/ecc/bw6-756/fp/hash_to_field/doc.go new file mode 100644 index 000000000..47a4f762a --- /dev/null +++ b/ecc/bw6-756/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bw6-756/fp" +) diff --git a/ecc/bw6-756/fp/hash_to_field/hash_to_field.go b/ecc/bw6-756/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..4b6d1b797 --- /dev/null +++ b/ecc/bw6-756/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bw6-756/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bw6-756/fp/hash_to_field/hash_to_field_test.go b/ecc/bw6-756/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..160020aae --- /dev/null +++ b/ecc/bw6-756/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bw6-756/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bw6-756/fr/hash_to_field/doc.go b/ecc/bw6-756/fr/hash_to_field/doc.go new file mode 100644 index 000000000..6f886cc85 --- /dev/null +++ b/ecc/bw6-756/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bw6-756/fr" +) diff --git a/ecc/bw6-756/fr/hash_to_field/hash_to_field.go b/ecc/bw6-756/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..b2ac7d066 --- /dev/null +++ b/ecc/bw6-756/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bw6-756/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bw6-756/fr/hash_to_field/hash_to_field_test.go b/ecc/bw6-756/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..bcb28dac2 --- /dev/null +++ b/ecc/bw6-756/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bw6-756/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bw6-761/fp/hash_to_field/doc.go b/ecc/bw6-761/fp/hash_to_field/doc.go new file mode 100644 index 000000000..fbd3b76a9 --- /dev/null +++ b/ecc/bw6-761/fp/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bw6-761/fp" +) diff --git a/ecc/bw6-761/fp/hash_to_field/hash_to_field.go b/ecc/bw6-761/fp/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..dd12c1e9d --- /dev/null +++ b/ecc/bw6-761/fp/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bw6-761/fp" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fp.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fp.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fp.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fp.Bytes +} diff --git a/ecc/bw6-761/fp/hash_to_field/hash_to_field_test.go b/ecc/bw6-761/fp/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..edd7e59e3 --- /dev/null +++ b/ecc/bw6-761/fp/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bw6-761/fp" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fp.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fp.Element + res2.SetBytes(bts[:fp.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/ecc/bw6-761/fr/hash_to_field/doc.go b/ecc/bw6-761/fr/hash_to_field/doc.go new file mode 100644 index 000000000..8bb5b62b9 --- /dev/null +++ b/ecc/bw6-761/fr/hash_to_field/doc.go @@ -0,0 +1,32 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "github.com/consensys/gnark-crypto/ecc/bw6-761/fr" +) diff --git a/ecc/bw6-761/fr/hash_to_field/hash_to_field.go b/ecc/bw6-761/fr/hash_to_field/hash_to_field.go new file mode 100644 index 000000000..01650f8bb --- /dev/null +++ b/ecc/bw6-761/fr/hash_to_field/hash_to_field.go @@ -0,0 +1,66 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "fmt" + "hash" + + "github.com/consensys/gnark-crypto/ecc/bw6-761/fr" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} + +// New returns a new hasher instance which uses [fr.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := fr.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return fr.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return fr.Bytes +} diff --git a/ecc/bw6-761/fr/hash_to_field/hash_to_field_test.go b/ecc/bw6-761/fr/hash_to_field/hash_to_field_test.go new file mode 100644 index 000000000..05dedfa27 --- /dev/null +++ b/ecc/bw6-761/fr/hash_to_field/hash_to_field_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 Consensys Software Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by consensys/gnark-crypto DO NOT EDIT + +package hash_to_field + +import ( + "testing" + + "github.com/consensys/gnark-crypto/ecc/bw6-761/fr" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := fr.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 fr.Element + res2.SetBytes(bts[:fr.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} diff --git a/internal/generator/hash_to_field/generate.go b/internal/generator/hash_to_field/generate.go new file mode 100644 index 000000000..d9c7dbbff --- /dev/null +++ b/internal/generator/hash_to_field/generate.go @@ -0,0 +1,18 @@ +package hash_to_field + +import ( + "path/filepath" + + "github.com/consensys/bavard" + "github.com/consensys/gnark-crypto/internal/generator/config" +) + +func Generate(conf config.FieldDependency, baseDir string, bgen *bavard.BatchGenerator) error { + entries := []bavard.Entry{ + {File: filepath.Join(baseDir, "doc.go"), Templates: []string{"doc.go.tmpl"}}, + {File: filepath.Join(baseDir, "hash_to_field.go"), Templates: []string{"hash_to_field.go.tmpl"}}, + {File: filepath.Join(baseDir, "hash_to_field_test.go"), Templates: []string{"hash_to_field_test.go.tmpl"}}, + } + + return bgen.Generate(conf, "hash_to_field", "./hash_to_field/template", entries...) +} diff --git a/internal/generator/hash_to_field/template/doc.go.tmpl b/internal/generator/hash_to_field/template/doc.go.tmpl new file mode 100644 index 000000000..088b533f0 --- /dev/null +++ b/internal/generator/hash_to_field/template/doc.go.tmpl @@ -0,0 +1,16 @@ +// Package htf provides hasher based on RFC 9380 Section 5. +// +// The [RFC 9380] defines a method for hashing bytes to elliptic curves. Section +// 5 of the RFC describes a method for uniformly hashing bytes into a field +// using a domain separation. The hashing is implemented in [fp], but this +// package provides a wrapper for the method which implements [hash.Hash] for +// using the method recursively. +// +// [RFC 9380]: https://datatracker.ietf.org/doc/html/rfc9380 +package hash_to_field + +import ( + _ "hash" + + _ "{{ .FieldPackagePath }}" +) \ No newline at end of file diff --git a/internal/generator/hash_to_field/template/hash_to_field.go.tmpl b/internal/generator/hash_to_field/template/hash_to_field.go.tmpl new file mode 100644 index 000000000..60452341b --- /dev/null +++ b/internal/generator/hash_to_field/template/hash_to_field.go.tmpl @@ -0,0 +1,47 @@ +import ( + "fmt" + "hash" + + "{{ .FieldPackagePath }}" +) + +type wrappedHashToField struct { + domain []byte + toHash []byte +} +// New returns a new hasher instance which uses [{{ .FieldPackageName}}.Hash] to hash all the +// written bytes to a field element, returning the byte representation of the +// field element. The domain separator is passed as-is to hashing method. +func New(domainSeparator []byte) hash.Hash { + return &wrappedHashToField{ + domain: append([]byte{}, domainSeparator...), // copy in case the argument is modified + } +} + +func (w *wrappedHashToField) Write(p []byte) (n int, err error) { + w.toHash = append(w.toHash, p...) + return len(p), nil +} + +func (w *wrappedHashToField) Sum(b []byte) []byte { + res, err := {{ .FieldPackageName }}.Hash(w.toHash, w.domain, 1) + if err != nil { + // we want to follow the interface, cannot return error and have to panic + // but by default the method shouldn't return an error internally + panic(fmt.Sprintf("native field to hash: %v", err)) + } + bts := res[0].Bytes() + return append(b, bts[:]...) +} + +func (w *wrappedHashToField) Reset() { + w.toHash = nil +} + +func (w *wrappedHashToField) Size() int { + return {{ .FieldPackageName}}.Bytes +} + +func (w *wrappedHashToField) BlockSize() int { + return {{ .FieldPackageName}}.Bytes +} \ No newline at end of file diff --git a/internal/generator/hash_to_field/template/hash_to_field_test.go.tmpl b/internal/generator/hash_to_field/template/hash_to_field_test.go.tmpl new file mode 100644 index 000000000..ab9037e17 --- /dev/null +++ b/internal/generator/hash_to_field/template/hash_to_field_test.go.tmpl @@ -0,0 +1,23 @@ +import ( + "testing" + + "{{ .FieldPackagePath }}" +) + +func TestHashInterface(t *testing.T) { + msg := []byte("test") + sep := []byte("separator") + res, err := {{ .FieldPackageName}}.Hash(msg, sep, 1) + if err != nil { + t.Fatal("hash to field", err) + } + + htfFn := New(sep) + htfFn.Write(msg) + bts := htfFn.Sum(nil) + var res2 {{ .ElementType }} + res2.SetBytes(bts[:{{ .FieldPackageName }}.Bytes]) + if !res[0].Equal(&res2) { + t.Error("not equal") + } +} \ No newline at end of file diff --git a/internal/generator/main.go b/internal/generator/main.go index 057062e32..2ed415fa0 100644 --- a/internal/generator/main.go +++ b/internal/generator/main.go @@ -19,6 +19,7 @@ import ( "github.com/consensys/gnark-crypto/internal/generator/fft" fri "github.com/consensys/gnark-crypto/internal/generator/fri/template" "github.com/consensys/gnark-crypto/internal/generator/gkr" + "github.com/consensys/gnark-crypto/internal/generator/hash_to_field" "github.com/consensys/gnark-crypto/internal/generator/iop" "github.com/consensys/gnark-crypto/internal/generator/kzg" "github.com/consensys/gnark-crypto/internal/generator/pairing" @@ -157,6 +158,16 @@ func main() { // generate iop functions assertNoError(iop.Generate(conf, filepath.Join(curveDir, "fr", "iop"), bgen)) + fpInfo := config.FieldDependency{ + FieldPackagePath: "github.com/consensys/gnark-crypto/ecc/" + conf.Name + "/fp", + FieldPackageName: "fp", + ElementType: "fp.Element", + } + + // generate wrapped hash-to-field for both fr and fp + assertNoError(hash_to_field.Generate(frInfo, filepath.Join(curveDir, "fr", "hash_to_field"), bgen)) + assertNoError(hash_to_field.Generate(fpInfo, filepath.Join(curveDir, "fp", "hash_to_field"), bgen)) + }(conf) }