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

Commit 57a538a

Browse files
author
Ilias Khairullin
committed
Threshold signature test for weighted Shamir test added. #3
1 parent 08861c0 commit 57a538a

File tree

7 files changed

+473
-212
lines changed

7 files changed

+473
-212
lines changed

include/nil/crypto3/pubkey/modes/accumulators/part_verify.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
#include <boost/accumulators/framework/depends_on.hpp>
3737
#include <boost/accumulators/framework/parameters/sample.hpp>
3838

39+
#include <nil/crypto3/pubkey/type_traits.hpp>
40+
3941
#include <nil/crypto3/pubkey/accumulators/parameters/iterator_last.hpp>
4042
#include <nil/crypto3/pubkey/accumulators/parameters/signature.hpp>
43+
#include <nil/crypto3/pubkey/accumulators/parameters/weights.hpp>
4144

4245
namespace nil {
4346
namespace crypto3 {
@@ -62,7 +65,12 @@ namespace nil {
6265
part_verify_impl(const Args &args) :
6366
key(args[boost::accumulators::sample]),
6467
signature(args[::nil::crypto3::accumulators::signature]) {
65-
processing_mode_type::init_accumulator(key, acc);
68+
if constexpr (is_weighted_shamir_sss<typename key_type::sss_public_key_group_type>::value) {
69+
processing_mode_type::init_accumulator(
70+
key, acc, args[nil::crypto3::accumulators::weights]);
71+
} else {
72+
processing_mode_type::init_accumulator(key, acc);
73+
}
6674
}
6775

6876
template<typename Args>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2021 Mikhail Komarov <[email protected]>
3+
// Copyright (c) 2021 Ilias Khairullin <[email protected]>
4+
//
5+
// MIT License
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
//---------------------------------------------------------------------------//
25+
26+
#ifndef CRYPTO3_ACCUMULATORS_PUBKEY_SIGN_WEIGHTED_HPP
27+
#define CRYPTO3_ACCUMULATORS_PUBKEY_SIGN_WEIGHTED_HPP
28+
29+
#include <iterator>
30+
#include <type_traits>
31+
32+
#include <boost/parameter/value_type.hpp>
33+
34+
#include <boost/accumulators/framework/accumulator_base.hpp>
35+
#include <boost/accumulators/framework/extractor.hpp>
36+
#include <boost/accumulators/framework/depends_on.hpp>
37+
#include <boost/accumulators/framework/parameters/sample.hpp>
38+
39+
#include <nil/crypto3/pubkey/accumulators/parameters/iterator_last.hpp>
40+
#include <nil/crypto3/pubkey/accumulators/parameters/weights.hpp>
41+
42+
#include <nil/crypto3/pubkey/modes/isomorphic.hpp>
43+
44+
namespace nil {
45+
namespace crypto3 {
46+
namespace pubkey {
47+
namespace accumulators {
48+
namespace impl {
49+
template<typename ProcessingMode, typename = void>
50+
struct sign_weighted_impl;
51+
52+
template<typename ProcessingMode>
53+
struct sign_weighted_impl<ProcessingMode> : boost::accumulators::accumulator_base {
54+
protected:
55+
typedef ProcessingMode processing_mode_type;
56+
typedef typename processing_mode_type::key_type key_type;
57+
typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
58+
59+
public:
60+
typedef typename processing_mode_type::result_type result_type;
61+
62+
template<typename Args>
63+
sign_weighted_impl(const Args &args) : key(args[boost::accumulators::sample]) {
64+
processing_mode_type::init_accumulator(key, acc, args[nil::crypto3::accumulators::weights]);
65+
}
66+
67+
template<typename Args>
68+
inline void operator()(const Args &args) {
69+
resolve_type(args[boost::accumulators::sample | nullptr],
70+
args[nil::crypto3::accumulators::iterator_last | nullptr]);
71+
}
72+
73+
inline result_type result(boost::accumulators::dont_care) const {
74+
return processing_mode_type::process(key, acc);
75+
}
76+
77+
protected:
78+
template<typename InputRange>
79+
inline void resolve_type(const InputRange &range, std::nullptr_t) {
80+
processing_mode_type::update(key, acc, range);
81+
}
82+
83+
template<typename InputIterator>
84+
inline void resolve_type(InputIterator first, InputIterator last) {
85+
processing_mode_type::update(key, acc, first, last);
86+
}
87+
88+
key_type key;
89+
mutable internal_accumulator_type acc;
90+
};
91+
} // namespace impl
92+
93+
namespace tag {
94+
template<typename ProcessingMode>
95+
struct sign_weighted : boost::accumulators::depends_on<> {
96+
typedef ProcessingMode processing_mode_type;
97+
98+
/// INTERNAL ONLY
99+
///
100+
101+
typedef boost::mpl::always<accumulators::impl::sign_weighted_impl<processing_mode_type>> impl;
102+
};
103+
} // namespace tag
104+
105+
namespace extract {
106+
template<typename ProcessingMode, typename AccumulatorSet>
107+
typename boost::mpl::apply<AccumulatorSet, tag::sign_weighted<ProcessingMode>>::type::result_type
108+
sign_weighted(const AccumulatorSet &acc) {
109+
return boost::accumulators::extract_result<tag::sign_weighted<ProcessingMode>>(acc);
110+
}
111+
} // namespace extract
112+
} // namespace accumulators
113+
} // namespace pubkey
114+
} // namespace crypto3
115+
} // namespace nil
116+
117+
#endif // CRYPTO3_ACCUMULATORS_PUBKEY_SIGN_WEIGHTED_HPP

include/nil/crypto3/pubkey/modes/algorithm/part_verify.hpp

+83-50
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//---------------------------------------------------------------------------//
2-
// Copyright (c) 2018-2020 Mikhail Komarov <[email protected]>
3-
// Copyright (c) 2020 Ilias Khairullin <[email protected]>
2+
// Copyright (c) 2021 Mikhail Komarov <[email protected]>
3+
// Copyright (c) 2021 Ilias Khairullin <[email protected]>
44
//
55
// MIT License
66
//
@@ -54,10 +54,10 @@ namespace nil {
5454
* @return
5555
*/
5656
template<typename Mode, typename SinglePassRange, typename OutputIterator>
57-
OutputIterator
58-
part_verify(const SinglePassRange &rng,
59-
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
60-
const pubkey::part_public_key<typename Mode::scheme_type> &key, OutputIterator out) {
57+
OutputIterator part_verify(
58+
const SinglePassRange &rng,
59+
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
60+
const pubkey::part_public_key<typename Mode::scheme_type> &key, OutputIterator out) {
6161

6262
typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
6363
typedef typename pubkey::part_verification_accumulator_set<ProcessingMode> ModeAccumulator;
@@ -86,10 +86,10 @@ namespace nil {
8686
* @return
8787
*/
8888
template<typename Mode, typename InputIterator, typename OutputIterator>
89-
OutputIterator
90-
part_verify(InputIterator first, InputIterator last,
91-
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
92-
const pubkey::part_public_key<typename Mode::scheme_type> &key, OutputIterator out) {
89+
OutputIterator part_verify(
90+
InputIterator first, InputIterator last,
91+
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
92+
const pubkey::part_public_key<typename Mode::scheme_type> &key, OutputIterator out) {
9393

9494
typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
9595
typedef typename pubkey::part_verification_accumulator_set<ProcessingMode> ModeAccumulator;
@@ -176,10 +176,10 @@ namespace nil {
176176
template<typename Mode, typename InputIterator,
177177
typename ModeAccumulator = typename pubkey::part_verification_accumulator_set<
178178
typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type>>
179-
pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>>
180-
part_verify(InputIterator first, InputIterator last,
181-
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
182-
const pubkey::part_public_key<typename Mode::scheme_type> &key) {
179+
pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>> part_verify(
180+
InputIterator first, InputIterator last,
181+
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
182+
const pubkey::part_public_key<typename Mode::scheme_type> &key) {
183183

184184
typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
185185

@@ -206,10 +206,10 @@ namespace nil {
206206
template<typename Mode, typename SinglePassRange,
207207
typename ModeAccumulator = typename pubkey::part_verification_accumulator_set<
208208
typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type>>
209-
pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>>
210-
part_verify(const SinglePassRange &r,
211-
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
212-
const pubkey::part_public_key<typename Mode::scheme_type> &key) {
209+
pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>> part_verify(
210+
const SinglePassRange &r,
211+
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
212+
const pubkey::part_public_key<typename Mode::scheme_type> &key) {
213213

214214
typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
215215

@@ -219,38 +219,71 @@ namespace nil {
219219
return VerifyerImpl(r, ModeAccumulator(key, nil::crypto3::accumulators::signature = part_sig));
220220
}
221221

222-
// /*!
223-
// * @brief
224-
// *
225-
// * @ingroup pubkey_algorithms
226-
// *
227-
// * @tparam Scheme
228-
// * @tparam InputIterator
229-
// * @tparam KeySinglePassRange
230-
// * @tparam ModeAccumulator
231-
// *
232-
// * @param first
233-
// * @param last
234-
// * @param key
235-
// *
236-
// * @return
237-
// */
238-
// template<typename Mode, typename InputIterator1, typename InputIterator2,
239-
// typename ModeAccumulator = typename pubkey::part_verification_accumulator_set<
240-
// typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type>>
241-
// pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>>
242-
// part_verify(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
243-
// const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
244-
// const pubkey::part_public_key<typename Mode::scheme_type> &key) {
245-
//
246-
// typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
247-
//
248-
// typedef pubkey::detail::value_pubkey_impl<ModeAccumulator> StreamVerifyerImpl;
249-
// typedef pubkey::detail::range_pubkey_impl<StreamVerifyerImpl> VerifyerImpl;
250-
//
251-
// return VerifyerImpl(first1, last1, first2, last2,
252-
// ModeAccumulator(key, nil::crypto3::accumulators::signature = part_sig));
253-
// }
222+
/*!
223+
* @brief
224+
*
225+
* @ingroup pubkey_algorithms
226+
*
227+
* @tparam Scheme
228+
* @tparam InputIterator
229+
* @tparam KeySinglePassRange
230+
* @tparam ModeAccumulator
231+
*
232+
* @param first
233+
* @param last
234+
* @param key
235+
*
236+
* @return
237+
*/
238+
template<typename Mode, typename InputIterator, typename Weights,
239+
typename ModeAccumulator = typename pubkey::part_verification_accumulator_set<
240+
typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type>>
241+
pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>> part_verify(
242+
InputIterator first, InputIterator last,
243+
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
244+
const Weights &weights, const pubkey::part_public_key<typename Mode::scheme_type> &key) {
245+
246+
typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
247+
248+
typedef pubkey::detail::value_pubkey_impl<ModeAccumulator> StreamVerifyerImpl;
249+
typedef pubkey::detail::range_pubkey_impl<StreamVerifyerImpl> VerifyerImpl;
250+
251+
return VerifyerImpl(first, last,
252+
ModeAccumulator(key, nil::crypto3::accumulators::signature = part_sig,
253+
nil::crypto3::accumulators::weights = weights));
254+
}
255+
256+
/*!
257+
* @brief
258+
*
259+
* @ingroup pubkey_algorithms
260+
*
261+
* @tparam Scheme
262+
* @tparam SinglePassRange
263+
* @tparam ModeAccumulator
264+
*
265+
* @param r
266+
* @param key
267+
*
268+
* @return
269+
*/
270+
template<typename Mode, typename SinglePassRange, typename Weights,
271+
typename ModeAccumulator = typename pubkey::part_verification_accumulator_set<
272+
typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type>>
273+
pubkey::detail::range_pubkey_impl<pubkey::detail::value_pubkey_impl<ModeAccumulator>> part_verify(
274+
const SinglePassRange &r,
275+
const typename pubkey::part_public_key<typename Mode::scheme_type>::part_signature_type &part_sig,
276+
const Weights &weights,
277+
const pubkey::part_public_key<typename Mode::scheme_type> &key) {
278+
279+
typedef typename Mode::template bind<pubkey::part_verification_mode_policy<Mode>>::type ProcessingMode;
280+
281+
typedef pubkey::detail::value_pubkey_impl<ModeAccumulator> StreamVerifyerImpl;
282+
typedef pubkey::detail::range_pubkey_impl<StreamVerifyerImpl> VerifyerImpl;
283+
284+
return VerifyerImpl(r, ModeAccumulator(key, nil::crypto3::accumulators::signature = part_sig,
285+
nil::crypto3::accumulators::weights = weights));
286+
}
254287
} // namespace crypto3
255288
} // namespace nil
256289

0 commit comments

Comments
 (0)