diff options
author | lloyd <[email protected]> | 2015-01-08 01:11:17 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-08 01:11:17 +0000 |
commit | 718d577455c2e431e32064950f2612e1381c275a (patch) | |
tree | f7fbbad052a82c9f17309f64f3de7e2cec5ad603 /src/lib/utils | |
parent | 624787ec08f215a7b0be51ceeeb211a717bf7f50 (diff) |
Add SHA-512/256
Define some new functions for copying out arrays of words and use them
across hashes.
Diffstat (limited to 'src/lib/utils')
-rw-r--r-- | src/lib/utils/loadstor.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/utils/loadstor.h b/src/lib/utils/loadstor.h index 29e00592a..1dbced60e 100644 --- a/src/lib/utils/loadstor.h +++ b/src/lib/utils/loadstor.h @@ -622,6 +622,48 @@ inline void store_be(byte out[], T x0, T x1, T x2, T x3, store_be(x7, out + (7 * sizeof(T))); } +template<typename T> +void copy_out_be(byte out[], size_t out_bytes, const T in[]) + { + while(out_bytes >= sizeof(T)) + { + store_be(in[0], out); + out += sizeof(T); + out_bytes -= sizeof(T); + in += 1; + } + + for(size_t i = 0; i != out_bytes; ++i) + out[i] = get_byte(i%8, in[0]); + } + +template<typename T, typename Alloc> +void copy_out_vec_be(byte out[], size_t out_bytes, const std::vector<T, Alloc>& in) + { + copy_out_be(out, out_bytes, &in[0]); + } + +template<typename T> +void copy_out_le(byte out[], size_t out_bytes, const T in[]) + { + while(out_bytes >= sizeof(T)) + { + store_le(in[0], out); + out += sizeof(T); + out_bytes -= sizeof(T); + in += 1; + } + + for(size_t i = 0; i != out_bytes; ++i) + out[i] = get_byte(sizeof(T) - 1 - (i % 8), in[0]); + } + +template<typename T, typename Alloc> +void copy_out_vec_le(byte out[], size_t out_bytes, const std::vector<T, Alloc>& in) + { + copy_out_le(out, out_bytes, &in[0]); + } + } #endif |