Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,087 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
ethereumj-core/src/main/java/org/ethereum/sharding/crypto/DummySign.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.sharding.crypto; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.ethereum.crypto.HashUtil.sha3; | ||
|
||
/** | ||
* Dummy signature implementation without real crypto underneath | ||
*/ | ||
public class DummySign implements Sign { | ||
|
||
/** | ||
* Sign the message | ||
*/ | ||
public Signature sign(byte[] msg, byte[] privateKey) { | ||
byte[] rSource = sha3(privateKey); | ||
byte[] sSource = sha3(msg, privateKey); | ||
Signature res = new Signature(); | ||
res.r = new BigInteger(rSource); | ||
res.s = new BigInteger(sSource); | ||
|
||
return res; | ||
} | ||
|
||
/** | ||
* Verifies whether signature is made by signer with publicKey | ||
*/ | ||
public boolean verify(Signature signature, byte[] publicKey) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Aggregates several signatures in one | ||
*/ | ||
public Signature aggSigns(Signature[] signatures) { | ||
int signatureLen = signatures.length; | ||
Signature aggSignature = new Signature(); | ||
aggSignature.r = BigInteger.ZERO; | ||
aggSignature.s = BigInteger.ZERO; | ||
for (int i = 0; i < signatureLen; ++i) { | ||
for (Signature signature : signatures) { | ||
aggSignature.r = aggSignature.r.xor(signature.r); | ||
aggSignature.s = aggSignature.s.xor(signature.s); | ||
} | ||
} | ||
|
||
return aggSignature; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
ethereumj-core/src/main/java/org/ethereum/sharding/crypto/Sign.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.ethereum.sharding.crypto; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Signature utilities | ||
* Signature should be implemented using BLS | ||
*/ | ||
public interface Sign { | ||
|
||
/** | ||
* Sign the message | ||
*/ | ||
Signature sign(byte[] msg, byte[] privateKey); | ||
|
||
/** | ||
* Verifies whether signature is made by signer with publicKey | ||
*/ | ||
boolean verify(Signature signature, byte[] publicKey); | ||
|
||
/** | ||
* Aggregates several signatures in one | ||
*/ | ||
Signature aggSigns(Signature[] signatures); | ||
|
||
class Signature { | ||
public BigInteger r; | ||
public BigInteger s; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Signature signature = (Signature) o; | ||
return Objects.equals(r, signature.r) && | ||
Objects.equals(s, signature.s); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Signature{" + | ||
"r=" + r + | ||
", s=" + s + | ||
'}'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.