extra25519

package
v1.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package extra25519 implements the key conversion from ed25519 to curve25519. Nothing more.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrivateKeyToCurve25519

func PrivateKeyToCurve25519(curve25519Private *[32]byte, privateKey ed25519.PrivateKey)

PrivateKeyToCurve25519 converts an ed25519 private key into a corresponding curve25519 private key such that the resulting curve25519 public key will equal the result from PublicKeyToCurve25519.

Example
package main

import (
	"bytes"

	"go.cryptoscope.co/secretstream/secrethandshake/internal/extra25519"
	"golang.org/x/crypto/ed25519"

	"encoding/hex"
	"fmt"
	"os"
)

func main() {
	dumper := hex.Dumper(os.Stdout)

	// really silly seed for reproduciability
	seed := make([]byte, 32)

	fmt.Println("seed:")
	dumper.Write(seed)

	_, private, err := ed25519.GenerateKey(bytes.NewReader(seed))
	fatal(err)

	fmt.Println("private ed25519:")
	dumper.Write(private)

	var curvPriv [32]byte
	extra25519.PrivateKeyToCurve25519(&curvPriv, private)

	fmt.Println("private curve25519:")
	dumper.Write(curvPriv[:])

}

func fatal(err error) {
	if err != nil {
		panic(err)
	}
}
Output:

seed:
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
private ed25519:
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  3b 6a 27 bc ce b6 a4 2d  62 a3 a8 d0 2a 6f 0d 73  |;j'....-b...*o.s|
00000050  65 32 15 77 1d e2 43 a6  3a c0 48 a1 8b 59 da 29  |e2.w..C.:.H..Y.)|
private curve25519:
00000060  50 46 ad c1 db a8 38 86  7b 2b bb fd d0 c3 42 3e  |PF....8.{+....B>|
00000070  58 b5 79 70 b5 26 7a 90  f5 79 60 92 4a 87 f1 56  |X.yp.&z..y`.J..V|

func PublicKeyToCurve25519

func PublicKeyToCurve25519(curveBytes *[32]byte, edBytes ed25519.PublicKey) bool

PublicKeyToCurve25519 converts an Ed25519 public key into the curve25519 public key that would be generated from the same private key.

Example
package main

import (
	"bytes"

	"go.cryptoscope.co/secretstream/secrethandshake/internal/extra25519"
	"golang.org/x/crypto/ed25519"

	"encoding/hex"
	"fmt"
	"os"
)

func main() {
	dumper := hex.Dumper(os.Stdout)

	// really silly seed for reproduciability
	seed := make([]byte, 32)

	fmt.Println("seed:")
	dumper.Write(seed)

	public, _, err := ed25519.GenerateKey(bytes.NewReader(seed))
	fatal(err)

	fmt.Println("public ed25519:")
	dumper.Write(public)

	var curvPub [32]byte
	extra25519.PublicKeyToCurve25519(&curvPub, public)

	fmt.Println("public curve25519:")
	dumper.Write(curvPub[:])

}

func fatal(err error) {
	if err != nil {
		panic(err)
	}
}
Output:

seed:
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
public ed25519:
00000020  3b 6a 27 bc ce b6 a4 2d  62 a3 a8 d0 2a 6f 0d 73  |;j'....-b...*o.s|
00000030  65 32 15 77 1d e2 43 a6  3a c0 48 a1 8b 59 da 29  |e2.w..C.:.H..Y.)|
public curve25519:
00000040  5b f5 5c 73 b8 2e be 22  be 80 f3 43 06 67 af 57  |[.\s..."...C.g.W|
00000050  0f ae 25 56 a6 41 5e 6b  30 d4 06 53 00 aa 94 7d  |..%V.A^k0..S...}|

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL