aboutsummaryrefslogtreecommitdiff
path: root/cc/mac/mac_key_templates.cc
diff options
context:
space:
mode:
authorBartosz Przydatek <przydatek@google.com>2018-04-09 12:08:14 -0700
committerTink Team <noreply@google.com>2018-04-12 22:13:19 -0400
commit8b6e8d4b1047a138d45363ddcb1bb54923daa19c (patch)
tree477c3eec0b660ec79f13a30655feb0c8164ccabf /cc/mac/mac_key_templates.cc
parent12d40bc998caf4e19240ea95cea4a7f25f4cb498 (diff)
downloadtink-8b6e8d4b1047a138d45363ddcb1bb54923daa19c.tar.gz
Adding KeyTemplate-classes missing in C++.
PiperOrigin-RevId: 192164449 GitOrigin-RevId: 8b8b91404d7190a1fa6a72c0cd830ac2537ca675
Diffstat (limited to 'cc/mac/mac_key_templates.cc')
-rw-r--r--cc/mac/mac_key_templates.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/cc/mac/mac_key_templates.cc b/cc/mac/mac_key_templates.cc
new file mode 100644
index 000000000..eca5fe80e
--- /dev/null
+++ b/cc/mac/mac_key_templates.cc
@@ -0,0 +1,69 @@
+// Copyright 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "tink/mac/mac_key_templates.h"
+
+#include "proto/common.pb.h"
+#include "proto/hmac.pb.h"
+#include "proto/tink.pb.h"
+
+namespace crypto {
+namespace tink {
+namespace {
+
+using google::crypto::tink::HmacKeyFormat;
+using google::crypto::tink::HashType;
+using google::crypto::tink::KeyTemplate;
+using google::crypto::tink::OutputPrefixType;
+
+KeyTemplate* NewHmacKeyTemplate(int key_size_in_bytes,
+ int tag_size_in_bytes,
+ HashType hash_type) {
+ KeyTemplate* key_template = new KeyTemplate;
+ key_template->set_type_url(
+ "type.googleapis.com/google.crypto.tink.HmacKey");
+ key_template->set_output_prefix_type(OutputPrefixType::TINK);
+ HmacKeyFormat key_format;
+ key_format.set_key_size(key_size_in_bytes);
+ key_format.mutable_params()->set_tag_size(tag_size_in_bytes);
+ key_format.mutable_params()->set_hash(hash_type);
+ key_format.SerializeToString(key_template->mutable_value());
+ return key_template;
+}
+
+
+} // anonymous namespace
+
+// static
+const KeyTemplate& MacKeyTemplates::Hmac128BittagSha256() {
+ static const KeyTemplate* key_template =
+ NewHmacKeyTemplate(/* key_size_in_bytes= */ 32,
+ /* tag_size_in_bytes= */ 16,
+ HashType::SHA256);
+ return *key_template;
+}
+
+// static
+const KeyTemplate& MacKeyTemplates::Hmac256BittagSha256() {
+ static const KeyTemplate* key_template =
+ NewHmacKeyTemplate(/* key_size_in_bytes= */ 32,
+ /* tag_size_in_bytes= */ 32,
+ HashType::SHA256);
+ return *key_template;
+}
+
+} // namespace tink
+} // namespace crypto