-
Notifications
You must be signed in to change notification settings - Fork 144
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
Implement Classic McEliece #378
Open
pufferffish
wants to merge
14
commits into
cloudflare:main
Choose a base branch
from
pufferffish:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
820e065
implement Classical McEliece
pufferffish 827a97b
trim down test data size
pufferffish 5e4053f
add more documentation
pufferffish ed1fba8
compress testdata.txt
pufferffish 728ed14
add TODO in pk_gen.go and add attribution to the Rust Classic McEliec…
pufferffish 1b8c3d0
Implement vectorization for systematic parameters (#1)
pufferffish ecb22e7
pass pointers instead of slices
pufferffish eb670e7
Implemenet vectorization for semi-systematic parameters (#2)
pufferffish c563649
optimize gf multiplication
pufferffish 0bf6199
update to round 4 specification
pufferffish 66aa9c5
Revert "optimize gf multiplication"
pufferffish d81cf1e
remove wrong comment
pufferffish 9dbf468
field arithmetic cleanup
pufferffish 7dfc396
Update comment to reference round 4 instead of round 3 NIST submission
pufferffish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
//go:build ignore | ||
// +build ignore | ||
|
||
// Autogenerates wrappers from templates to prevent too much duplicated code | ||
// between the code for different modes. | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"go/format" | ||
"io/ioutil" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type Param struct { | ||
Gf string | ||
PublicKeySize uint | ||
PrivateKeySize uint | ||
CiphertextSize uint | ||
SysN uint | ||
SysT uint | ||
} | ||
|
||
type Instance struct { | ||
Name string | ||
Param Param | ||
} | ||
|
||
func (m Instance) Pkg() string { | ||
return strings.ToLower(m.Name) | ||
} | ||
|
||
func (m Instance) IsSemiSystematic() bool { | ||
return strings.HasSuffix(m.Name, "f") | ||
} | ||
|
||
func (m Instance) Is348864() bool { | ||
return strings.Contains(m.Name, "348864") | ||
} | ||
|
||
func (m Instance) Is460896() bool { | ||
return strings.Contains(m.Name, "460896") | ||
} | ||
|
||
func (m Instance) Is6688128() bool { | ||
return strings.Contains(m.Name, "6688128") | ||
} | ||
|
||
func (m Instance) Is6960119() bool { | ||
return strings.Contains(m.Name, "6960119") | ||
} | ||
|
||
func (m Instance) Is8192128() bool { | ||
return strings.Contains(m.Name, "8192128") | ||
} | ||
|
||
var ( | ||
McElieceParam348864 = Param{ | ||
Gf: "gf2e12", | ||
PublicKeySize: 261120, | ||
PrivateKeySize: 6492, | ||
CiphertextSize: 96, | ||
SysN: 3488, | ||
SysT: 64, | ||
} | ||
McElieceParam460896 = Param{ | ||
Gf: "gf2e13", | ||
PublicKeySize: 524160, | ||
PrivateKeySize: 13608, | ||
CiphertextSize: 156, | ||
SysN: 4608, | ||
SysT: 96, | ||
} | ||
McElieceParam6688128 = Param{ | ||
Gf: "gf2e13", | ||
PublicKeySize: 1044992, | ||
PrivateKeySize: 13932, | ||
CiphertextSize: 208, | ||
SysN: 6688, | ||
SysT: 128, | ||
} | ||
McElieceParam6960119 = Param{ | ||
Gf: "gf2e13", | ||
PublicKeySize: 1047319, | ||
PrivateKeySize: 13948, | ||
CiphertextSize: 194, | ||
SysN: 6960, | ||
SysT: 119, | ||
} | ||
McElieceParam8192128 = Param{ | ||
Gf: "gf2e13", | ||
PublicKeySize: 1357824, | ||
PrivateKeySize: 14120, | ||
CiphertextSize: 208, | ||
SysN: 8192, | ||
SysT: 128, | ||
} | ||
Instances = []Instance{ | ||
{Name: "mceliece348864", Param: McElieceParam348864}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose to use names in line with liboqs here: This also matches the capitalization of e.g. |
||
{Name: "mceliece348864f", Param: McElieceParam348864}, | ||
{Name: "mceliece460896", Param: McElieceParam460896}, | ||
{Name: "mceliece460896f", Param: McElieceParam460896}, | ||
{Name: "mceliece6688128", Param: McElieceParam6688128}, | ||
{Name: "mceliece6688128f", Param: McElieceParam6688128}, | ||
{Name: "mceliece6960119", Param: McElieceParam6960119}, | ||
{Name: "mceliece6960119f", Param: McElieceParam6960119}, | ||
{Name: "mceliece8192128", Param: McElieceParam8192128}, | ||
{Name: "mceliece8192128f", Param: McElieceParam8192128}, | ||
} | ||
|
||
TemplateWarning = "// Code generated from" | ||
) | ||
|
||
func main() { | ||
generateTemplateFilesIf("templates/benes_348864.templ.go", "benes", func(m Instance) bool { return m.Is348864() }) | ||
generateTemplateFilesIf("templates/benes_other.templ.go", "benes", func(m Instance) bool { return !m.Is348864() }) | ||
generateTemplateFilesIf("templates/operations_6960119.templ.go", "operations", func(m Instance) bool { return m.Is6960119() }) | ||
generateTemplateFiles("templates/mceliece.templ.go", "mceliece") | ||
generateTemplateFiles("templates/pk_gen_vec.templ.go", "pk_gen") | ||
generateTemplateFiles("templates/vec.templ.go", "vec") | ||
generateTemplateFilesIf("templates/fft_348864.templ.go", "fft", func(m Instance) bool { return m.Is348864() }) | ||
generateTemplateFilesIf("templates/fft_other.templ.go", "fft", func(m Instance) bool { return !m.Is348864() }) | ||
} | ||
|
||
func generateTemplateFiles(templatePath, outputName string) { | ||
generateTemplateFilesIf(templatePath, outputName, func(instance Instance) bool { return true }) | ||
} | ||
|
||
func generateTemplateFilesIf(templatePath, outputName string, predicate func(Instance) bool) { | ||
tl, err := template.ParseFiles(templatePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, mode := range Instances { | ||
if !predicate(mode) { | ||
continue | ||
} | ||
buf := new(bytes.Buffer) | ||
err := tl.Execute(buf, mode) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Formating output code | ||
code, err := format.Source(buf.Bytes()) | ||
if err != nil { | ||
panic("error formating code") | ||
} | ||
|
||
res := string(code) | ||
offset := strings.Index(res, TemplateWarning) | ||
if offset == -1 { | ||
panic("Missing template warning in pkg.templ.go") | ||
} | ||
err = ioutil.WriteFile(mode.Pkg()+"/"+outputName+".go", []byte(res[offset:]), 0o644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we maybe consider also adding
pc
variants of Classic McEliece including a 32-byte plaintext confirmation.This would be desirable as liboqs always adds/expects the plaintext confirmation which makes incompatible with this implementation.
See: https://classic.mceliece.org/mceliece-pc-20221023.pdf