summaryrefslogtreecommitdiff
path: root/src/TMCG_CardSecret.hh
blob: c4c0ed5fa71cc7e050b1f827b532444957e8d654 (plain)
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
/*******************************************************************************
   Data structure for the secrets of a card. This file is part of LibTMCG.

 Copyright (C) 2004, 2005, 2007, 2010,
                           2016, 2018  Heiko Stamer <[email protected]>

   LibTMCG is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   LibTMCG is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with LibTMCG; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*******************************************************************************/

#ifndef INCLUDED_TMCG_CardSecret_HH
	#define INCLUDED_TMCG_CardSecret_HH
	
// C++/STL header
#include <string>
#include <iostream>
#include <vector>
	
// GNU multiple precision library
#include <gmp.h>

/** @brief Data structure for secrets of the masking operation.
    
    This struct represents the secrets of the masking operation in the
    original encoding scheme of Schindelhauer [Sch98]. */
struct TMCG_CardSecret
{
	/** These @f$k\times w@f$-matrices encode the secrets involved in the
	    masking operation. For each of the @f$k@f$ players there is a
	    separate row and for each of the @f$w@f$ bits in the binary
	    representation of the card type there is a column. The elements
	    of the matrix @a r are numbers from @f$\mathbb{Z}^{\circ}_{m_i}@f$
	    where @f$m_i@f$ is the public modul of the @f$i@f$th player.
	    The elements of the matrix @a b are bits from @f$\{0, 1\}@f$. */
	std::vector< std::vector<MP_INT> >			r, b;
	
	/** This constructor initializes the secrets with a @f$1\times 1@f$-matrix.
	    Later the function TMCG_CardSecret::resize can be used to enlarge the
	    representation of the secret. */
	TMCG_CardSecret
		();
	
	/** This constructor initializes the secrets with a @f$k\times w@f$-matrix.
	    @param k is the number of players.
	    @param w is the number of bits used in the binary representation
	           of the card type. */
	TMCG_CardSecret
		(size_t k, size_t w);
	
	/** A simple copy-constructor.
	    @param that is the secret to be copied. */
	TMCG_CardSecret
		(const TMCG_CardSecret& that);
	
	/** A simple assignment-operator.
	    @param that is the secret to be assigned. */
	TMCG_CardSecret& operator =
		(const TMCG_CardSecret& that);
	
	/** This function resizes the representation of the secrets. The current
	    content will be released and new @f$k\times w@f$-matrices created.
	    @param k is the number of players.
	    @param w is the number of bits used in the binary representation
	           of the card type. */
	void resize
		(size_t k, size_t w);
	
	/** This function imports the secret.
	    @param s is correctly formated input string.
	    @returns True, if the import was successful. */
	bool import
		(std::string s);
	
	/** This destructor releases all occupied resources. */
	~TMCG_CardSecret
		();
};

/** @relates TMCG_CardSecret
    This operator prints a secret to an output stream.
    @param out is the output stream.
    @param cardsecret is the secret to be printed. */
std::ostream& operator <<
	(std::ostream& out, const TMCG_CardSecret& cardsecret);

/** @relates TMCG_CardSecret
    This operator imports a secret from an input stream. It has to
    be delimited by a newline character.
    The failbit of the stream is set, if any parse error occurred.
    @param in is the input stream.
    @param cardsecret is the secret to be imported. */
std::istream& operator >>
	(std::istream& in, TMCG_CardSecret& cardsecret);

#endif