hash/blake: prefer std types
This commit is contained in:
parent
103ede647b
commit
cfc728a3a7
@ -147,17 +147,10 @@ G (int i,
|
||||
const auto j = permute[r][2 * i ];
|
||||
const auto k = permute[r][2 * i + 1];
|
||||
|
||||
a = a + b + (m[j] ^ traits<width>::pi[k]);
|
||||
d = cruft::rotater (d ^ a, traits<width>::rotations[0]);
|
||||
|
||||
c = c + d;
|
||||
b = cruft::rotater (b ^ c, traits<width>::rotations[1]);
|
||||
|
||||
a = a + b + (m[k] ^ traits<width>::pi[j]);
|
||||
d = cruft::rotater (d ^ a, traits<width>::rotations[2]);
|
||||
|
||||
c = c + d;
|
||||
b = cruft::rotater (b ^ c, traits<width>::rotations[3]);
|
||||
a = a + b + (m[j] ^ traits<width>::pi[k]); d = cruft::rotater (d ^ a, traits<width>::rotations[0]);
|
||||
c = c + d; b = cruft::rotater (b ^ c, traits<width>::rotations[1]);
|
||||
a = a + b + (m[k] ^ traits<width>::pi[j]); d = cruft::rotater (d ^ a, traits<width>::rotations[2]);
|
||||
c = c + d; b = cruft::rotater (b ^ c, traits<width>::rotations[3]);
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +162,7 @@ compress (
|
||||
std::array<typename traits<width>::word_t,8> h,
|
||||
const typename traits<width>::word_t m[16],
|
||||
const std::array<typename traits<width>::word_t,4> s,
|
||||
uint64_t t
|
||||
u64 t
|
||||
) {
|
||||
typename traits<width>::word_t t0 = t & 0xffffffff;
|
||||
typename traits<width>::word_t t1 = (t >> 32u) & 0xffffffff;
|
||||
@ -212,8 +205,8 @@ compress (
|
||||
template <int width>
|
||||
typename blake<width>::digest_t
|
||||
blake<width>::operator() (
|
||||
cruft::view<const uint8_t*> data,
|
||||
cruft::view<const uint8_t*> salt
|
||||
cruft::view<const u08*> data,
|
||||
cruft::view<const u08*> salt
|
||||
) const {
|
||||
std::array<typename traits<width>::word_t, 4> fwd {};
|
||||
|
||||
@ -228,7 +221,7 @@ blake<width>::operator() (
|
||||
template <int width>
|
||||
typename blake<width>::digest_t
|
||||
blake<width>::operator() (
|
||||
cruft::view<const uint8_t *> data,
|
||||
cruft::view<const u08 *> data,
|
||||
const std::array<typename traits<width>::word_t, 4> salt
|
||||
) const noexcept {
|
||||
auto h = traits<width>::iv;
|
||||
@ -241,10 +234,10 @@ blake<width>::operator() (
|
||||
// more than simple calls to hton would allow.
|
||||
union {
|
||||
word_t dw[16];
|
||||
uint8_t d08[16*sizeof(word_t)];
|
||||
u08 d08[16*sizeof(word_t)];
|
||||
};
|
||||
|
||||
uint64_t t = 0;
|
||||
u64 t = 0;
|
||||
auto cursor = data.cbegin ();
|
||||
|
||||
// perform the simple case where we're consuming whole blocks
|
||||
@ -327,7 +320,6 @@ blake<width>::operator() (
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template class cruft::crypto::hash::blake<256>;
|
||||
template class cruft::crypto::hash::blake<512>;
|
||||
|
@ -3,12 +3,12 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2018-2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_CRYPTO_HASH_BLAKE_HPP
|
||||
#define CRUFT_CRYPTO_HASH_BLAKE_HPP
|
||||
#pragma once
|
||||
|
||||
#include <cruft/util/std.hpp>
|
||||
#include <cruft/util/view.hpp>
|
||||
|
||||
#include <array>
|
||||
@ -29,7 +29,7 @@ namespace cruft::crypto::hash {
|
||||
template <>
|
||||
struct traits<256>
|
||||
{
|
||||
using word_t = uint32_t;
|
||||
using word_t = u32;
|
||||
|
||||
static const std::array<word_t,8> iv;
|
||||
static const std::array<word_t,16> pi;
|
||||
@ -50,7 +50,7 @@ namespace cruft::crypto::hash {
|
||||
template <>
|
||||
struct traits<512>
|
||||
{
|
||||
using word_t = uint64_t;
|
||||
using word_t = u64;
|
||||
|
||||
static const std::array<word_t,8> iv;
|
||||
static const std::array<word_t,16> pi;
|
||||
@ -83,22 +83,20 @@ namespace cruft::crypto::hash {
|
||||
|
||||
// size of the digest in bytes
|
||||
static const size_t digest_size = width / 8;
|
||||
using digest_t = std::array<uint8_t,digest_size>;
|
||||
using digest_t = std::array<u08,digest_size>;
|
||||
|
||||
|
||||
digest_t operator() (
|
||||
cruft::view<const uint8_t*> data,
|
||||
cruft::view<const uint8_t*> salt
|
||||
cruft::view<const u08*> data,
|
||||
cruft::view<const u08*> salt
|
||||
) const;
|
||||
|
||||
digest_t operator() (cruft::view<const uint8_t*> data,
|
||||
digest_t operator() (cruft::view<const u08*> data,
|
||||
const std::array<word_t,4> salt) const noexcept;
|
||||
|
||||
digest_t operator() (cruft::view<const uint8_t*> data) const noexcept
|
||||
digest_t operator() (cruft::view<const u08*> data) const noexcept
|
||||
{
|
||||
return (*this) (data, {0,0,0,0});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user