示例#1
0
文件: key.go 项目: ZiRo-/srndv2
// get public key from secret key
func GetBoxPubkey(sk []byte) []byte {
	sk_len := C.crypto_box_seedbytes()
	if C.size_t(len(sk)) != sk_len {
		return nil
	}

	pk_len := C.crypto_box_publickeybytes()
	pkbuff := malloc(pk_len)
	defer pkbuff.Free()

	skbuff := NewBuffer(sk)
	defer skbuff.Free()

	// compute the public key
	C.crypto_scalarmult_base(pkbuff.uchar(), skbuff.uchar())

	return pkbuff.Bytes()
}
示例#2
0
文件: key.go 项目: ZiRo-/srndv2
// make keypair from seed
func SeedBoxKey(seed []byte) *KeyPair {
	seed_len := C.crypto_box_seedbytes()
	if C.size_t(len(seed)) != seed_len {
		return nil
	}
	seedbuff := NewBuffer(seed)
	defer seedbuff.Free()
	pk_len := C.crypto_box_publickeybytes()
	sk_len := C.crypto_box_secretkeybytes()
	pkbuff := malloc(pk_len)
	skbuff := malloc(sk_len)
	res := C.crypto_box_seed_keypair(pkbuff.uchar(), skbuff.uchar(), seedbuff.uchar())
	if res != 0 {
		pkbuff.Free()
		skbuff.Free()
		return nil
	}
	return &KeyPair{pkbuff, skbuff}
}
示例#3
0
文件: key.go 项目: 4cdn/srndv2
// make keypair from seed
func SeedBoxKey(seed []byte) *KeyPair {
	seed_len := C.crypto_box_seedbytes()
	if C.size_t(len(seed)) != seed_len {
		log.Println("nacl.SeedBoxKey() invalid seed size", len(seed))
		return nil
	}
	seedbuff := NewBuffer(seed)
	defer seedbuff.Free()
	pk_len := C.crypto_box_publickeybytes()
	sk_len := C.crypto_box_secretkeybytes()
	pkbuff := malloc(pk_len)
	skbuff := malloc(sk_len)
	res := C.crypto_box_seed_keypair(pkbuff.uchar(), skbuff.uchar(), seedbuff.uchar())
	if res != 0 {
		pkbuff.Free()
		skbuff.Free()
		log.Println("nacl.SeedBoxKey cannot derive keys from seed:", res)
		return nil
	}
	return &KeyPair{pkbuff, skbuff}
}
示例#4
0
func BoxSeedBytes() int {
	return int(C.crypto_box_seedbytes())
}