| 1 | // Copyright 2022 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 | ) |
| 20 | |
| 21 | const ( |
| 22 | // AESGCMIVSize is the acceptable IV size defined by RFC 5116. |
| 23 | AESGCMIVSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/AESGCMIVSize. = 12 |
| 24 | // AESGCMTagSize is the acceptable tag size defined by RFC 5116. |
| 25 | AESGCMTagSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/AESGCMTagSize. = 16 |
| 26 | |
| 27 | // aesGCMMaxPlaintextSize is the maximum plaintext size defined by RFC 5116. |
| 28 | aesGCMMaxPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/aesGCMMaxPlaintextSize. = (1 << 36) - 31 |
| 29 | |
| 30 | intSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/intSize. = 32 << (^uint(0) >> 63) // 32 or 64 |
| 31 | maxIntscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/maxInt. = 1<<(intSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/intSize.-1) - 1 |
| 32 | maxIntPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/maxIntPlaintextSize. = maxIntscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/maxInt. - AESGCMIVSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/AESGCMIVSize. - AESGCMTagSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/AESGCMTagSize. |
| 33 | ) |
| 34 | |
| 35 | // CheckAESGCMPlaintextSize checks if the given plaintext size is valid for AES-GCM. |
| 36 | func CheckAESGCMPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/CheckAESGCMPlaintextSize().(size uint64) error { |
| 37 | var maxPlaintextSize uint64 = maxIntPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/maxIntPlaintextSize. |
| 38 | if maxIntPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/maxIntPlaintextSize. > aesGCMMaxPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/aesGCMMaxPlaintextSize. { |
| 39 | maxPlaintextSize = aesGCMMaxPlaintextSizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/aesGCMMaxPlaintextSize. |
| 40 | } |
| 41 | if size > maxPlaintextSize { |
| 42 | 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", size) |
| 43 | } |
| 44 | return nil |
| 45 | } |