Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit e3c2c75

Browse files
committed
Cipher state accumulator updated. Build configuration updated #3
1 parent 45c7769 commit e3c2c75

File tree

7 files changed

+102
-102
lines changed

7 files changed

+102
-102
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if(NOT ${CMAKE_WORKSPACE_NAME} STREQUAL crypto3)
1111
cm_workspace(crypto3)
1212
endif()
1313

14-
cm_project(block WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME})
14+
cm_project(block WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES C CXX)
1515

1616
if(NOT Boost_CONTAINER_FOUND OR NOT Boost_FOUND)
1717
cm_find_package(Boost COMPONENTS container)
@@ -443,7 +443,7 @@ list(APPEND ${CURRENT_PROJECT_NAME}_SOURCES
443443
${${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES}
444444
)
445445

446-
cm_setup_version(VERSION 0.3.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})
446+
cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})
447447

448448
add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
449449
${${CURRENT_PROJECT_NAME}_HEADERS} ${${CURRENT_PROJECT_NAME}_SOURCES})

include/nil/crypto3/block/algorithm/decrypt.hpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace nil {
4444
typedef typename BlockCipher::stream_decrypter_type EncryptionMode;
4545
typedef typename block::block_accumulator<EncryptionMode> CipherAccumulator;
4646

47-
typedef block::detail::value_cipher_impl <CipherAccumulator> StreamEncrypterImpl;
48-
typedef block::detail::itr_cipher_impl <StreamEncrypterImpl, OutputIterator> EncrypterImpl;
47+
typedef block::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
48+
typedef block::detail::itr_cipher_impl<StreamEncrypterImpl, OutputIterator> EncrypterImpl;
4949

5050
return EncrypterImpl(first, last, std::move(out), CiperState(BlockCipher(key_first, key_last)));
5151
}
@@ -70,13 +70,13 @@ namespace nil {
7070
typename InputIterator,
7171
typename OutputAccumulator = typename block::block_accumulator<
7272
typename BlockCipher::stream_decrypter_type>>
73-
OutputAccumulator &decrypt(InputIterator first, InputIterator last, typename OutputAccumulator::type &acc) {
73+
OutputAccumulator &decrypt(InputIterator first, InputIterator last, OutputAccumulator &acc) {
7474

7575
typedef typename BlockCipher::stream_decrypter_type EncryptionMode;
7676
typedef typename block::block_accumulator<EncryptionMode> CipherAccumulator;
7777

78-
typedef block::detail::ref_cipher_impl <CipherAccumulator> StreamEncrypterImpl;
79-
typedef block::detail::range_cipher_impl <StreamEncrypterImpl> EncrypterImpl;
78+
typedef block::detail::ref_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
79+
typedef block::detail::range_cipher_impl<StreamEncrypterImpl> EncrypterImpl;
8080

8181
return EncrypterImpl(first, last, acc);
8282
}
@@ -99,13 +99,13 @@ namespace nil {
9999
typename SinglePassRange,
100100
typename OutputAccumulator = typename block::block_accumulator<
101101
typename BlockCipher::stream_decrypter_type>>
102-
OutputAccumulator &decrypt(const SinglePassRange &r, typename OutputAccumulator::type &acc) {
102+
OutputAccumulator &decrypt(const SinglePassRange &r, OutputAccumulator &acc) {
103103

104104
typedef typename BlockCipher::stream_decrypter_type EncryptionMode;
105105
typedef typename block::block_accumulator<EncryptionMode> CipherAccumulator;
106106

107-
typedef block::detail::ref_cipher_impl <CipherAccumulator> StreamEncrypterImpl;
108-
typedef block::detail::range_cipher_impl <StreamEncrypterImpl> EncrypterImpl;
107+
typedef block::detail::ref_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
108+
typedef block::detail::range_cipher_impl<StreamEncrypterImpl> EncrypterImpl;
109109

110110
return EncrypterImpl(r, acc);
111111
}
@@ -129,8 +129,9 @@ namespace nil {
129129
typename BlockCipher::stream_decrypter_type>>
130130
block::detail::range_cipher_impl <block::detail::value_cipher_impl<CipherAccumulator>> decrypt(
131131
InputIterator first, InputIterator last, KeyIterator key_first, KeyIterator key_last) {
132-
typedef block::detail::value_cipher_impl <CipherAccumulator> StreamEncrypterImpl;
133-
typedef block::detail::range_cipher_impl <StreamEncrypterImpl> EncrypterImpl;
132+
133+
typedef block::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
134+
typedef block::detail::range_cipher_impl<StreamEncrypterImpl> EncrypterImpl;
134135

135136
return EncrypterImpl(first, last, CipherAccumulator(BlockCipher(key_first, key_last)));
136137
}
@@ -154,8 +155,8 @@ namespace nil {
154155
typedef typename BlockCipher::stream_decrypter_type EncryptionMode;
155156
typedef typename block::block_accumulator<EncryptionMode> CipherAccumulator;
156157

157-
typedef block::detail::value_cipher_impl <CipherAccumulator> StreamEncrypterImpl;
158-
typedef block::detail::itr_cipher_impl <StreamEncrypterImpl, OutputIterator> EncrypterImpl;
158+
typedef block::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
159+
typedef block::detail::itr_cipher_impl<StreamEncrypterImpl, OutputIterator> EncrypterImpl;
159160

160161
return EncrypterImpl(rng, std::move(out), CipherState(BlockCipher(key)));
161162
}
@@ -179,8 +180,8 @@ namespace nil {
179180
block::detail::range_cipher_impl <block::detail::value_cipher_impl<CipherAccumulator>> decrypt(
180181
const SinglePassRange &r, const KeyRange &key) {
181182

182-
typedef block::detail::value_cipher_impl <CipherAccumulator> StreamEncrypterImpl;
183-
typedef block::detail::range_cipher_impl <StreamEncrypterImpl> EncrypterImpl;
183+
typedef block::detail::value_cipher_impl<CipherAccumulator> StreamEncrypterImpl;
184+
typedef block::detail::range_cipher_impl<StreamEncrypterImpl> EncrypterImpl;
184185

185186
return EncrypterImpl(r, CipherState(BlockCipher(key)));
186187
}

include/nil/crypto3/block/algorithm/encrypt.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace nil {
7070
typename InputIterator,
7171
typename OutputAccumulator = typename block::block_accumulator<
7272
typename BlockCipher::stream_encrypter_type>>
73-
OutputAccumulator &encrypt(InputIterator first, InputIterator last, typename OutputAccumulator::type &acc) {
73+
OutputAccumulator &encrypt(InputIterator first, InputIterator last, OutputAccumulator &acc) {
7474

7575
typedef typename BlockCipher::stream_encrypter_type EncryptionMode;
7676
typedef typename block::block_accumulator<EncryptionMode> CipherAccumulator;
@@ -99,7 +99,7 @@ namespace nil {
9999
typename SinglePassRange,
100100
typename OutputAccumulator = typename block::block_accumulator<
101101
typename BlockCipher::stream_encrypter_type>>
102-
OutputAccumulator &encrypt(const SinglePassRange &r, typename OutputAccumulator::type &acc) {
102+
OutputAccumulator &encrypt(const SinglePassRange &r, OutputAccumulator &acc) {
103103

104104
typedef typename BlockCipher::stream_encrypter_type EncryptionMode;
105105
typedef typename block::block_accumulator<EncryptionMode> CipherAccumulator;

include/nil/crypto3/block/cipher_state.hpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@ namespace nil {
2727
* @tparam ValueBits
2828
* @tparam LengthBits
2929
*/
30-
template<typename ProcessingMode>
31-
struct block_accumulator {
32-
typedef boost::accumulators::accumulator_set<block::digest<ProcessingMode::input_block_bits>,
33-
boost::accumulators::features<
34-
accumulators::tag::block<ProcessingMode>>> type;
35-
36-
typedef ProcessingMode mode_type;
37-
};
30+
template<typename ProcessingMode> using block_accumulator = boost::accumulators::accumulator_set<
31+
block::digest<ProcessingMode::input_block_bits>,
32+
boost::accumulators::features<accumulators::tag::block<ProcessingMode>>>;
3833
}
3934
}
4035
}

include/nil/crypto3/block/cipher_value.hpp

+47-43
Original file line numberDiff line numberDiff line change
@@ -26,58 +26,60 @@ namespace nil {
2626
namespace crypto3 {
2727
namespace block {
2828
namespace detail {
29-
template<typename CodecAccumulator>
29+
template<typename CipherAccumulator>
3030
struct ref_cipher_impl {
31-
typedef CodecAccumulator cipher_accumulator_type;
32-
typedef typename cipher_accumulator_type::type cipher_accumulator_set;
31+
typedef CipherAccumulator accumulator_set_type;
32+
typedef typename boost::mpl::front<
33+
typename accumulator_set_type::features_type>::type accumulator_type;
3334

34-
typedef typename CodecAccumulator::mode_type mode_type;
35+
typedef typename CipherAccumulator::mode_type mode_type;
3536
typedef typename mode_type::encoder_type cipher_type;
3637

37-
ref_cipher_impl(const cipher_accumulator_set &acc) : accumulator_set(acc) {
38+
ref_cipher_impl(const accumulator_set_type &acc) : accumulator_set(acc) {
3839

3940
}
4041

41-
cipher_accumulator_set &accumulator_set;
42+
accumulator_set_type &accumulator_set;
4243
};
4344

44-
template<typename CodecAccumulator>
45+
template<typename CipherAccumulator>
4546
struct value_cipher_impl {
46-
typedef CodecAccumulator cipher_accumulator_type;
47-
typedef typename cipher_accumulator_type::type cipher_accumulator_set;
47+
typedef CipherAccumulator accumulator_set_type;
48+
typedef typename boost::mpl::front<
49+
typename accumulator_set_type::features_type>::type accumulator_type;
4850

49-
typedef typename CodecAccumulator::mode_type mode_type;
51+
typedef typename CipherAccumulator::mode_type mode_type;
5052
typedef typename mode_type::encoder_type cipher_type;
5153

52-
value_cipher_impl(const cipher_accumulator_set &acc) : accumulator_set(acc) {
54+
value_cipher_impl(const accumulator_set_type &acc) : accumulator_set(acc) {
5355

5456
}
5557

56-
mutable cipher_accumulator_set accumulator_set;
58+
mutable accumulator_set_type accumulator_set;
5759
};
5860

59-
template<typename CodecStateImpl>
60-
struct range_cipher_impl : public CodecStateImpl {
61-
typedef CodecStateImpl cipher_state_impl_type;
61+
template<typename CipherStateImpl>
62+
struct range_cipher_impl : public CipherStateImpl {
63+
typedef CipherStateImpl cipher_state_impl_type;
6264

63-
typedef typename cipher_state_impl_type::cipher_accumulator_type cipher_accumulator_type;
64-
typedef typename cipher_accumulator_type::type cipher_accumulator_set;
65+
typedef typename cipher_state_impl_type::accumulator_type accumulator_type;
66+
typedef typename cipher_state_impl_type::accumulator_set_type accumulator_set_type;
6567

6668
typedef typename cipher_state_impl_type::mode_type mode_type;
6769
typedef typename cipher_state_impl_type::cipher_type cipher_type;
6870

69-
typedef typename boost::mpl::apply<cipher_accumulator_set, accumulators::tag::block<
70-
mode_type> >::type::result_type result_type;
71+
typedef typename boost::mpl::apply<accumulator_set_type,
72+
accumulator_type>::type::result_type result_type;
7173

7274
template<typename SinglePassRange>
73-
range_cipher_impl(const SinglePassRange &range, const cipher_accumulator_set &ise)
74-
: CodecStateImpl(ise) {
75+
range_cipher_impl(const SinglePassRange &range, const accumulator_set_type &ise)
76+
: CipherStateImpl(ise) {
7577
BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const SinglePassRange>));
7678

7779
typedef typename std::iterator_traits<
7880
typename SinglePassRange::iterator>::value_type value_type;
7981
BOOST_STATIC_ASSERT(std::numeric_limits<value_type>::is_specialized);
80-
typedef typename cipher_type::template stream_processor<mode_type, cipher_accumulator_set,
82+
typedef typename cipher_type::template stream_processor<mode_type, accumulator_set_type,
8183
std::numeric_limits<
8284
value_type>::digits +
8385
std::numeric_limits<
@@ -88,13 +90,13 @@ namespace nil {
8890
}
8991

9092
template<typename InputIterator>
91-
range_cipher_impl(InputIterator first, InputIterator last, const cipher_accumulator_set &ise)
92-
: CodecStateImpl(ise) {
93+
range_cipher_impl(InputIterator first, InputIterator last, const accumulator_set_type &ise)
94+
: CipherStateImpl(ise) {
9395
BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<InputIterator>));
9496

9597
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
9698
BOOST_STATIC_ASSERT(std::numeric_limits<value_type>::is_specialized);
97-
typedef typename cipher_type::template stream_processor<mode_type, cipher_accumulator_set,
99+
typedef typename cipher_type::template stream_processor<mode_type, accumulator_set_type,
98100
std::numeric_limits<
99101
value_type>::digits +
100102
std::numeric_limits<
@@ -105,54 +107,55 @@ namespace nil {
105107

106108
template<typename OutputRange>
107109
operator OutputRange() const {
108-
result_type result = accumulators::extract::block<mode_type>(this->accumulator_set);
110+
result_type result = boost::accumulators::extract_result<accumulator_type>(
111+
this->accumulator_set);
109112
return OutputRange(result.cbegin(), result.cend());
110113
}
111114

112115
operator result_type() const {
113-
return accumulators::extract::block<mode_type>(this->accumulator_set);
116+
return boost::accumulators::extract_result<accumulator_type>(this->accumulator_set);
114117
}
115118

116-
operator cipher_accumulator_set() const {
119+
operator accumulator_set_type() const {
117120
return this->accumulator_set;
118121
}
119122

120123
#ifdef CRYPTO3_ASCII_STRING_CODEC_OUTPUT
121124

122125
template<typename Char, typename CharTraits, typename Alloc>
123126
operator std::basic_string<Char, CharTraits, Alloc>() const {
124-
return std::to_string(accumulators::extract::cipher<mode_type>(this->accumulator_set));
127+
return std::to_string(boost::accumulators::extract_result<accumulator_type>(this->accumulator_set));
125128
}
126129

127130
#endif
128131
};
129132

130-
template<typename CodecStateImpl, typename OutputIterator>
131-
struct itr_cipher_impl : public CodecStateImpl {
133+
template<typename CipherStateImpl, typename OutputIterator>
134+
struct itr_cipher_impl : public CipherStateImpl {
132135
private:
133136
mutable OutputIterator out;
134137

135138
public:
136-
typedef CodecStateImpl cipher_state_impl_type;
139+
typedef CipherStateImpl cipher_state_impl_type;
137140

138-
typedef typename cipher_state_impl_type::cipher_accumulator_type cipher_accumulator_type;
139-
typedef typename cipher_accumulator_type::type cipher_accumulator_set;
141+
typedef typename cipher_state_impl_type::accumulator_type accumulator_type;
142+
typedef typename cipher_state_impl_type::accumulator_set_type accumulator_set_type;
140143

141144
typedef typename cipher_state_impl_type::mode_type mode_type;
142145
typedef typename cipher_state_impl_type::cipher_type cipher_type;
143146

144-
typedef typename boost::mpl::apply<cipher_accumulator_set, accumulators::tag::block<
145-
mode_type> >::type::result_type result_type;
147+
typedef typename boost::mpl::apply<accumulator_set_type,
148+
accumulator_type>::type::result_type result_type;
146149

147150
template<typename SinglePassRange>
148-
itr_cipher_impl(const SinglePassRange &range, OutputIterator out, const cipher_accumulator_set &ise)
149-
: CodecStateImpl(ise), out(std::move(out)) {
151+
itr_cipher_impl(const SinglePassRange &range, OutputIterator out, const accumulator_set_type &ise)
152+
: CipherStateImpl(ise), out(std::move(out)) {
150153
BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const SinglePassRange>));
151154

152155
typedef typename std::iterator_traits<
153156
typename SinglePassRange::iterator>::value_type value_type;
154157
BOOST_STATIC_ASSERT(std::numeric_limits<value_type>::is_specialized);
155-
typedef typename cipher_type::template stream_processor<mode_type, cipher_accumulator_set,
158+
typedef typename cipher_type::template stream_processor<mode_type, accumulator_set_type,
156159
std::numeric_limits<
157160
value_type>::digits +
158161
std::numeric_limits<
@@ -164,13 +167,13 @@ namespace nil {
164167

165168
template<typename InputIterator>
166169
itr_cipher_impl(InputIterator first, InputIterator last, OutputIterator out,
167-
const cipher_accumulator_set &ise)
168-
: CodecStateImpl(ise), out(std::move(out)) {
170+
const accumulator_set_type &ise)
171+
: CipherStateImpl(ise), out(std::move(out)) {
169172
BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<InputIterator>));
170173

171174
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
172175
BOOST_STATIC_ASSERT(std::numeric_limits<value_type>::is_specialized);
173-
typedef typename cipher_type::template stream_processor<mode_type, cipher_accumulator_set,
176+
typedef typename cipher_type::template stream_processor<mode_type, accumulator_set_type,
174177
std::numeric_limits<
175178
value_type>::digits +
176179
std::numeric_limits<
@@ -181,7 +184,8 @@ namespace nil {
181184
}
182185

183186
operator OutputIterator() const {
184-
result_type result = accumulators::extract::block<mode_type>(this->accumulator_set);
187+
result_type result = boost::accumulators::extract_result<accumulator_type>(
188+
this->accumulator_set);
185189

186190
return std::move(result.cbegin(), result.cend(), out);
187191
}

test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(TESTS_NAMES
3737
"blowfish"
3838
"camellia"
3939
"cast"
40-
# "des"
40+
"des"
4141
"gost28147"
4242
"idea"
4343
"kasumi"

0 commit comments

Comments
 (0)