本文整理汇总了Golang中github.com/dedis/crypto/edwards/ed25519.NewAES128SHA256Ed25519函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAES128SHA256Ed25519函数的具体用法?Golang NewAES128SHA256Ed25519怎么用?Golang NewAES128SHA256Ed25519使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAES128SHA256Ed25519函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSmallConfigHealthyEd25519
func TestSmallConfigHealthyEd25519(t *testing.T) {
suite := ed25519.NewAES128SHA256Ed25519(true)
RoundsPerView := 100
if err := runTreeSmallConfig(sign.MerkleTree, RoundsPerView, suite, 0); err != nil {
t.Fatal(err)
}
}
示例2: main
/* runs through the process of setting up the server as specified in the args */
func main() {
kingpin.MustParse(app.Parse(os.Args[1:]))
var port int = *appPort
var kfilepath string = *appPrivatekeyfile
var kinfopath string = *appInfo
fmt.Printf("Sigserv3 - listening on port %d.\n", port)
suite := ed25519.NewAES128SHA256Ed25519(true)
kv, err := crypto.SchnorrLoadKeypair(kfilepath, suite)
if err != nil {
fmt.Println("Error " + err.Error())
return
}
info, err := LoadInfo(kinfopath)
if err != nil {
fmt.Println("Error " + err.Error())
return
}
// I don't know if there's a way to
// do std::bind-like behaviour in GO.
// for C++ what I'd do is pretty simple:
// newfunc := std::bind(&func, args to bind)
var signBlindImpl connectionhandler = func(conn net.Conn) {
signBlindlySchnorr(conn, suite, kv, info)
}
serve(port, signBlindImpl)
}
示例3: runMultiSignatureGen
/* Create a group configuration file. This is really a convenience feature
more than anything, making it easier to direct the client than supplying
all the arguments on the command line. */
func runMultiSignatureGen(group []SchnorrMSHostSpec, outputFile string) error {
var config SchnorrMGroupConfig
var pkeys []crypto.SchnorrPublicKey
suite := ed25519.NewAES128SHA256Ed25519(true)
for _, mshp := range group {
pkey, err := crypto.SchnorrLoadPubkey(mshp.KeyFilePath, suite)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
pkeys = append(pkeys, pkey)
member := SchnorrMMember{mshp.HostName, mshp.Port, pkey}
config.Members = append(config.Members, member)
}
jointKey := crypto.SchnorrMComputeSharedPublicKey(suite, pkeys)
config.JointKey = jointKey.GetSchnorrPK()
data, _ := json.Marshal(config)
f, err := os.OpenFile(outputFile, os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
return err
}
defer f.Close()
_, err = f.Write(data)
return err
}
示例4: main
func main() {
var port int
var kfilepath string
flag.IntVar(&port, "port", 1111, "Listen on given port")
flag.StringVar(&kfilepath, "keyfile", "", "Use the keyfile specified")
flag.Parse()
fmt.Printf("Sigserv1 - listening on port %d.\n", port)
suite := ed25519.NewAES128SHA256Ed25519(true)
kv, err := crypto.SchnorrLoadKeypair(kfilepath, suite)
if err != nil {
fmt.Println("Error " + err.Error())
return
}
// I don't know if there's a way to
// do std::bind-like behaviour in GO.
// for C++ what I'd do is pretty simple:
// newfunc := std::bind(&func, args to bind)
var signOneKBImpl connectionhandler = func(conn net.Conn) {
signOneKBMSchnorr(conn, suite, kv)
}
serve(port, signOneKBImpl)
}
示例5: initialize
// Helper function to create some stuff for testing
func initialize() (abstract.Suite, *PriKey, *PubKey, abstract.Point) {
suite := ed25519.NewAES128SHA256Ed25519(true)
sk, pk := GenerateKeyPair(suite)
el, _ := suite.Point().Pick(nil, suite.Cipher(nil))
return suite, sk, pk, el
}
示例6: All
// Returns a map of all suites
func All() Suites {
s := make(Suites)
s.add(nist.NewAES128SHA256P256())
s.add(nist.NewAES128SHA256QR512())
s.add(edwards.NewAES128SHA256Ed25519(false))
s.add(ed25519.NewAES128SHA256Ed25519(false))
return s
}
示例7: main
func main() {
var port int
var hostname string
var kfilepath string
flag.StringVar(&kfilepath, "keyfile", "", "Use the keyfile specified")
flag.StringVar(&hostname, "host", "localhost", "Connect to the specified host")
flag.IntVar(&port, "port", 1111, "Use the specified port")
flag.Parse()
suite := ed25519.NewAES128SHA256Ed25519(true)
pk, err := crypto.SchnorrLoadPubkey(kfilepath, suite)
if err != nil {
fmt.Println("Error " + err.Error())
return
}
fmt.Println(pk.Y)
var hostspec string
hostspec = fmt.Sprintf("%s:%d", hostname, port)
fmt.Println("Connecting to %s\n", hostspec)
conn, err := net.Dial("tcp", hostspec)
if err != nil {
fmt.Println(err.Error())
return
}
randomdata := make([]byte, 1024)
_, err = rand.Read(randomdata)
if err != nil {
fmt.Println(err.Error())
return
}
buffer := make([]byte, 64)
conn.Write(randomdata)
_, err = conn.Read(buffer)
if err != nil {
fmt.Println(err.Error())
return
}
v, err := crypto.SchnorrVerify(suite, pk, randomdata, buffer)
if err != nil {
fmt.Println(err.Error())
return
}
if v == true {
fmt.Println("Signature verified OK")
} else {
fmt.Println("Signature verify FAILED")
}
return
}
示例8: decodeFromB64
func decodeFromB64(buf []byte) abstract.Point {
suite := ed25519.NewAES128SHA256Ed25519(true)
str := string(buf)
decodedBytes, _ := hex.DecodeString(str)
P := suite.Point()
decoded := bytes.NewBuffer(decodedBytes)
_ = abstract.Read(decoded, &P, suite)
return P
}
示例9: encodeAsB64
func encodeAsB64(y abstract.Point) string {
// there must be better ways of doing this. Ideally,
// we should have JSON marshalling for the
// point, secret types in dedis/crypto
// but we don't, so, that's a shame.
suite := ed25519.NewAES128SHA256Ed25519(true)
buf := bytes.Buffer{}
abstract.Write(&buf, &y, suite)
return hex.EncodeToString(buf.Bytes())
}
示例10: TestSchnorrGenerateKeyset
func TestSchnorrGenerateKeyset(t *testing.T) {
// again, if I had more time and was publishing
// this, I'd be calculating some known values
// outside this code
// and checking generation produced what it
// should.
suite := ed25519.NewAES128SHA256Ed25519(true)
_, err := SchnorrGenerateKeypair(suite)
if err != nil {
t.Error("Keypair generation failed")
}
}
示例11: TestLoadSaveKeys
func TestLoadSaveKeys(t *testing.T) {
suite := ed25519.NewAES128SHA256Ed25519(true)
keypair, err := SchnorrGenerateKeypair(suite)
if err != nil {
t.Error("Keypair generation failed")
}
pk := SchnorrExtractPubkey(keypair)
err = SchnorrSaveKeypair("/tmp/gotests.pri", suite, keypair)
if err != nil {
t.Error("Failed to write file")
}
err = SchnorrSavePubkey("/tmp/gotests.pub", suite, pk)
if err != nil {
t.Error("Failed to write file")
}
keypair_loaded, err := SchnorrLoadKeypair("/tmp/gotests.pri", suite)
if err != nil {
t.Error("Failed to load keypair")
}
pk_loaded, err := SchnorrLoadPubkey("/tmp/gotests.pub", suite)
message := []byte("This is a test")
wrongmessage := []byte("Clearly this shouldn't work")
sig, err := SchnorrSign(suite, keypair_loaded, message)
if err != nil {
t.Error("Signature Generation failed")
}
v1, e1 := SchnorrVerify(suite, pk_loaded, message, sig)
if e1 != nil {
t.Error("Error during Verification")
}
if v1 == false {
t.Error("Verification of signature failed")
}
v2, e2 := SchnorrVerify(suite, pk_loaded, wrongmessage, sig)
if e2 != nil {
t.Error("Error during Verification")
}
if v2 == true {
t.Error("Verification of signature succeeded for bad message")
}
}
示例12: GetSuite
func GetSuite(suite string) abstract.Suite {
var s abstract.Suite
switch {
case suite == "nist256":
s = nist.NewAES128SHA256P256()
case suite == "nist512":
s = nist.NewAES128SHA256QR512()
case suite == "ed25519":
s = ed25519.NewAES128SHA256Ed25519(true)
default:
s = nist.NewAES128SHA256P256()
}
return s
}
示例13: TestSchnorrSignature
func TestSchnorrSignature(t *testing.T) {
suite := ed25519.NewAES128SHA256Ed25519(true)
// for good measure, do a few.
// in proper code we'd not just rely
// on random generation, we'd also have
// some known test vectors.
for i := 0; i < 100; i++ {
kv, err := SchnorrGenerateKeypair(suite)
if err != nil {
t.Error("Keypair generation failed")
}
pk := SchnorrExtractPubkey(kv)
message := []byte("This is a test")
wrongmessage := []byte("Clearly this shouldn't work")
sig, err := SchnorrSign(suite, kv, message)
if err != nil {
t.Error("Signature Generation failed")
}
v1, e1 := SchnorrVerify(suite, pk, message, sig)
if e1 != nil {
t.Error("Error during Verification")
}
if v1 == false {
t.Error("Verification of signature failed")
}
v2, e2 := SchnorrVerify(suite, pk, wrongmessage, sig)
if e2 != nil {
t.Error("Error during Verification")
}
if v2 == true {
t.Error("Verification of signature succeeded for bad message")
}
}
}
示例14: TestShuffle
func TestShuffle(T *testing.T) {
amount := 6
servers := 3
suite := ed25519.NewAES128SHA256Ed25519(true)
sks, pks := make([]*elgamal.PriKey, servers), make([]*elgamal.PubKey, servers)
// Generate keys for the shuffle servers
for i := 0; i < servers; i++ {
sks[i], pks[i] = elgamal.GenerateKeyPair(suite)
}
// Generate random plaintexts, encrypt them all to the sum of all server public keys
sumpks := elgamal.SumKeys(pks)
points, ciphers := make([]abstract.Point, amount), make([]*elgamal.CipherText, amount)
for i := 0; i < amount; i++ {
points[i], _ = suite.Point().Pick(nil, suite.Cipher(nil))
ciphers[i] = sumpks.Encrypt(points[i])
}
var shuffle *VerifiableShuffle
var err error
for i := 0; i < servers; i++ {
shuffle, err = ShuffleDecrypt(suite, ciphers, pks, sks[i], "nonce", i)
if err != nil {
T.Fatalf("Failed to create proof: %v", err)
}
if err = shuffle.Verify(ciphers, pks, "nonce", i); err != nil {
T.Fatal("Shuffle verification failed: ", err)
}
// These are the ones that should be shuffled by the next server
ciphers = shuffle.Decrypted
}
for i := 0; i < amount; i++ {
T.Log(str(points[i]), str(shuffle.Decrypted[i].C2))
}
}
示例15: TestPartialBlindSignatureScheme
func TestPartialBlindSignatureScheme(t *testing.T) {
// I tried suite := ed25519.NewAES128SHA256Ed25519(true) but got null pointer derefs
suite := ed25519.NewAES128SHA256Ed25519(true)
privKey, _ := SchnorrGenerateKeypair(suite)
pubKey := SchnorrExtractPubkey(privKey)
// now "agree" some information. For our purposes just fish
// some bytes out of /dev/urandom
info := make([]byte, 16)
_, err := rand.Read(info)
if err != nil {
t.Error(err.Error())
}
badinfo := make([]byte, 16)
_, err = rand.Read(info)
if err != nil {
t.Error(err.Error())
}
// likewise let's sign a random message.
message := make([]byte, 16)
_, err = rand.Read(message)
if err != nil {
t.Error(err.Error())
}
// now the first step from pg277
signerParams, err := NewPrivateParams(suite, info)
if err != nil {
t.Error(err.Error())
}
// "send" these to the user.
userPublicParams := signerParams.DerivePubParams()
// now the user does their thing.
challenge, userPrivateParams, err := ClientGenerateChallenge(suite, userPublicParams, pubKey, info, message)
if err != nil {
t.Error(err.Error())
}
// and now we compute a response on the server side.
response := ServerGenerateResponse(suite, challenge, signerParams, privKey)
// finally, we can sign the message and check it verifies.
sig, worked := ClientSignBlindly(suite, userPrivateParams, response, pubKey, message)
//fmt.Println(blindSignature)
if worked != true {
t.Error("Signature scheme did not return true.")
}
// now verify this worked fine.
result, err := VerifyBlindSignature(suite, pubKey, sig, info, message)
if err != nil {
t.Error(err.Error())
}
if result != true {
t.Error("VerifyBlindSignature failed with valid info - this should work.")
}
// and now try again with the wrong information to prove
// that any change in this information fails to generate the correct
// signature.
result, err = VerifyBlindSignature(suite, pubKey, sig, badinfo, message)
if err != nil {
t.Error(err.Error())
}
if result != false {
t.Error("VerifyBlindSignature succeeded with bad info - this should fail.")
}
}