aboutsummaryrefslogtreecommitdiff
path: root/internals.h
blob: fa2ea876ac76cf13b040dd03304e52f842612382 (plain) (blame)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* This file is part of libbrandt.
 * Copyright (C) 2016 GNUnet e.V.
 *
 * libbrandt 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 3 of the License, or (at your option) any later
 * version.
 *
 * libbrandt 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
 * libbrandt.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file internals.h
 * @brief This header contains library internal structs.
 * @author Markus Teich
 */

#ifndef _BRANDT_INTERNALS_H
#define _BRANDT_INTERNALS_H

#include <gcrypt.h>

#include "brandt.h"


enum rounds {
	msg_join,
	msg_init,
	msg_bid,
	msg_outcome,
	msg_decrypt,
	msg_last
};


enum auction_type {
	auction_firstPrice,
	auction_mPlusFirstPrice,
	auction_last
};


enum outcome_type {
	outcome_private,
	outcome_public,
	outcome_last
};


GNUNET_NETWORK_STRUCT_BEGIN

/**
 * This struct describes an auction and is always linked to a description buffer
 * of #description_len bytes of arbitrary data where the description of the item
 * to be sold is stored. This buffer should also contain information linking the
 * auction to the payment system (which exact prices do the k possibilities
 * refer to, payment system seller identity, …). All fields are stored in
 * network byte order.
 *
 * \todo: align to a multiple of 64bit
 * \todo: versionsnummer */
struct BRANDT_DescrP {
	/** Hash code over the remaining elements of this struct followed by the
	 * description buffer of #description_len bytes */
	struct GNUNET_HashCode hash GNUNET_PACKED;

	/** Starting time of the auction. Bidders have to join the auction via
	 * BRANDT_join until this time */
	struct GNUNET_TIME_AbsoluteNBO time_start;

	/** The maximum duration the participants have to complete each round. */
	struct GNUNET_TIME_RelativeNBO time_round;

	/** The length of the description in bytes */
	uint32_t description_len GNUNET_PACKED;

	/** reserved for future use */
	uint32_t reserved1 GNUNET_PACKED;

	/** The amount of possible prices */
	uint16_t k GNUNET_PACKED;

	/** Auction type. 0 means first price Auction, >= 0 means M+1st price
	 * auction with an amount of m items being sold. */
	uint16_t m GNUNET_PACKED;

	/** Outcome type. 0 means private outcome, everything else means public
	 * outcome. */
	uint16_t outcome_public GNUNET_PACKED;

	/** reserved for future use */
	uint16_t reserved2 GNUNET_PACKED;
};

GNUNET_NETWORK_STRUCT_END


struct BRANDT_Auction {
	/** Starting time of the auction. Bidders have to join the auction via
	 * BRANDT_join until this time */
	struct GNUNET_TIME_Absolute time_start;

	/** The maximum duration the participants have to complete each round. */
	struct GNUNET_TIME_Relative time_round;

	/** Auction type. 0 means first price Auction, >= 0 means M+1st price
	 * auction with an amount of m items being sold. */
	uint16_t m;

	/** Outcome type. 0 means private outcome, everything else means public
	 * outcome. */
	uint16_t outcome_public;

	/** Link to the next delayed task (auction start trigger, round trigger) */
	struct GNUNET_SCHEDULER_Task *task;

	void *closure;              /** auction closure given by the user */

	BRANDT_CbBroadcast bcast;   /** broadcast callback */
	BRANDT_CbUnicast   ucast;   /** unicast callback */
	BRANDT_CbResult    result;  /** result reporting callback */

	int         seller_mode;    /** If 0 we are bidding, selling otherwise */
	enum rounds cur_round;      /** The round we expect messages from */
	gcry_mpi_t  round_progress; /** Stores which round messages were received */

	uint16_t n;                 /** The amount of bidders/agents */
	uint16_t k;                 /** The amount of possible prices */
	uint16_t i;                 /** Own agents index, only used when bidding */
	uint16_t b;                 /** Own bid */

	gcry_mpi_t       x;         /** Own private additive key share */
	gcry_mpi_point_t *y;        /** public multiplicative key shares, size: n */
	gcry_mpi_point_t Y;         /** Shared public key */

	gcry_mpi_point_t **alpha;   /** alphas, size: n*k */
	gcry_mpi_point_t **beta;    /** betas, size: n*k */

	gcry_mpi_point_t **gamma2;  /** gamma2, for public outcome, size: n*k */
	gcry_mpi_point_t ***gamma3; /** gamma3, for private outcome, size: n*n*k */
	gcry_mpi_point_t **delta2;  /** delta2, for public outcome, size: n*k */
	gcry_mpi_point_t ***delta3; /** delta3, for private outcome, size: n*n*k */
	gcry_mpi_point_t **phi2;    /** phi2, for public outcome, size: n*k */
	gcry_mpi_point_t ***phi3;   /** phi3, for private outcome, size: n*n*k */

	gcry_mpi_point_t *tmpa1;    /** used for temporary storage, size: k */
	gcry_mpi_point_t *tmpb1;    /** used for temporary storage, size: k */
};

#endif /* ifndef _BRANDT_INTERNALS_H */