Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-tink
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-tink
Commits
b4142f9a
Commit
b4142f9a
authored
5 years ago
by
Tink Team
Committed by
Copybara-Service
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add AES-256-GCM key template with RAW output prefix.
PiperOrigin-RevId: 270099454
parent
5e64d1cd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
go/aead/aead_key_templates.go
+15
-5
15 additions, 5 deletions
go/aead/aead_key_templates.go
go/aead/aead_key_templates_test.go
+15
-3
15 additions, 3 deletions
go/aead/aead_key_templates_test.go
with
30 additions
and
8 deletions
go/aead/aead_key_templates.go
+
15
−
5
View file @
b4142f9a
...
...
@@ -30,14 +30,23 @@ import (
// AES128GCMKeyTemplate is a KeyTemplate that generates an AES-GCM key with the following parameters:
// - Key size: 16 bytes
// - Output prefix type: TINK
func
AES128GCMKeyTemplate
()
*
tinkpb
.
KeyTemplate
{
return
createAESGCMKeyTemplate
(
16
)
return
createAESGCMKeyTemplate
(
16
,
tinkpb
.
OutputPrefixType_TINK
)
}
// AES256GCMKeyTemplate is a KeyTemplate that generates an AES-GCM key with the following parameters:
// - Key size: 32 bytes
// - Output prefix type: TINK
func
AES256GCMKeyTemplate
()
*
tinkpb
.
KeyTemplate
{
return
createAESGCMKeyTemplate
(
32
)
return
createAESGCMKeyTemplate
(
32
,
tinkpb
.
OutputPrefixType_TINK
)
}
// AES256GCMNoPrefixKeyTemplate is a KeyTemplate that generates an AES-GCM key with the following parameters:
// - Key size: 32 bytes
// - Output prefix type: RAW
func
AES256GCMNoPrefixKeyTemplate
()
*
tinkpb
.
KeyTemplate
{
return
createAESGCMKeyTemplate
(
32
,
tinkpb
.
OutputPrefixType_RAW
)
}
// AES128CTRHMACSHA256KeyTemplate is a KeyTemplate that generates an AES-CTR-HMAC-AEAD key with the following parameters:
...
...
@@ -94,14 +103,15 @@ func KMSEnvelopeAEADKeyTemplate(uri string, dekT *tinkpb.KeyTemplate) *tinkpb.Ke
// createAESGCMKeyTemplate creates a new AES-GCM key template with the given key
// size in bytes.
func
createAESGCMKeyTemplate
(
keySize
uint32
)
*
tinkpb
.
KeyTemplate
{
func
createAESGCMKeyTemplate
(
keySize
uint32
,
outputPrefixType
tinkpb
.
OutputPrefixType
)
*
tinkpb
.
KeyTemplate
{
format
:=
&
gcmpb
.
AesGcmKeyFormat
{
KeySize
:
keySize
,
}
serializedFormat
,
_
:=
proto
.
Marshal
(
format
)
return
&
tinkpb
.
KeyTemplate
{
TypeUrl
:
aesGCMTypeURL
,
Value
:
serializedFormat
,
TypeUrl
:
aesGCMTypeURL
,
Value
:
serializedFormat
,
OutputPrefixType
:
outputPrefixType
,
}
}
...
...
This diff is collapsed.
Click to expand it.
go/aead/aead_key_templates_test.go
+
15
−
3
View file @
b4142f9a
...
...
@@ -34,7 +34,7 @@ import (
func
TestAESGCMKeyTemplates
(
t
*
testing
.
T
)
{
// AES-GCM 128 bit
template
:=
aead
.
AES128GCMKeyTemplate
()
if
err
:=
checkAESGCMKeyTemplate
(
template
,
uint32
(
16
));
err
!=
nil
{
if
err
:=
checkAESGCMKeyTemplate
(
template
,
uint32
(
16
)
,
tinkpb
.
OutputPrefixType_TINK
);
err
!=
nil
{
t
.
Errorf
(
"invalid AES-128 GCM key template: %s"
,
err
)
}
if
err
:=
testEncryptDecrypt
(
template
,
testutil
.
AESGCMTypeURL
);
err
!=
nil
{
...
...
@@ -43,18 +43,30 @@ func TestAESGCMKeyTemplates(t *testing.T) {
// AES-GCM 256 bit
template
=
aead
.
AES256GCMKeyTemplate
()
if
err
:=
checkAESGCMKeyTemplate
(
template
,
uint32
(
32
));
err
!=
nil
{
if
err
:=
checkAESGCMKeyTemplate
(
template
,
uint32
(
32
)
,
tinkpb
.
OutputPrefixType_TINK
);
err
!=
nil
{
t
.
Errorf
(
"invalid AES-256 GCM key template: %s"
,
err
)
}
if
err
:=
testEncryptDecrypt
(
template
,
testutil
.
AESGCMTypeURL
);
err
!=
nil
{
t
.
Errorf
(
"%v"
,
err
)
}
// AES-GCM 256 bit No Prefix
template
=
aead
.
AES256GCMNoPrefixKeyTemplate
()
if
err
:=
checkAESGCMKeyTemplate
(
template
,
uint32
(
32
),
tinkpb
.
OutputPrefixType_RAW
);
err
!=
nil
{
t
.
Errorf
(
"invalid AES-256 GCM No Prefix key template: %s"
,
err
)
}
if
err
:=
testEncryptDecrypt
(
template
,
testutil
.
AESGCMTypeURL
);
err
!=
nil
{
t
.
Errorf
(
"%v"
,
err
)
}
}
func
checkAESGCMKeyTemplate
(
template
*
tinkpb
.
KeyTemplate
,
keySize
uint32
)
error
{
func
checkAESGCMKeyTemplate
(
template
*
tinkpb
.
KeyTemplate
,
keySize
uint32
,
outputPrefixType
tinkpb
.
OutputPrefixType
)
error
{
if
template
.
TypeUrl
!=
testutil
.
AESGCMTypeURL
{
return
fmt
.
Errorf
(
"incorrect type url"
)
}
if
template
.
OutputPrefixType
!=
outputPrefixType
{
return
fmt
.
Errorf
(
"incorrect output prefix type"
)
}
keyFormat
:=
new
(
gcmpb
.
AesGcmKeyFormat
)
err
:=
proto
.
Unmarshal
(
template
.
Value
,
keyFormat
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment