Skip to content

Commit

Permalink
perf: use inverse as a bijection for bw6-761 mimc
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhousni committed Dec 2, 2023
1 parent e773088 commit f229677
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ecc/bw6-761/fr/mimc/mimc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions internal/generator/crypto/hash/mimc/template/mimc.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ func (d *digest) encrypt(m fr.Element) fr.Element {
m.Add(&m, &d.h)
return m
}
{{ else if eq .Name "bw6-761" }}
// plain execution of a mimc run
// m: message
// k: encryption key
func (d *digest) encrypt(m fr.Element) fr.Element {
once.Do(initConstants) // init constants

for i := 0; i < mimcNbRounds; i++ {
// m = 1/(m+k+c)
m.Add(&m, &d.h).Add(&m, &mimcConstants[i]).Inverse(&m)
}
m.Add(&m, &d.h)
return m
}
{{ else }}
// plain execution of a mimc run
// m: message
Expand Down

0 comments on commit f229677

Please sign in to comment.