示例#1
0
// CreateKeyPair needs no input, produces a public key and secret key as output
func CreateKeyPair() (publicKey PublicKey, secretKey SecretKey, err error) {
	errorCode := C.crypto_sign_keypair((*C.uchar)(unsafe.Pointer(&publicKey[0])), (*C.uchar)(unsafe.Pointer(&secretKey[0])))
	if errorCode != 0 {
		err = fmt.Errorf("Key Creation Failed!")
		return
	}

	return
}
示例#2
0
// EdDSAGenerateKeys generates an EdDSA private key. The public key
// can be derived from the private key, so there is no issue.
// Keys are represented by byte slices, and can be cast to and from them.
func EdDSAGenerateKey() EdDSAPrivate {
	priv := make([]byte, EdDSAPrivateLength)
	publ := make([]byte, EdDSAPublicLength)
	rv := C.crypto_sign_keypair((*C.uchar)(&publ[0]), (*C.uchar)(&priv[0]))
	if rv != 0 {
		panic("crypto_sign_keypair returned non-zero")
	}
	return priv
}
示例#3
0
func CryptoSignKeyPair() ([]byte, []byte, int) {
	sk := make([]byte, CryptoSignSecretKeyBytes())
	pk := make([]byte, CryptoSignPublicKeyBytes())
	exit := int(C.crypto_sign_keypair(
		(*C.uchar)(&pk[0]),
		(*C.uchar)(&sk[0])))

	return sk, pk, exit
}
示例#4
0
文件: key.go 项目: ZiRo-/srndv2
// generate a keypair
func GenSignKeypair() *KeyPair {
	sk_len := C.crypto_sign_secretkeybytes()
	sk := malloc(sk_len)
	pk_len := C.crypto_sign_publickeybytes()
	pk := malloc(pk_len)
	res := C.crypto_sign_keypair(pk.uchar(), sk.uchar())
	if res == 0 {
		return &KeyPair{pk, sk}
	}
	pk.Free()
	sk.Free()
	return nil
}
示例#5
0
文件: key.go 项目: 4cdn/srndv2
// generate a keypair
func GenSignKeypair() *KeyPair {
	sk_len := C.crypto_sign_secretkeybytes()
	sk := malloc(sk_len)
	pk_len := C.crypto_sign_publickeybytes()
	pk := malloc(pk_len)
	res := C.crypto_sign_keypair(pk.uchar(), sk.uchar())
	if res == 0 {
		return &KeyPair{pk, sk}
	}
	log.Println("nacl.GenSignKeypair() failed to generate keypair")
	pk.Free()
	sk.Free()
	return nil
}
示例#6
0
func SignKeyPair(pkOut []byte, skOut []byte) int {
	support.CheckSize(pkOut, SignPublicKeyBytes(), "sign key pair public")
	support.CheckSize(skOut, SignSecretKeyBytes(), "sign key pair secret")
	return int(C.crypto_sign_keypair((*C.uchar)(&pkOut[0]), (*C.uchar)(&skOut[0])))
}