summaryrefslogtreecommitdiff
path: root/src/mongo/crypto/sha256_block.h
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2017-07-18 16:13:32 -0400
committerJason Carey <jcarey@argv.me>2017-07-25 10:48:44 -0400
commitffe9014101f7bd53ed9674b770e9371324fcdf34 (patch)
tree7f1051ee8d382d41cc56cf61ce39949b50ea8133 /src/mongo/crypto/sha256_block.h
parent4e27af1e980a5f5479fc26a3d616a5b56245261a (diff)
downloadmongo-ffe9014101f7bd53ed9674b770e9371324fcdf34.tar.gz
SERVER-30218 Add SHA256 Support
The addition of a SHA256Block will give us the flexibility to handle new workloads that aren't appropriate for SHA1. As part of this change, let's make the current code templatized so we can limit as strongly as possible the duplication of code between sha1 and sha256.
Diffstat (limited to 'src/mongo/crypto/sha256_block.h')
-rw-r--r--src/mongo/crypto/sha256_block.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/mongo/crypto/sha256_block.h b/src/mongo/crypto/sha256_block.h
new file mode 100644
index 00000000000..2e24e551dc8
--- /dev/null
+++ b/src/mongo/crypto/sha256_block.h
@@ -0,0 +1,56 @@
+/**
+ * Copyright (C) 2017 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/crypto/sha_block.h"
+
+#include "mongo/util/make_array_type.h"
+
+namespace mongo {
+
+/**
+ * A Traits type for adapting SHABlock to sha256 hashes.
+ */
+struct SHA256BlockTraits {
+ using HashType = MakeArrayType<std::uint8_t, 32, SHA256BlockTraits>;
+
+ static constexpr StringData name = "SHA256Block"_sd;
+
+ static HashType computeHash(std::initializer_list<ConstDataRange> input);
+
+ static void computeHmac(const uint8_t* key,
+ size_t keyLen,
+ const uint8_t* input,
+ size_t inputLen,
+ HashType* const output);
+};
+
+using SHA256Block = SHABlock<SHA256BlockTraits>;
+
+} // namespace mongo