/// <summary> /// Creates a random polynomial f(x,y) and then to create from it for /// the i-th player two polynomials : fi(x) = f(x,w^i) and gi(y) = f(w^i,y). /// </summary> public static IList <SecretPolynomials> ShareByzantineCase(Zp secret, int numPlayers, int polynomDeg) { if (numPlayers <= 4 * polynomDeg) { throw new System.ArgumentException("Cannot use Byzantine algoritm -- numberOfPlayers <= 4*polynomDeg - " + "use regular computation instead"); } // Creating the Random Polynomial - f(x , y) // Note : there are (t+1)^2 coefficiet for the polynomial including the free coefficient (the secret) // first row coef are of (x^0,x^1,x^2,...,x^t)y^0, second row coef are (x^0, x1,...,x^t)y^1 and so forth... var randomMatrix_f_xy = ZpMatrix.GetRandomMatrix(polynomDeg + 1, polynomDeg + 1, secret.Prime); randomMatrix_f_xy.SetMatrixCell(0, 0, secret); var polynomialShares = new List <SecretPolynomials>(); for (int i = 0; i < numPlayers; i++) { var pSecret = new SecretPolynomials(); pSecret.Fi_xPolynomial = GenerateF_i_xPolynomial(randomMatrix_f_xy, secret, i); pSecret.Gi_yPolynomial = GenerateG_i_yPolynomial(randomMatrix_f_xy, secret, i); polynomialShares.Add(pSecret); } return(polynomialShares); }
/// <summary> /// Creates a random polynomial f(x,y) and then to create from it for /// the i-th player two polynomials : fi(x) = f(x,w^i) and gi(y) = f(w^i,y). /// </summary> public static IList<SecretPolynomials> ShareByzantineCase(Zp secret, int numPlayers, int polynomDeg) { if (numPlayers <= 4 * polynomDeg) throw new System.ArgumentException("Cannot use Byzantine algoritm -- numberOfPlayers <= 4*polynomDeg - " + "use regular computation instead"); // Creating the Random Polynomial - f(x , y) // Note : there are (t+1)^2 coefficiet for the polynomial including the free coefficient (the secret) // first row coef are of (x^0,x^1,x^2,...,x^t)y^0, second row coef are (x^0, x1,...,x^t)y^1 and so forth... var randomMatrix_f_xy = ZpMatrix.GetRandomMatrix(polynomDeg + 1, polynomDeg + 1, secret.Prime); randomMatrix_f_xy.SetMatrixCell(0, 0, secret); var polynomialShares = new List<SecretPolynomials>(); for (int i = 0; i < numPlayers; i++) { var pSecret = new SecretPolynomials(); pSecret.Fi_xPolynomial = GenerateF_i_xPolynomial(randomMatrix_f_xy, secret, i); pSecret.Gi_yPolynomial = GenerateG_i_yPolynomial(randomMatrix_f_xy, secret, i); polynomialShares.Add(pSecret); } return polynomialShares; }
private bool IsPublicDataContradictPrivate(SecretPolynomials myRecvPolys, IList<SecretPolynomials> recvPublicPolysList, IList<PlayerNotification> recvComplaintesList, Zp myRecvShare) { if ((recvPublicPolysList == null) || (recvPublicPolysList.Count != NumParties)) return true; var myG_j_w_iValues = myRecvPolys.calculateG_i_yValuesForVerification(NumParties, Prime); var myF_j_w_iValues = myRecvPolys.CalculateF_i_xValuesForPlayers(NumParties, Prime); for (int k = 0; k < NumParties; k++) { if ((recvComplaintesList[k] != null) && (recvComplaintesList[k].Confirmation == Confirmation.Complaint)) { var playerKNewPolys = recvPublicPolysList[k]; // Check if the dealer didn't publish all the required data or published a corrupted data if (!IsSecretPolynomialsLegal(playerKNewPolys)) return true; // Verify that the public information doesn't contradict itself - check that : f(w^k, w^k) = fk(w^k) = gk(w^k) = f(w^k, w^k) var playerKNewFk_x_w_iValues = playerKNewPolys.CalculateF_i_xValuesForPlayers(NumParties, Prime); var playerKNewGk_y_w_iValues = playerKNewPolys.calculateG_i_yValuesForVerification(NumParties, Prime); if (!playerKNewFk_x_w_iValues[k].Equals(playerKNewGk_y_w_iValues[k])) return true; if (k == Party.Id) { // Verify that the new public polynomials equals the old polynomials if (!IsSecretPolynomialsLegal(myRecvPolys) || !myRecvPolys.Equals(playerKNewPolys)) return true; } else { // Verify that the public information doesn't contradict the old information : // f(w^j, w^k) = fk(w^j) = gj(w^k) = f(w^j, w^k) && f(w^k, w^j) = fj(w^k) = gk(w^j) = f(w^k, w^j) if ((!myG_j_w_iValues[k].Equals(playerKNewFk_x_w_iValues[Party.Id])) || (!myF_j_w_iValues[k].Equals(playerKNewGk_y_w_iValues[Party.Id]))) return true; } } } return false; }
/// <summary> /// Checks if the received polynomials are not null, from the right size and have no null elements */ /// </summary> protected bool IsSecretPolynomialsLegal(SecretPolynomials secretPolynomial) { if (secretPolynomial == null) return false; else { var fi_xPoly = secretPolynomial.Fi_xPolynomial; var gi_yPoly = secretPolynomial.Gi_yPolynomial; if (!IsPolynomialLegal(fi_xPoly, PolynomialDeg + 1) || !IsPolynomialLegal(gi_yPoly, PolynomialDeg + 1)) return false; } return true; }
protected virtual void HandleNotDealer(bool isOrigPolyLegal, IList<Coordinate> wrongCoordinatesList, int playerToVerify, Zp recvSecretShare_i, SecretPolynomials secretPoly_i) { //// Step 2 - Check and advertise results to players on the bulletin board //var foundWrongValue1 = !isOrigPolyLegal || (wrongCoordinatesList.Count != 0); //var complaintValue = new PlayerNotification(foundWrongValue1 ? Confirmation.Complaint : Confirmation.Approval); //var recvComplaintesList = Sendable.asPlayerNotifications( // BulletinBoardProtocol.PublishAndRead(complaintValue, Prime, BadPlayers)); //// Count complaints number //int numOfcomplaints = GetNumberOfComplaints(recvComplaintesList); //// Step 3 - If there is a need, receive polynomials for the complainig sides and verify it //// currently check only polynomials - not wrong coordinates //if (numOfcomplaints != 0) //{ // // Should get a list of the public polynomials from player 'playerToVerify' - get info from the bulletin board // var sendablePolysRecv = BulletinBoardProtocol.Read(playerToVerify, Prime); // IList<SecretPolynomials> recvPublicPolysList1 = null; // if (sendablePolysRecv != null) // recvPublicPolysList1 = sendablePolysRecv.asSecretPolynomialsBundle().List; // if (foundWrongValue1) // UpdateRecvShare(recvPublicPolysList1, recvSecretShare_i); // bool foundWrongValue2 = (!isOrigPolyLegal) || IsPublicDataContradictPrivate(secretPoly_i, recvPublicPolysList1, recvComplaintesList, recvSecretShare_i); // // Check and advertise results to players on the bulletin board // complaintValue = new PlayerNotification(foundWrongValue2 ? Confirmation.Complaint : Confirmation.Approval); // recvComplaintesList = Sendable.asPlayerNotifications( // BulletinBoardProtocol.PublishAndRead(complaintValue, Prime, BadPlayers)); // // Count complaints number // numOfcomplaints = GetNumberOfComplaints(recvComplaintesList); // // Step 4 - If there is a need, recieve polynomials for the complainig sides and verify it // if (numOfcomplaints != 0) // { // // Should get a list of the public polynomials from player 'playerToVerify' - get info from the bulletin board // sendablePolysRecv = BulletinBoardProtocol.Read(playerToVerify, Prime); // IList<SecretPolynomials> recvPublicPolysList2 = null; // if (sendablePolysRecv != null) // recvPublicPolysList2 = sendablePolysRecv.asSecretPolynomialsBundle().List; // if (foundWrongValue2) // UpdateRecvShare(recvPublicPolysList2, recvSecretShare_i); // bool foundWrongValue3 = (!isOrigPolyLegal) || IsPublicDataContradictPrivate(secretPoly_i, recvPublicPolysList2, recvComplaintesList, recvSecretShare_i); // foundWrongValue3 = foundWrongValue3 || IsNewPublicDataContradictOld(recvPublicPolysList1, recvPublicPolysList2); // // Check and advertise results to players on the bulletin board // complaintValue = new PlayerNotification(foundWrongValue3 ? Confirmation.Complaint : Confirmation.Approval); // recvComplaintesList = Sendable.asPlayerNotifications( // BulletinBoardProtocol.PublishAndRead(complaintValue, Prime, BadPlayers)); // // Count complaints number // numOfcomplaints = GetNumberOfComplaints(recvComplaintesList); // /* Step 5 - Check if there is more than 'polynomialDeg' complaintes or recption timeout occured */ // if (numOfcomplaints > PolynomialDeg) // { // // Found a cheater player: playerToVerify - taking its input as zero. // // Take the zero polynomial as this user input // recvSecretShare_i.Value = 0; // RemoveCheaterPlayer(playerToVerify); // don't send and receive from this player anymore... // } // } //} //throw new NotImplementedException(); }