Skip to content

Commit

Permalink
Rabin signature
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Jul 3, 2019
1 parent 03f967b commit 60618d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Script is designed to facilitate writing smart contract running on chain.
p2pkh
rpuzzle
ackermann
rabin

..
contributing: PR for example contracts
Expand Down
41 changes: 41 additions & 0 deletions docs/rabin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
===============
Rabin Signature
===============

`Rabin signature <https://nchain.com/app/uploads/2018/09/Rabin-Signatures-in-Bitcoin-Cash.pdf>`_ is an alternative form of digital signature to ECDSA used in Bitcoin.

.. code-block:: solidity
contract RabinSignature {
Ripemd160 nHash;
constructor() {
nHash = Ripemd160(0x88d9931ea73d60eaf7e5671efc0552b912911f2a);
}
function hash3072(bytes x) returns (bytes) {
Sha256 y = sha256(x);
int i = 0;
// start with empty
bytes ret = 0x;
// divide into 3072 / 256 = 12 slices
loop (12) {
// 256 bits is 32 bytes
bytes slice = y[32 * i : 32 * (i+1)];
// concatenate
ret = ret . sha256(slice);
i = i + 1;
}
// 3072 bit hash
return ret;
}
public function verifySig(int S, bytes U, bytes m, int lambda, bytes n) {
require(hash160(n) == nHash);
int h = bin2num(hash3072(m . U));
require(S * S == h + lambda * bin2num(n));
}
}

0 comments on commit 60618d8

Please sign in to comment.