-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to use external contracts for digest and algorithm
- Loading branch information
Showing
13 changed files
with
140 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
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,5 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
contract Algorithm { | ||
function verify(bytes key, bytes data, bytes signature) public view returns(bool); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pragma solidity ^0.4.13; | ||
pragma solidity ^0.4.17; | ||
|
||
library BytesUtils { | ||
struct slice { | ||
|
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,5 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
contract Digest { | ||
function verify(bytes data, bytes hash) public view returns (bool); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
contract Owned { | ||
address public owner; | ||
|
||
function Owned() { | ||
owner = msg.sender; | ||
} | ||
|
||
modifier owner_only() { | ||
require(msg.sender == owner); | ||
_; | ||
} | ||
|
||
function setOwner(address newOwner) public owner_only { | ||
owner = newOwner; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pragma solidity ^0.4.13; | ||
pragma solidity ^0.4.17; | ||
|
||
import "./bytesutils.sol"; | ||
|
||
|
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,43 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
import "./algorithm.sol"; | ||
import "./bytesutils.sol"; | ||
import "./rsaverify.sol"; | ||
|
||
contract RSASHA256Algorithm is Algorithm { | ||
using BytesUtils for *; | ||
|
||
function verify(bytes key, bytes data, bytes sig) public view returns (bool) { | ||
BytesUtils.slice memory dnskey; | ||
dnskey.fromBytes(key); | ||
|
||
bytes memory exponent; | ||
bytes memory modulus; | ||
|
||
var exponentLen = uint16(dnskey.uint8At(4)); | ||
if(exponentLen != 0) { | ||
exponent = dnskey.toBytes(5, exponentLen + 5); | ||
modulus = dnskey.toBytes(exponentLen + 5, dnskey.len); | ||
} else { | ||
exponentLen = dnskey.uint16At(5); | ||
exponent = dnskey.toBytes(7, exponentLen + 7); | ||
modulus = dnskey.toBytes(exponentLen + 7, dnskey.len); | ||
} | ||
|
||
bytes memory sigdata = new bytes(modulus.length); | ||
BytesUtils.slice memory sigdataslice; | ||
sigdataslice.fromBytes(sigdata); | ||
// Write 0x0001 | ||
sigdataslice.writeBytes32(0, 0x0001 << 240); | ||
// Repeat 0xFF as many times as needed (2 byte 0x0001 + 20 byte prefix + 32 byte hash = 54) | ||
var padsize = modulus.length - 54; | ||
sigdataslice.fill(2, padsize, 0xff); | ||
// Write the prefix | ||
sigdataslice.writeBytes32(padsize + 2, 0x00003031300d060960864801650304020105000420 << 96); | ||
// Write the hash | ||
sigdataslice.writeBytes32(padsize + 22, sha256(data)); | ||
|
||
// Verify the signature | ||
return RSAVerify.rsaverify(sigdata, modulus, exponent, sig); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pragma solidity ^0.4.16; | ||
pragma solidity ^0.4.17; | ||
|
||
import "./modexp.sol"; | ||
|
||
|
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,14 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
import "./digest.sol"; | ||
import "./bytesutils.sol"; | ||
|
||
contract SHA256Digest is Digest { | ||
using BytesUtils for *; | ||
|
||
function verify(bytes data, bytes hash) public view returns (bool) { | ||
BytesUtils.slice memory hashslice; | ||
hashslice.fromBytes(hash); | ||
return sha256(data) == hashslice.bytes32At(0); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,21 @@ | ||
var rsasha256 = artifacts.require("./rsasha256algorithm.sol"); | ||
var sha256 = artifacts.require("./sha256digest.sol"); | ||
var dnssec = artifacts.require("./dnssec.sol"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(dnssec); | ||
deployer.deploy(dnssec).then(function() { | ||
return deployer.deploy(rsasha256); | ||
}).then(function() { | ||
return deployer.deploy(sha256); | ||
}).then(function() { | ||
return dnssec.deployed().then(function(instance) { | ||
return rsasha256.deployed().then(function(algorithm) { | ||
return instance.setAlgorithm(8, algorithm.address); | ||
}).then(function() { | ||
return sha256.deployed(); | ||
}).then(function(digest) { | ||
return instance.setDigest(2, digest.address); | ||
}); | ||
}); | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.