File: skein_mixin.hpp

package info (click to toggle)
salmon 1.10.2%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 35,580 kB
  • sloc: cpp: 199,285; ansic: 171,082; sh: 859; python: 792; makefile: 235
file content (113 lines) | stat: -rw-r--r-- 2,961 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
This code is written by kerukuro and released into public domain.
*/

#ifndef DIGESTPP_MIXINS_SKEIN_HPP
#define DIGESTPP_MIXINS_SKEIN_HPP

namespace digestpp
{

namespace mixin
{

/**
 * \brief Defines additional public functions for Skein family of algorithms.
 * \sa hasher, skein256, skein512, skein1024, skein256_xof, skein512_xof, skein1024_xof
 */
template<typename T>
class skein_mixin
{
public:
	/**
	 * \brief Set personalization from std::string
	 *
	 * \param[in] personalization Personalization string
	 * \return Reference to hasher
	 */
	inline hasher<T, mixin::skein_mixin>& set_personalization(const std::string& personalization)
	{
		auto& skein = static_cast<hasher<T, mixin::skein_mixin>&>(*this);
		skein.provider.set_personalization(personalization);
		skein.provider.init();
		return skein;
	}

	/**
	 * \brief Set personalization from raw buffer
	 *
	 * \param[in] personalization Pointer to personalization bytes
	 * \param[in] personalization_len Personalization length (in bytes)
	 * \return Reference to hasher
	 */
	template<typename C, typename std::enable_if<detail::is_byte<C>::value>::type* = nullptr>
	inline hasher<T, mixin::skein_mixin>& set_personalization(const C* personalization, size_t personalization_len)
	{
		return set_personalization(std::string(reinterpret_cast<const char*>(personalization), personalization_len));
	}

	/**
	 * \brief Set key from std::string
	 *
	 * \param[in] key Key string
	 * \return Reference to hasher
	 */
	inline hasher<T, mixin::skein_mixin>& set_key(const std::string& key)
	{
		auto& skein = static_cast<hasher<T, mixin::skein_mixin>&>(*this);
		skein.provider.set_key(key);
		skein.provider.init();
		return skein;
	}

	/**
	 * \brief Set key from raw buffer
	 *
	 * \param[in] key Pointer to key bytes
	 * \param[in] key_len Key length (in bytes)
	 * \return Reference to hasher
	 */
	template<typename C, typename std::enable_if<detail::is_byte<C>::value>::type* = nullptr>
	inline hasher<T, mixin::skein_mixin>& set_key(const C* key, size_t key_len)
	{
		return set_key(std::string(reinterpret_cast<const char*>(key), key_len));
	}

	/**
	 * \brief Set nonce from std::string
	 *
	 * \param[in] nonce Nonce string
	 * \return Reference to hasher
	 */
	inline hasher<T, mixin::skein_mixin>& set_nonce(const std::string& nonce)
	{
		auto& skein = static_cast<hasher<T, mixin::skein_mixin>&>(*this);
		skein.provider.set_nonce(nonce);
		skein.provider.init();
		return skein;
	}

	/**
	 * \brief Set nonce from raw buffer
	 *
	 * \param[in] nonce Pointer to nonce bytes
	 * \param[in] nonce_len Nonce length (in bytes)
	 * \return Reference to hasher
	 */
	template<typename C, typename std::enable_if<detail::is_byte<C>::value>::type* = nullptr>
	inline hasher<T, mixin::skein_mixin>& set_nonce(const C* nonce, size_t nonce_len)
	{
		return set_nonce(std::string(reinterpret_cast<const char*>(nonce), nonce_len));
	}
};

} // namespace mixin

} // namespace digestpp

#endif