diff --git a/go/subtle/aead/chacha20poly1305.go b/go/subtle/aead/chacha20poly1305.go index 8fa0687a91..2055b30941 100644 --- a/go/subtle/aead/chacha20poly1305.go +++ b/go/subtle/aead/chacha20poly1305.go @@ -24,29 +24,29 @@ import ( "github.com/google/tink/go/tink" ) -// Chacha20poly1305Aead is an implementation of Aead interface. -type Chacha20poly1305Aead struct { - key []byte +// ChaCha20Poly1305 is an implementation of Aead interface. +type ChaCha20Poly1305 struct { + Key []byte } -// Assert that Chacha20poly1305Aead implements the Aead interface. -var _ tink.Aead = (*Chacha20poly1305Aead)(nil) +// Assert that ChaCha20Poly1305 implements the Aead interface. +var _ tink.Aead = (*ChaCha20Poly1305)(nil) -// NewChacha20poly1305Aead returns an Chacha20poly1305Aead instance. +// NewChaCha20Poly1305 returns an ChaCha20Poly1305 instance. // The key argument should be a 32-bytes key. -func NewChacha20poly1305Aead(key []byte) (*Chacha20poly1305Aead, error) { +func NewChaCha20Poly1305(key []byte) (*ChaCha20Poly1305, error) { if len(key) != chacha20poly1305.KeySize { return nil, errors.New("chacha20poly1305: bad key length") } - return &Chacha20poly1305Aead{key: key}, nil + return &ChaCha20Poly1305{Key: key}, nil } // Encrypt encrypts {@code pt} with {@code aad} as additional // authenticated data. The resulting ciphertext consists of two parts: // (1) the nonce used for encryption and (2) the actual ciphertext. -func (ca *Chacha20poly1305Aead) Encrypt(pt []byte, aad []byte) ([]byte, error) { - c, err := chacha20poly1305.New(ca.key) +func (ca *ChaCha20Poly1305) Encrypt(pt []byte, aad []byte) ([]byte, error) { + c, err := chacha20poly1305.New(ca.Key) if err != nil { return nil, err } @@ -60,8 +60,8 @@ func (ca *Chacha20poly1305Aead) Encrypt(pt []byte, aad []byte) ([]byte, error) { } // Decrypt decrypts {@code ct} with {@code aad} as the additionalauthenticated data. -func (ca *Chacha20poly1305Aead) Decrypt(ct []byte, aad []byte) ([]byte, error) { - c, err := chacha20poly1305.New(ca.key) +func (ca *ChaCha20Poly1305) Decrypt(ct []byte, aad []byte) ([]byte, error) { + c, err := chacha20poly1305.New(ca.Key) if err != nil { return nil, err } @@ -69,12 +69,12 @@ func (ca *Chacha20poly1305Aead) Decrypt(ct []byte, aad []byte) ([]byte, error) { n := ct[:chacha20poly1305.NonceSize] pt, err := c.Open(nil, n, ct[chacha20poly1305.NonceSize:], aad) if err != nil { - return nil, fmt.Errorf("Chacha20poly1305Aead.Decrypt: %s", err) + return nil, fmt.Errorf("ChaCha20Poly1305.Decrypt: %s", err) } return pt, nil } // newNonce creates a new nonce for encryption. -func (ca *Chacha20poly1305Aead) newNonce() []byte { +func (ca *ChaCha20Poly1305) newNonce() []byte { return random.GetRandomBytes(chacha20poly1305.NonceSize) } diff --git a/go/subtle/aead/chacha20poly1305_test.go b/go/subtle/aead/chacha20poly1305_test.go index 2eeb82d114..096c60ac19 100644 --- a/go/subtle/aead/chacha20poly1305_test.go +++ b/go/subtle/aead/chacha20poly1305_test.go @@ -27,17 +27,17 @@ import ( "github.com/google/tink/go/subtle/random" ) -func TestChacha20poly1305EncryptDecrypt(t *testing.T) { - for i, test := range chacha20Poly1305Tests { +func TestChaCha20Poly1305EncryptDecrypt(t *testing.T) { + for i, test := range chaCha20Poly1305Tests { key, _ := hex.DecodeString(test.key) pt, _ := hex.DecodeString(test.plaintext) aad, _ := hex.DecodeString(test.aad) nonce, _ := hex.DecodeString(test.nonce) out, _ := hex.DecodeString(test.out) - ca, err := aead.NewChacha20poly1305Aead(key) + ca, err := aead.NewChaCha20Poly1305(key) if err != nil { - t.Errorf("#%d, cannot create new instance of Chacha20poly1305Aead: %s", i, err) + t.Errorf("#%d, cannot create new instance of ChaCha20Poly1305: %s", i, err) continue } @@ -60,12 +60,12 @@ func TestChacha20poly1305EncryptDecrypt(t *testing.T) { } } -func TestChacha20poly1305EmptyAssociatedData(t *testing.T) { +func TestChaCha20Poly1305EmptyAssociatedData(t *testing.T) { key := random.GetRandomBytes(chacha20poly1305.KeySize) aad := []byte{} badAad := []byte{1, 2, 3} - ca, err := aead.NewChacha20poly1305Aead(key) + ca, err := aead.NewChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -110,7 +110,7 @@ func TestChacha20poly1305EmptyAssociatedData(t *testing.T) { } } -func TestChacha20poly1305LongMessages(t *testing.T) { +func TestChaCha20Poly1305LongMessages(t *testing.T) { dataSize := uint32(16) // Encrypts and decrypts messages of size <= 8192. for dataSize <= 1<<24 { @@ -118,7 +118,7 @@ func TestChacha20poly1305LongMessages(t *testing.T) { aad := random.GetRandomBytes(dataSize / 3) key := random.GetRandomBytes(chacha20poly1305.KeySize) - ca, err := aead.NewChacha20poly1305Aead(key) + ca, err := aead.NewChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -137,13 +137,13 @@ func TestChacha20poly1305LongMessages(t *testing.T) { } } -func TestChacha20poly1305ModifyCiphertext(t *testing.T) { - for i, test := range chacha20Poly1305Tests { +func TestChaCha20Poly1305ModifyCiphertext(t *testing.T) { + for i, test := range chaCha20Poly1305Tests { key, _ := hex.DecodeString(test.key) pt, _ := hex.DecodeString(test.plaintext) aad, _ := hex.DecodeString(test.aad) - ca, err := aead.NewChacha20poly1305Aead(key) + ca, err := aead.NewChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -176,9 +176,9 @@ func TestChacha20poly1305ModifyCiphertext(t *testing.T) { // This is a very simple test for the randomness of the nonce. // The test simply checks that the multiple ciphertexts of the same message are distinct. -func TestChacha20poly1305RandomNonce(t *testing.T) { +func TestChaCha20Poly1305RandomNonce(t *testing.T) { key := random.GetRandomBytes(chacha20poly1305.KeySize) - ca, err := aead.NewChacha20poly1305Aead(key) + ca, err := aead.NewChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -196,7 +196,7 @@ func TestChacha20poly1305RandomNonce(t *testing.T) { } } -func TestChacha20poly1305WycheproofVectors(t *testing.T) { +func TestChaCha20Poly1305WycheproofVectors(t *testing.T) { f, err := os.Open("../../../../wycheproof/testvectors/chacha20_poly1305_test.json") if err != nil { t.Fatalf("cannot open file: %s, make sure that github.com/google/wycheproof is in your gopath", err) @@ -246,9 +246,9 @@ func TestChacha20poly1305WycheproofVectors(t *testing.T) { combinedCt = append(combinedCt, ct...) combinedCt = append(combinedCt, tag...) - ca, err := aead.NewChacha20poly1305Aead(key) + ca, err := aead.NewChaCha20Poly1305(key) if err != nil { - t.Errorf("#%d, cannot create new instance of Chacha20poly1305Aead: %s", tc.TcID, err) + t.Errorf("#%d, cannot create new instance of ChaCha20Poly1305: %s", tc.TcID, err) continue } diff --git a/go/subtle/aead/chacha20poly1305_vectors_test.go b/go/subtle/aead/chacha20poly1305_vectors_test.go index d80d672db0..a0c7922f00 100644 --- a/go/subtle/aead/chacha20poly1305_vectors_test.go +++ b/go/subtle/aead/chacha20poly1305_vectors_test.go @@ -14,7 +14,7 @@ package aead_test -var chacha20Poly1305Tests = []struct { +var chaCha20Poly1305Tests = []struct { plaintext, aad, key, nonce, out string }{ { diff --git a/go/subtle/aead/xchacha20poly1305.go b/go/subtle/aead/xchacha20poly1305.go index 24f2a8305e..99f3d2494f 100644 --- a/go/subtle/aead/xchacha20poly1305.go +++ b/go/subtle/aead/xchacha20poly1305.go @@ -24,29 +24,29 @@ import ( "github.com/google/tink/go/tink" ) -// XChacha20poly1305Aead is an implementation of Aead interface. -type XChacha20poly1305Aead struct { - key []byte +// XChaCha20Poly1305 is an implementation of Aead interface. +type XChaCha20Poly1305 struct { + Key []byte } -// Assert that XChacha20poly1305Aead implements the Aead interface. -var _ tink.Aead = (*XChacha20poly1305Aead)(nil) +// Assert that XChaCha20Poly1305 implements the Aead interface. +var _ tink.Aead = (*XChaCha20Poly1305)(nil) -// NewXChacha20poly1305Aead returns an XChacha20poly1305Aead instance. +// NewXChaCha20Poly1305 returns an XChaCha20Poly1305 instance. // The key argument should be a 32-bytes key. -func NewXChacha20poly1305Aead(key []byte) (*XChacha20poly1305Aead, error) { +func NewXChaCha20Poly1305(key []byte) (*XChaCha20Poly1305, error) { if len(key) != chacha20poly1305.KeySize { return nil, errors.New("xchacha20poly1305: bad key length") } - return &XChacha20poly1305Aead{key: key}, nil + return &XChaCha20Poly1305{Key: key}, nil } // Encrypt encrypts {@code pt} with {@code aad} as additional // authenticated data. The resulting ciphertext consists of two parts: // (1) the nonce used for encryption and (2) the actual ciphertext. -func (x *XChacha20poly1305Aead) Encrypt(pt []byte, aad []byte) ([]byte, error) { - c, err := chacha20poly1305.NewX(x.key) +func (x *XChaCha20Poly1305) Encrypt(pt []byte, aad []byte) ([]byte, error) { + c, err := chacha20poly1305.NewX(x.Key) if err != nil { return nil, err } @@ -60,8 +60,8 @@ func (x *XChacha20poly1305Aead) Encrypt(pt []byte, aad []byte) ([]byte, error) { } // Decrypt decrypts {@code ct} with {@code aad} as the additionalauthenticated data. -func (x *XChacha20poly1305Aead) Decrypt(ct []byte, aad []byte) ([]byte, error) { - c, err := chacha20poly1305.NewX(x.key) +func (x *XChaCha20Poly1305) Decrypt(ct []byte, aad []byte) ([]byte, error) { + c, err := chacha20poly1305.NewX(x.Key) if err != nil { return nil, err } @@ -69,12 +69,12 @@ func (x *XChacha20poly1305Aead) Decrypt(ct []byte, aad []byte) ([]byte, error) { n := ct[:chacha20poly1305.NonceSizeX] pt, err := c.Open(nil, n, ct[chacha20poly1305.NonceSizeX:], aad) if err != nil { - return nil, fmt.Errorf("XChacha20poly1305Aead.Decrypt: %s", err) + return nil, fmt.Errorf("XChaCha20Poly1305.Decrypt: %s", err) } return pt, nil } // newNonce creates a new nonce for encryption. -func (x *XChacha20poly1305Aead) newNonce() []byte { +func (x *XChaCha20Poly1305) newNonce() []byte { return random.GetRandomBytes(chacha20poly1305.NonceSizeX) } diff --git a/go/subtle/aead/xchacha20poly1305_test.go b/go/subtle/aead/xchacha20poly1305_test.go index 027d1bd456..6b7213314a 100644 --- a/go/subtle/aead/xchacha20poly1305_test.go +++ b/go/subtle/aead/xchacha20poly1305_test.go @@ -25,8 +25,8 @@ import ( "github.com/google/tink/go/subtle/random" ) -func TestXChacha20poly1305EncryptDecrypt(t *testing.T) { - for i, test := range xChacha20Poly1305Tests { +func TestXChaCha20Poly1305EncryptDecrypt(t *testing.T) { + for i, test := range xChaCha20Poly1305Tests { key, _ := hex.DecodeString(test.key) pt, _ := hex.DecodeString(test.plaintext) aad, _ := hex.DecodeString(test.aad) @@ -34,9 +34,9 @@ func TestXChacha20poly1305EncryptDecrypt(t *testing.T) { out, _ := hex.DecodeString(test.out) tag, _ := hex.DecodeString(test.tag) - x, err := aead.NewXChacha20poly1305Aead(key) + x, err := aead.NewXChaCha20Poly1305(key) if err != nil { - t.Errorf("#%d, cannot create new instance of XChacha20poly1305Aead: %s", i, err) + t.Errorf("#%d, cannot create new instance of XChaCha20Poly1305: %s", i, err) continue } @@ -60,12 +60,12 @@ func TestXChacha20poly1305EncryptDecrypt(t *testing.T) { } } -func TestXChacha20poly1305EmptyAssociatedData(t *testing.T) { +func TestXChaCha20Poly1305EmptyAssociatedData(t *testing.T) { key := random.GetRandomBytes(chacha20poly1305.KeySize) aad := []byte{} badAad := []byte{1, 2, 3} - x, err := aead.NewXChacha20poly1305Aead(key) + x, err := aead.NewXChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -110,7 +110,7 @@ func TestXChacha20poly1305EmptyAssociatedData(t *testing.T) { } } -func TestXChacha20poly1305LongMessages(t *testing.T) { +func TestXChaCha20Poly1305LongMessages(t *testing.T) { dataSize := uint32(16) // Encrypts and decrypts messages of size <= 8192. for dataSize <= 1<<24 { @@ -118,7 +118,7 @@ func TestXChacha20poly1305LongMessages(t *testing.T) { aad := random.GetRandomBytes(dataSize / 3) key := random.GetRandomBytes(chacha20poly1305.KeySize) - x, err := aead.NewXChacha20poly1305Aead(key) + x, err := aead.NewXChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -137,13 +137,13 @@ func TestXChacha20poly1305LongMessages(t *testing.T) { } } -func TestXChacha20poly1305ModifyCiphertext(t *testing.T) { - for i, test := range xChacha20Poly1305Tests { +func TestXChaCha20Poly1305ModifyCiphertext(t *testing.T) { + for i, test := range xChaCha20Poly1305Tests { key, _ := hex.DecodeString(test.key) pt, _ := hex.DecodeString(test.plaintext) aad, _ := hex.DecodeString(test.aad) - x, err := aead.NewXChacha20poly1305Aead(key) + x, err := aead.NewXChaCha20Poly1305(key) if err != nil { t.Fatal(err) } @@ -176,9 +176,9 @@ func TestXChacha20poly1305ModifyCiphertext(t *testing.T) { // This is a very simple test for the randomness of the nonce. // The test simply checks that the multiple ciphertexts of the same message are distinct. -func TestXChacha20poly1305RandomNonce(t *testing.T) { +func TestXChaCha20Poly1305RandomNonce(t *testing.T) { key := random.GetRandomBytes(chacha20poly1305.KeySize) - x, err := aead.NewXChacha20poly1305Aead(key) + x, err := aead.NewXChaCha20Poly1305(key) if err != nil { t.Fatal(err) } diff --git a/go/subtle/aead/xchacha20poly1305_vectors_test.go b/go/subtle/aead/xchacha20poly1305_vectors_test.go index 2c01c6412a..863974ba59 100644 --- a/go/subtle/aead/xchacha20poly1305_vectors_test.go +++ b/go/subtle/aead/xchacha20poly1305_vectors_test.go @@ -66,7 +66,7 @@ package aead_test // return 0; // } -var xChacha20Poly1305Tests = []struct { +var xChaCha20Poly1305Tests = []struct { key, nonce, plaintext, aad, out, tag string }{ {