Documentation ¶
Overview ¶
Package mac provides implementations of the MAC primitive.
MAC computes a tag for a given message that can be used to authenticate a message. MAC protects data integrity as well as provides for authenticity of the message.
Example ¶
package main import ( "encoding/base64" "fmt" "log" "github.com/google/tink/go/keyset" "github.com/google/tink/go/mac" ) func main() { kh, err := keyset.NewHandle(mac.HMACSHA256Tag256KeyTemplate()) if err != nil { log.Fatal(err) } // TODO: save the keyset to a safe location. DO NOT hardcode it in source code. // Consider encrypting it with a remote key in Cloud KMS, AWS KMS or HashiCorp Vault. // See https://github.com/google/tink/blob/master/docs/GOLANG-HOWTO.md#storing-and-loading-existing-keysets. m, err := mac.New(kh) if err != nil { log.Fatal(err) } msg := []byte("this data needs to be authenticated") tag, err := m.ComputeMAC(msg) if err != nil { log.Fatal(err) } if m.VerifyMAC(tag, msg); err != nil { log.Fatal(err) } fmt.Printf("Message: %s\n", msg) fmt.Printf("Authentication tag: %s\n", base64.StdEncoding.EncodeToString(tag)) }
Output:
Index ¶
- func AESCMACTag128KeyTemplate() *tinkpb.KeyTemplate
- func HMACSHA256Tag128KeyTemplate() *tinkpb.KeyTemplate
- func HMACSHA256Tag256KeyTemplate() *tinkpb.KeyTemplate
- func HMACSHA512Tag256KeyTemplate() *tinkpb.KeyTemplate
- func HMACSHA512Tag512KeyTemplate() *tinkpb.KeyTemplate
- func New(h *keyset.Handle) (tink.MAC, error)
- func NewWithKeyManager(h *keyset.Handle, km registry.KeyManager) (tink.MAC, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESCMACTag128KeyTemplate ¶
func AESCMACTag128KeyTemplate() *tinkpb.KeyTemplate
AESCMACTag128KeyTemplate is a KeyTemplate that generates a AES-CMAC key with the following parameters:
- Key size: 32 bytes
- Tag size: 16 bytes
func HMACSHA256Tag128KeyTemplate ¶
func HMACSHA256Tag128KeyTemplate() *tinkpb.KeyTemplate
HMACSHA256Tag128KeyTemplate is a KeyTemplate that generates a HMAC key with the following parameters:
- Key size: 32 bytes
- Tag size: 16 bytes
- Hash function: SHA256
func HMACSHA256Tag256KeyTemplate ¶
func HMACSHA256Tag256KeyTemplate() *tinkpb.KeyTemplate
HMACSHA256Tag256KeyTemplate is a KeyTemplate that generates a HMAC key with the following parameters:
- Key size: 32 bytes
- Tag size: 32 bytes
- Hash function: SHA256
func HMACSHA512Tag256KeyTemplate ¶
func HMACSHA512Tag256KeyTemplate() *tinkpb.KeyTemplate
HMACSHA512Tag256KeyTemplate is a KeyTemplate that generates a HMAC key with the following parameters:
- Key size: 64 bytes
- Tag size: 32 bytes
- Hash function: SHA512
func HMACSHA512Tag512KeyTemplate ¶
func HMACSHA512Tag512KeyTemplate() *tinkpb.KeyTemplate
HMACSHA512Tag512KeyTemplate is a KeyTemplate that generates a HMAC key with the following parameters:
- Key size: 64 bytes
- Tag size: 64 bytes
- Hash function: SHA512
func NewWithKeyManager ¶
NewWithKeyManager creates a MAC primitive from the given keyset handle and a custom key manager. Deprecated: register the KeyManager and use New above.
Types ¶
This section is empty.