| 1 | // Copyright 2026 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package aeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 19 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 20 | |
| 21 | "golang.org/x/crypto/chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/" |
| 22 | ) |
| 23 | |
| 24 | // CheckChaCha20Poly1305PlaintextSize checks if the given plaintext size is |
| 25 | // valid for ChaCha20Poly1305. |
| 26 | func CheckChaCha20Poly1305PlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/CheckChaCha20Poly1305PlaintextSize().(plaintextLength int) error { |
| 27 | maxSize := mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxIntscip-go gomod github.com/golang/go/src go1.24.0 math/MaxInt. - chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/.NonceSizescip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/NonceSize. - chacha20poly1305scip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/.Overheadscip-go gomod golang.org/x/crypto v0.45.0 `golang.org/x/crypto/chacha20poly1305`/Overhead. |
| 28 | if plaintextLength > maxSize { |
| 29 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("plaintext too long: got %d, want %d", plaintextLength, maxSize) |
| 30 | } |
| 31 | return nil |
| 32 | } |