Created
July 28, 2016 14:58
-
-
Save benma/08b5fde37113ab6e7e1b24b9d7ef0c95 to your computer and use it in GitHub Desktop.
ed255519 -> curve25519
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
package main | |
import ( | |
"crypto/rand" | |
"fmt" | |
"github.com/agl/ed25519" | |
"github.com/agl/ed25519/extra25519" | |
"github.com/monetas/gotary/util/enc" | |
) | |
func newk() (*[32]byte, *[32]byte) { | |
edpk, edsk, err := ed25519.GenerateKey(rand.Reader) | |
if err != nil { | |
panic(err) | |
} | |
cpk := new([32]byte) | |
if !extra25519.PublicKeyToCurve25519(cpk, edpk) { | |
panic("nope") | |
} | |
csk := new([32]byte) | |
extra25519.PrivateKeyToCurve25519(csk, edsk) | |
return cpk, csk | |
} | |
func main() { | |
ns, err := enc.NewNonceStream() | |
if err != nil { | |
panic(err) | |
} | |
for i := 0; i < 10000; i++ { | |
pk, sk := newk() | |
pk2, sk2 := newk() | |
cipher, err := enc.Encrypt([]byte("LOL"), pk2, sk, ns) | |
if err != nil { | |
panic(err) | |
} | |
decrypted, err := enc.Decrypt(cipher, pk, sk2) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(string(decrypted)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
failed 50.3 %