generated from martinthomson/internet-draft-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into seanturner-name-change
- Loading branch information
Showing
4 changed files
with
106 additions
and
10 deletions.
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
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,10 @@ | ||
module github.com/lamps-wg/kyber-certificates/example | ||
|
||
go 1.20 | ||
|
||
require github.com/cloudflare/circl v1.3.2 | ||
|
||
require ( | ||
golang.org/x/crypto v0.7.0 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
) |
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,10 @@ | ||
github.com/cloudflare/circl v1.3.2 h1:VWp8dY3yH69fdM7lM6A1+NhhVoDu9vqK0jOgmkQHFWk= | ||
github.com/cloudflare/circl v1.3.2/go.mod h1:+CauBF6R70Jqcyl8N2hC8pAXYbWkGIezuSbuGLtRhnw= | ||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= | ||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= | ||
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= | ||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
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,75 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/x509/pkix" | ||
"encoding/asn1" | ||
"encoding/pem" | ||
"log" | ||
"os" | ||
|
||
"github.com/cloudflare/circl/kem/schemes" | ||
) | ||
|
||
type subjectPublicKeyInfo struct { | ||
Algorithm pkix.AlgorithmIdentifier | ||
PublicKey asn1.BitString | ||
} | ||
|
||
type oneAsymmetricKey struct { | ||
Version int | ||
Algorithm pkix.AlgorithmIdentifier | ||
PrivateKey []byte | ||
Attributes []asn1.RawValue `asn1:"tag:0,optional"` | ||
PublicKey *subjectPublicKeyInfo `asn1:"tag:1,optional"` | ||
} | ||
|
||
func main() { | ||
scheme := schemes.ByName("Kyber768") | ||
seed := make([]byte, scheme.SeedSize()) | ||
pk, sk := scheme.DeriveKeyPair(seed) | ||
|
||
ppk, _ := pk.MarshalBinary() | ||
psk, _ := sk.MarshalBinary() | ||
|
||
apk := subjectPublicKeyInfo{ | ||
Algorithm: pkix.AlgorithmIdentifier{ | ||
Algorithm: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 44363, 45, 1234, 1}, // TODO | ||
}, | ||
PublicKey: asn1.BitString{ | ||
BitLength: len(ppk) * 8, | ||
Bytes: ppk, | ||
}, | ||
} | ||
|
||
ask := oneAsymmetricKey{ | ||
Version: 0, | ||
Algorithm: pkix.AlgorithmIdentifier{ | ||
Algorithm: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 44363, 45, 1234, 1}, // TODO | ||
}, | ||
PrivateKey: psk, | ||
} | ||
|
||
papk, err := asn1.Marshal(apk) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
pask, err := asn1.Marshal(ask) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err = pem.Encode(os.Stdout, &pem.Block{ | ||
Type: "KYBER768 PRIVATE KEY", | ||
Bytes: pask, | ||
}); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err = pem.Encode(os.Stdout, &pem.Block{ | ||
Type: "KYBER768 PUBLIC KEY", | ||
Bytes: papk, | ||
}); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |