mirror of
https://github.com/henrydcase/nobs.git
synced 2024-11-22 23:28:57 +00:00
add function for one-off calculation
This commit is contained in:
parent
24408329a5
commit
cccb9890e1
@ -132,14 +132,10 @@ func (c *state) Write(in []byte) (nwrite int, err error) {
|
|||||||
return nwrite, nil
|
return nwrite, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read changes state of the hash if called first time. It will
|
func (c *state) finalize_sha3() {
|
||||||
// return len(out) bytes of data. Never fails.
|
|
||||||
func (c *state) Read(out []byte) (nread int, err error) {
|
|
||||||
buf := c.data.asBytes()[:]
|
buf := c.data.asBytes()[:]
|
||||||
rate := c.BlockSize()
|
rate := c.BlockSize()
|
||||||
nread = len(out)
|
|
||||||
|
|
||||||
if !c.isSquezing {
|
|
||||||
// there is at least one byte free, otherise
|
// there is at least one byte free, otherise
|
||||||
// buf would be squezed already
|
// buf would be squezed already
|
||||||
for i := c.idx + 1; i < rate; i++ {
|
for i := c.idx + 1; i < rate; i++ {
|
||||||
@ -152,6 +148,17 @@ func (c *state) Read(out []byte) (nread int, err error) {
|
|||||||
copyOut(c, buf[:rate])
|
copyOut(c, buf[:rate])
|
||||||
c.idx = rate // now, idx indicates unconsumed amount of data
|
c.idx = rate // now, idx indicates unconsumed amount of data
|
||||||
c.isSquezing = true
|
c.isSquezing = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read changes state of the hash if called first time. It will
|
||||||
|
// return len(out) bytes of data. Never fails.
|
||||||
|
func (c *state) Read(out []byte) (nread int, err error) {
|
||||||
|
buf := c.data.asBytes()[:]
|
||||||
|
rate := c.BlockSize()
|
||||||
|
nread = len(out)
|
||||||
|
|
||||||
|
if !c.isSquezing {
|
||||||
|
c.finalize_sha3()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy-out bytes that are still kept in the buffer
|
// Copy-out bytes that are still kept in the buffer
|
||||||
@ -211,6 +218,21 @@ func (c *state) Sum(in []byte) []byte {
|
|||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *state) digest(out, in []byte) {
|
||||||
|
nread := len(out)
|
||||||
|
rate := c.BlockSize()
|
||||||
|
nblocks := nread / rate
|
||||||
|
c.Write(in)
|
||||||
|
c.finalize_sha3()
|
||||||
|
for i := 0; i < nblocks-1; i++ {
|
||||||
|
keccakF1600(&c.a)
|
||||||
|
copyOut(c, out[:])
|
||||||
|
out = out[rate:]
|
||||||
|
}
|
||||||
|
keccakF1600(&c.a)
|
||||||
|
copyOut(c, out[:len(out)])
|
||||||
|
}
|
||||||
|
|
||||||
// New224 creates a new SHA3-224 hash.
|
// New224 creates a new SHA3-224 hash.
|
||||||
// Its generic security strength is 224 bits against preimage attacks,
|
// Its generic security strength is 224 bits against preimage attacks,
|
||||||
// and 112 bits against collision attacks.
|
// and 112 bits against collision attacks.
|
||||||
|
Loading…
Reference in New Issue
Block a user