コード例 #1
0
ファイル: onetimeauth.go プロジェクト: alanfairless/GoSodium
// OneTimeAuth computes a message authentication code (MAC) for the given input buffer and writes
// it to 'out'. 'out' must be a []byte of OneTimeAuthBytes() bytes. 'key' must not be used with
// any other messages.
//
// Returns: 0
// TODO: Can this ever return non-zero? If not should not return a value.
func OneTimeAuth(macOut []byte, message []byte, key []byte) int {
	support.CheckSize(macOut, OneTimeAuthBytes(), "MAC output buffer")
	support.CheckSize(key, OneTimeAuthKeyBytes(), "key")

	return int(C.crypto_onetimeauth(
		(*C.uchar)(&macOut[0]),
		(*C.uchar)(&message[0]), (C.ulonglong)(len(message)),
		(*C.uchar)(&key[0])))
}
コード例 #2
0
func OneTimeAuth(message []byte, key []byte) []byte {
	if len(key) != OneTimeAuthKeySize {
		panic(fmt.Sprintf("Key is wrong size; expected it to be %d", C.crypto_onetimeauth_KEYBYTES))
	}

	auth := make([]byte, C.crypto_onetimeauth_BYTES)

	C.crypto_onetimeauth(array(auth), array(message), C.ulonglong(len(message)), array(key))

	return auth
}