Debian Codegraph @

aead/aesgcm/key.go

raw symbols SCIP
1 // Copyright 2024 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 aesgcmscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/
16
17 import (
18 "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/"
19 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
20
21 internalaeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/ "github.com/tink-crypto/tink-go/v2/internal/aeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/"
22 "github.com/tink-crypto/tink-go/v2/internal/outputprefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/outputprefix`/"
23 "github.com/tink-crypto/tink-go/v2/keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/"
24 "github.com/tink-crypto/tink-go/v2/secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/"
25 )
26
27 // Variant is the prefix variant of AES-GCM keys.
28 //
29 // It describes how the prefix of the ciphertext is constructed. For AEAD there
30 // are three options:
31 //
32 // * TINK: prepends '0x01<big endian key id>' to the ciphertext.
33 // * CRUNCHY: prepends '0x00<big endian key id>' to the ciphertext.
34 // * NO_PREFIX: adds no prefix to the ciphertext.
35 type Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant# int
36
37 const (
38 // VariantUnknown is the default and invalid value of Variant.
39 VariantUnknownscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantUnknown. Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant# = iota
40 // VariantTink prefixes '0x01<big endian key id>' to the ciphertext.
41 VariantTinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantTink.
42 // VariantCrunchy prefixes '0x00<big endian key id>' to the ciphertext.
43 VariantCrunchyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantCrunchy.
44 // VariantNoPrefix adds no prefix to the ciphertext.
45 VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix.
46 )
47
48 func (variant Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#) Stringscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#String().() string {
49 switch variant {
50 case VariantTinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantTink.:
51 return "TINK"
52 case VariantCrunchyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantCrunchy.:
53 return "CRUNCHY"
54 case VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix.:
55 return "NO_PREFIX"
56 default:
57 return "UNKNOWN"
58 }
59 }
60
61 // calculateOutputPrefix calculates the output prefix from keyID.
62 func calculateOutputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/calculateOutputPrefix().(variant Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#, keyID uint32) ([]byte, error) {
63 switch variant {
64 case VariantTinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantTink.:
65 return outputprefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/outputprefix`/.Tinkscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/outputprefix`/Tink().(keyID), nil
66 case VariantCrunchyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantCrunchy.:
67 return outputprefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/outputprefix`/.Legacyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/outputprefix`/Legacy().(keyID), nil
68 case VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix.:
69 return nil, nil
70 default:
71 return nil, 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().("invalid output prefix variant: %v", variant)
72 }
73 }
74
75 // Parameters specifies an AES-GCM key.
76 type Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters# struct {
77 keySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#keySizeInBytes. int
78 ivSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#ivSizeInBytes. int
79 tagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#tagSizeInBytes. int
80 variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant. Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#
81 }
82
83 var _ keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters# = (*Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#)(nil)
84
85 // KeySizeInBytes returns the size of the key in bytes.
86 func (p *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#KeySizeInBytes().() int { return p.keySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#keySizeInBytes. }
87
88 // IVSizeInBytes returns the size of the IV in bytes.
89 func (p *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#IVSizeInBytes().() int { return p.ivSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#ivSizeInBytes. }
90
91 // TagSizeInBytes returns the size of the tag in bytes.
92 func (p *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#TagSizeInBytes().() int { return p.tagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#tagSizeInBytes. }
93
94 // Variant returns the variant of the key.
95 func (p *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#Variant().() Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant# { return p.variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant. }
96
97 // ParametersOpts specifies options for creating AES-GCM parameters.
98 type ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts# struct {
99 KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes. int
100 IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes. int
101 TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes. int
102 Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant. Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Variant#
103 }
104
105 func validateOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/validateOpts().(opts *ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#) error {
106 if opts.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes. != 16 && opts.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes. != 24 && opts.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes. != 32 {
107 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().("unsupported key size; want 16, 24, or 32, got: %v", opts.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes.)
108 }
109 if opts.IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes. <= 0 {
110 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().("unsupported IV size; want > 0, got: %v", opts.IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes.)
111 }
112 if opts.TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes. < 12 || opts.TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes. > 16 {
113 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().("unsupported tag size; want >= 12 and <= 16, got: %v", opts.TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes.)
114 }
115 if opts.Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant. == VariantUnknownscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantUnknown. {
116 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().("unsupported variant: %v", opts.Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant.)
117 }
118 return nil
119 }
120
121 // NewParameters creates a new AES-GCM Parameters object.
122 func NewParametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewParameters().(opts ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#) (*Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#, error) {
123 if err := validateOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/validateOpts().(&opts); err != nil {
124 return nil, 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().("aesgcm.NewParameters: %v", err)
125 }
126 return &Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#{
127 keySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#keySizeInBytes.: opts.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes.,
128 ivSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#ivSizeInBytes.: opts.IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes.,
129 tagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#tagSizeInBytes.: opts.TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes.,
130 variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant.: opts.Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant.,
131 }, nil
132 }
133
134 // HasIDRequirement returns whether the key has an ID requirement.
135 func (p *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#HasIDRequirement().() bool { return p.variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant. != VariantNoPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/VariantNoPrefix. }
136
137 // Equal returns whether this Parameters object is equal to other.
138 func (p *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#Equal().(other keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#) bool {
139 actualParams, ok := other.(*Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#)
140 return ok && p.HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#HasIDRequirement().() == actualParams.HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#HasIDRequirement().() &&
141 p.keySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#keySizeInBytes. == actualParams.keySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#keySizeInBytes. &&
142 p.ivSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#ivSizeInBytes. == actualParams.ivSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#ivSizeInBytes. &&
143 p.tagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#tagSizeInBytes. == actualParams.tagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#tagSizeInBytes. &&
144 p.variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant. == actualParams.variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#variant.
145 }
146
147 // Key represents an AES-GCM key.
148 type Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key# struct {
149 keyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#keyBytes. secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/.Bytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/Bytes#
150 // idRequirement is the ID requirement to be included in the output of the
151 // AES-GCM function. If the key is in a keyset and the key has an ID
152 // requirement, this matches the keyset key ID.
153 idRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#idRequirement. uint32
154 outputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#outputPrefix. []byte
155 parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#parameters. *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#
156 }
157
158 var _ keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Key# = (*Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#)(nil)
159
160 // NewKey creates a new AES-GCM key with key, idRequirement and parameters.
161 //
162 // The idRequirement is the ID requirement to be included in the output of the
163 // AES-GCM function. If parameters.HasIDRequirement() == false, idRequirement
164 // must be zero.
165 func NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewKey().(keyBytes secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/.Bytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/Bytes#, idRequirement uint32, parameters *Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#) (*Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#, error) {
166 if parameters == nil {
167 return nil, 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().("aesgcm.NewKey: parameters is nil")
168 }
169 opts := &ParametersOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#{
170 KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#KeySizeInBytes.: parameters.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#KeySizeInBytes().(),
171 IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#IVSizeInBytes.: parameters.IVSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#IVSizeInBytes().(),
172 TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#TagSizeInBytes.: parameters.TagSizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#TagSizeInBytes().(),
173 Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/ParametersOpts#Variant.: parameters.Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#Variant().(),
174 }
175 if err := validateOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/validateOpts().(opts); err != nil {
176 return nil, 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().("aesgcm.NewKey: %v", err)
177 }
178 if !parameters.HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#HasIDRequirement().() && idRequirement != 0 {
179 return nil, 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().("aesgcm.NewKey: idRequirement = %v and parameters.HasIDRequirement() = false, want 0", idRequirement)
180 }
181 if keyBytes.Lenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/Bytes#Len().() != int(parameters.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#KeySizeInBytes().()) {
182 return nil, 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().("aesgcm.NewKey: key.Len() = %v, want %v", keyBytes.Lenscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/Bytes#Len().(), parameters.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#KeySizeInBytes().())
183 }
184 outputPrefix, err := calculateOutputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/calculateOutputPrefix().(parameters.Variantscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#Variant().(), idRequirement)
185 if err != nil {
186 return nil, 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().("aesgcm.NewKey: %v", err)
187 }
188 return &Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#{
189 keyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#keyBytes.: keyBytes,
190 idRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#idRequirement.: idRequirement,
191 outputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#outputPrefix.: outputPrefix,
192 parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#parameters.: parameters,
193 }, nil
194 }
195
196 // KeyBytes returns the key material.
197 //
198 // This function provides access to partial key material. See
199 // https://developers.google.com/tink/design/access_control#access_of_parts_of_a_key
200 // for more information.
201 func (k *Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#) KeyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#KeyBytes().() secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/.Bytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/Bytes# { return k.keyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#keyBytes. }
202
203 // Parameters returns the parameters of this key.
204 func (k *Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#) Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#Parameters().() keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters# { return k.parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#parameters. }
205
206 // IDRequirement returns required to indicate if this key requires an
207 // identifier. If it does, id will contain that identifier.
208 func (k *Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#) IDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#IDRequirement().() (uint32, bool) {
209 return k.idRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#idRequirement., k.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#Parameters().().HasIDRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#HasIDRequirement.()
210 }
211
212 // OutputPrefix returns the output prefix.
213 func (k *Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#) OutputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#OutputPrefix().() []byte { return bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Clonescip-go gomod github.com/golang/go/src go1.24.0 bytes/Clone().(k.outputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#outputPrefix.) }
214
215 // Equal returns whether this key object is equal to other.
216 func (k *Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#) Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#Equal().(other keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Key#) bool {
217 that, ok := other.(*Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#)
218 return ok && k.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#Parameters().().Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#Equal.(that.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#Parameters().()) &&
219 k.idRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#idRequirement. == that.idRequirementscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#idRequirement. &&
220 k.keyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#keyBytes..Equalscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/Bytes#Equal().(that.keyBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#keyBytes.) &&
221 bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.24.0 bytes/Equal().(k.outputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#outputPrefix., that.outputPrefixscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Key#outputPrefix.)
222 }
223
224 func createKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/createKey().(p keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Parameters#, idRequirement uint32) (keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/.Keyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/key`/Key#, error) {
225 aesGCMParams, ok := p.(*Parametersscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#)
226 if !ok {
227 return nil, 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().("key is of type %T; needed *aesgcm.Parameters", p)
228 }
229
230 // Make sure AES key size is either 16 or 32 bytes for consistency with other Tink
231 // implementations.
232 if err := internalaeadscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/.ValidateAESKeySizescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/internal/aead`/ValidateAESKeySize().(uint32(aesGCMParams.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#KeySizeInBytes().())); err != nil {
233 return nil, err
234 }
235
236 keyBytes, err := secretdatascip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/.NewBytesFromRandscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/secretdata`/NewBytesFromRand().(uint32(aesGCMParams.KeySizeInBytesscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/Parameters#KeySizeInBytes().()))
237 if err != nil {
238 return nil, err
239 }
240 return NewKeyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/aead/aesgcm`/NewKey().(keyBytes, idRequirement, aesGCMParams)
241 }