Skip to content

Commit

Permalink
ed25519 keygen
Browse files Browse the repository at this point in the history
  • Loading branch information
aburdulescu committed Dec 10, 2023
1 parent 50faa5b commit 953384c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
59 changes: 59 additions & 0 deletions internal/keygen/ed25519.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package keygen

import (
"crypto/ed25519"
"encoding/hex"
"flag"
"fmt"
"io"
"os"
)

func Ed25519(args ...string) error {
fset := flag.NewFlagSet("gen-ed25519", flag.ContinueOnError)
fset.Usage = func() {
fmt.Fprint(os.Stderr, `Usage: pocryp gen-ed25519 [-out OUTPUT] [-bin]
Generate ED25519 key.
If -out is not specified, the output will be printed to stdout.
Options:
`)
fset.PrintDefaults()
}

fOutput := fset.String("out", "", "Write the result to the file at path OUTPUT.")
fBin := fset.Bool("bin", false, "Write output as binary not hex.")

if err := fset.Parse(args); err != nil {
return err
}

var w io.Writer
if *fOutput == "" {
w = os.Stdout
} else {
f, err := os.Create(*fOutput)
if err != nil {
return err
}
defer f.Close()
w = f
}

key, _, err := ed25519.GenerateKey(nil)
if err != nil {
return err
}

if *fBin {
if _, err := w.Write(key); err != nil {
return err
}
} else {
fmt.Fprintln(w, hex.EncodeToString(key))
}

return nil
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func main() {
Usage: "Generate RSA key",
Run: keygen.Rsa,
},
app.Command{
Name: "gen-ed25519",
Usage: "Generate ED25519 key",
Run: keygen.Ed25519,
},
)

a.Add(
Expand Down
1 change: 1 addition & 0 deletions progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [x] AES
- [x] RSA
- [x] ED25519

# Block Cipher

Expand Down

0 comments on commit 953384c

Please sign in to comment.