Esempio n. 1
0
// I took care of the typedef confusions. This should work okay.
func CryptoGenericHash(outlen int, in []byte, key []byte) ([]byte, int) {
	support.CheckSizeInRange(outlen, CryptoGenericHashBytesMin(), CryptoGenericHashBytesMax(), "out")
	support.CheckSizeInRange(len(key), CryptoGenericHashKeyBytesMin(), CryptoGenericHashKeyBytesMax(), "key")
	out := make([]byte, outlen)
	exit := int(C.crypto_generichash(
		(*C.uchar)(&out[0]),
		(C.size_t)(outlen),
		(*C.uchar)(&in[0]),
		(C.ulonglong)(len(in)),
		(*C.uchar)(&key[0]),
		(C.size_t)(len(key))))

	return out, exit
}
Esempio n. 2
0
func CryptoGenericHashFinal(state *C.struct_crypto_generichash_blake2b_state, outlen int) (*C.struct_crypto_generichash_blake2b_state, []byte, int) {
	support.CheckSizeInRange(outlen, CryptoGenericHashBytesMin(), CryptoGenericHashBytesMax(), "out")
	out := make([]byte, outlen)
	exit := int(C.crypto_generichash_final(
		state,
		(*C.uchar)(&out[0]),
		(C.size_t)(outlen)))

	return state, out, exit
}
Esempio n. 3
0
// I took care of the typedef confusions. This should work okay.
func CryptoGenericHashInit(key []byte, outlen int) (*C.struct_crypto_generichash_blake2b_state, int) {
	support.CheckSizeInRange(outlen, CryptoGenericHashBytesMin(), CryptoGenericHashBytesMax(), "out")
	state := new(C.struct_crypto_generichash_blake2b_state)
	exit := int(C.crypto_generichash_init(
		(*C.struct_crypto_generichash_blake2b_state)(state),
		(*C.uchar)(&key[0]),
		(C.size_t)(len(key)),
		(C.size_t)(outlen)))

	return state, exit
}