Skip to content

Commit

Permalink
Use keccak256() instead of sha3()
Browse files Browse the repository at this point in the history
Requires Solidity 0.4.12.
  • Loading branch information
axic committed Jul 23, 2018
1 parent 7e1c3a1 commit ab0ec4b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/strings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ library strings {
let length := mload(needle)
let selfptr := mload(add(self, 0x20))
let needleptr := mload(add(needle, 0x20))
equal := eq(sha3(selfptr, length), sha3(needleptr, length))
equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
}
}

Expand Down Expand Up @@ -488,11 +488,11 @@ library strings {
} else {
// For long needles, use hashing
bytes32 hash;
assembly { hash := sha3(needleptr, needlelen) }
assembly { hash := keccak256(needleptr, needlelen) }

for (idx = 0; idx <= selflen - needlelen; idx++) {
bytes32 testHash;
assembly { testHash := sha3(ptr, needlelen) }
assembly { testHash := keccak256(ptr, needlelen) }
if (hash == testHash)
return ptr;
ptr += 1;
Expand Down Expand Up @@ -528,11 +528,11 @@ library strings {
} else {
// For long needles, use hashing
bytes32 hash;
assembly { hash := sha3(needleptr, needlelen) }
assembly { hash := keccak256(needleptr, needlelen) }
ptr = selfptr + (selflen - needlelen);
while (ptr >= selfptr) {
bytes32 testHash;
assembly { testHash := sha3(ptr, needlelen) }
assembly { testHash := keccak256(ptr, needlelen) }
if (hash == testHash)
return ptr + needlelen;
ptr -= 1;
Expand Down

0 comments on commit ab0ec4b

Please sign in to comment.