From f96c34d581361e9357bb079bb3a25b5d533da583 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 20 Jun 2016 16:50:12 +1000 Subject: [PATCH] hash/simple: add simple oneshot hash calculator --- Makefile.am | 2 ++ hash/simple.cpp | 17 +++++++++++++++++ hash/simple.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 hash/simple.cpp create mode 100644 hash/simple.hpp diff --git a/Makefile.am b/Makefile.am index f9e61f47..949ddb62 100644 --- a/Makefile.am +++ b/Makefile.am @@ -107,6 +107,8 @@ UTIL_FILES = \ guid.cpp \ guid.hpp \ hash.hpp \ + hash/simple.hpp \ + hash/simple.cpp \ hash/adler.cpp \ hash/adler.hpp \ hash/bsdsum.cpp \ diff --git a/hash/simple.cpp b/hash/simple.cpp new file mode 100644 index 00000000..20ee090a --- /dev/null +++ b/hash/simple.cpp @@ -0,0 +1,17 @@ +/* + * 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. + * + * Copyright 2016, Danny Robson + */ + +#include "./simple.hpp" diff --git a/hash/simple.hpp b/hash/simple.hpp new file mode 100644 index 00000000..5c67db78 --- /dev/null +++ b/hash/simple.hpp @@ -0,0 +1,42 @@ +/* + * 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. + * + * Copyright 2016, Danny Robson + */ + +#ifndef __UTIL_HASH_SIMPLE_HPP +#define __UTIL_HASH_SIMPLE_HPP + +#include + + +/////////////////////////////////////////////////////////////////////////////// +namespace util { namespace hash { + //template + template + typename H::digest_t + simple (const void *restrict first, const void *restrict last) noexcept + { + H h; + + h.update ( + static_cast (first), + static_cast (last) + ); + h.finish (); + + return h.digest (); + } +} } + +#endif