Exemple #1
0
func CryptoSignSeedKeyPair(seed []byte) ([]byte, []byte, int) {
	support.CheckSize(seed, CryptoSignSeedBytes(), "seed")
	sk := make([]byte, CryptoSignSecretKeyBytes())
	pk := make([]byte, CryptoSignPublicKeyBytes())
	exit := int(C.crypto_sign_seed_keypair(
		(*C.uchar)(&pk[0]),
		(*C.uchar)(&sk[0]),
		(*C.uchar)(&seed[0])))

	return sk, pk, exit
}
Exemple #2
0
// make keypair from seed
func LoadSignKey(seed []byte) *KeyPair {
	seed_len := C.crypto_sign_seedbytes()
	if C.size_t(len(seed)) != seed_len {
		return nil
	}
	seedbuff := NewBuffer(seed)
	defer seedbuff.Free()
	pk_len := C.crypto_sign_publickeybytes()
	sk_len := C.crypto_sign_secretkeybytes()
	pkbuff := malloc(pk_len)
	skbuff := malloc(sk_len)
	res := C.crypto_sign_seed_keypair(pkbuff.uchar(), skbuff.uchar(), seedbuff.uchar())
	if res != 0 {
		pkbuff.Free()
		skbuff.Free()
		return nil
	}
	return &KeyPair{pkbuff, skbuff}
}
Exemple #3
0
// make keypair from seed
func LoadSignKey(seed []byte) *KeyPair {
	seed_len := C.crypto_sign_seedbytes()
	if C.size_t(len(seed)) != seed_len {
		log.Println("nacl.SeedSignKey() invalid seed size", len(seed))
		return nil
	}
	seedbuff := NewBuffer(seed)
	defer seedbuff.Free()
	pk_len := C.crypto_sign_publickeybytes()
	sk_len := C.crypto_sign_secretkeybytes()
	pkbuff := malloc(pk_len)
	skbuff := malloc(sk_len)
	res := C.crypto_sign_seed_keypair(pkbuff.uchar(), skbuff.uchar(), seedbuff.uchar())
	if res != 0 {
		log.Println("nacl.SeedSignKey cannot derive keys from seed", res)
		pkbuff.Free()
		skbuff.Free()
		return nil
	}
	return &KeyPair{pkbuff, skbuff}
}
Exemple #4
0
// get public key from secret key
func GetSignPubkey(sk []byte) ([]byte, error) {
	sk_len := C.crypto_sign_secretkeybytes()
	if C.size_t(len(sk)) != sk_len {
		return nil, errors.New(fmt.Sprintf("nacl.GetSignPubkey() invalid secret key size %d != %d", len(sk), sk_len))
	}

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

	skbuff := NewBuffer(sk)
	defer skbuff.Free()
	//XXX: hack
	res := C.crypto_sign_seed_keypair(pkbuff.uchar(), skbuff.uchar(), skbuff.uchar())

	if res != 0 {
		return nil, errors.New(fmt.Sprintf("nacl.GetSignPubkey() failed to get public key from secret key: %d", res))
	}

	return pkbuff.Bytes(), nil
}
Exemple #5
0
func SignSeedKeyPair(pkOut []byte, skOut []byte, seed []byte) int {
	return int(C.crypto_sign_seed_keypair((*C.uchar)(&pkOut[0]), (*C.uchar)(&skOut[0]), (*C.uchar)(&seed[0])))
}