Commit 14e7192d authored by Péter Szilágyi's avatar Péter Szilágyi

crypto/sha3: pull in latest keccak from go crypto (45% speed increase)

parent 9085b105
This diff is collapsed.
...@@ -38,13 +38,10 @@ const stateSize = laneSize * numLanes ...@@ -38,13 +38,10 @@ const stateSize = laneSize * numLanes
// O(2^{outputSize/2}) computations (the birthday lower bound). Future standards may modify the // O(2^{outputSize/2}) computations (the birthday lower bound). Future standards may modify the
// capacity/outputSize ratio to allow for more output with lower cryptographic security. // capacity/outputSize ratio to allow for more output with lower cryptographic security.
type digest struct { type digest struct {
a [numLanes]uint64 // main state of the hash a [numLanes]uint64 // main state of the hash
b [numLanes]uint64 // intermediate states outputSize int // desired output size in bytes
c [sliceSize]uint64 // intermediate states capacity int // number of bytes to leave untouched during squeeze/absorb
d [sliceSize]uint64 // intermediate states absorbed int // number of bytes absorbed thus far
outputSize int // desired output size in bytes
capacity int // number of bytes to leave untouched during squeeze/absorb
absorbed int // number of bytes absorbed thus far
} }
// minInt returns the lesser of two integer arguments, to simplify the absorption routine. // minInt returns the lesser of two integer arguments, to simplify the absorption routine.
...@@ -116,7 +113,7 @@ func (d *digest) Write(p []byte) (int, error) { ...@@ -116,7 +113,7 @@ func (d *digest) Write(p []byte) (int, error) {
// For every rate() bytes absorbed, the state must be permuted via the F Function. // For every rate() bytes absorbed, the state must be permuted via the F Function.
if (d.absorbed)%d.rate() == 0 { if (d.absorbed)%d.rate() == 0 {
d.keccakF() keccakF1600(&d.a)
} }
} }
...@@ -134,7 +131,7 @@ func (d *digest) Write(p []byte) (int, error) { ...@@ -134,7 +131,7 @@ func (d *digest) Write(p []byte) (int, error) {
d.absorbed += (lastLane - firstLane) * laneSize d.absorbed += (lastLane - firstLane) * laneSize
// For every rate() bytes absorbed, the state must be permuted via the F Function. // For every rate() bytes absorbed, the state must be permuted via the F Function.
if (d.absorbed)%d.rate() == 0 { if (d.absorbed)%d.rate() == 0 {
d.keccakF() keccakF1600(&d.a)
} }
offset = 0 offset = 0
...@@ -167,7 +164,7 @@ func (d *digest) pad() { ...@@ -167,7 +164,7 @@ func (d *digest) pad() {
// finalize prepares the hash to output data by padding and one final permutation of the state. // finalize prepares the hash to output data by padding and one final permutation of the state.
func (d *digest) finalize() { func (d *digest) finalize() {
d.pad() d.pad()
d.keccakF() keccakF1600(&d.a)
} }
// squeeze outputs an arbitrary number of bytes from the hash state. // squeeze outputs an arbitrary number of bytes from the hash state.
...@@ -192,7 +189,7 @@ func (d *digest) squeeze(in []byte, toSqueeze int) []byte { ...@@ -192,7 +189,7 @@ func (d *digest) squeeze(in []byte, toSqueeze int) []byte {
out = out[laneSize:] out = out[laneSize:]
} }
if len(out) > 0 { if len(out) > 0 {
d.keccakF() keccakF1600(&d.a)
} }
} }
return in[:len(in)+toSqueeze] // Re-slice in case we wrote extra data. return in[:len(in)+toSqueeze] // Re-slice in case we wrote extra data.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment