Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ML-DSA (FIPS204) #480

Merged
merged 11 commits into from
Oct 9, 2024
Prev Previous commit
Next Next commit
Avoid to export unsafeSignInternal.
  • Loading branch information
armfazh committed Oct 9, 2024
commit d55a0aacd1ce94c093c3f16adb27db709e45d586
35 changes: 35 additions & 0 deletions sign/dilithium/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var (

func main() {
generateModePackageFiles()
generateACVPTest()
generateParamsFiles()
generateSourceFiles()
}
Expand Down Expand Up @@ -212,6 +213,40 @@ func generateModePackageFiles() {
}
}

// Generates modeX/dilithium.go from templates/pkg.templ.go
func generateACVPTest() {
tl, err := template.ParseFiles("templates/acvp.templ.go")
if err != nil {
panic(err)
}

for _, mode := range Modes {
if !strings.HasPrefix(mode.Name, "ML-DSA") {
continue
}

buf := new(bytes.Buffer)
err := tl.Execute(buf, mode)
if err != nil {
panic(err)
}

res, err := format.Source(buf.Bytes())
if err != nil {
panic("error formating code")
}

offset := strings.Index(string(res), TemplateWarning)
if offset == -1 {
panic("Missing template warning in pkg.templ.go")
}
err = os.WriteFile(mode.PkgPath()+"/acvp_test.go", res[offset:], 0o644)
if err != nil {
panic(err)
}
}
}

// Copies mode3 source files to other modes
func generateSourceFiles() {
files := make(map[string][]byte)
Expand Down
266 changes: 266 additions & 0 deletions sign/dilithium/templates/acvp.templ.go

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

6 changes: 3 additions & 3 deletions sign/dilithium/templates/pkg.templ.go

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

Loading