mirror of
https://github.com/pmai/sha3.git
synced 2025-12-21 23:34:29 +01:00
Fix buffer handling for partial updates (fix #1).
Calls to sha3-update that did not completely fill an already partially filled buffer were handled incorrectly, in that the buffer-index wasn't properly updated. Thanks to Orivej Desh for the bug report.
This commit is contained in:
17
sha3.lisp
17
sha3.lisp
@ -110,14 +110,19 @@ and `end', which must be numeric bounding-indices."
|
|||||||
#.*optimize-declaration*)
|
#.*optimize-declaration*)
|
||||||
;; Handle potential remaining bytes
|
;; Handle potential remaining bytes
|
||||||
(unless (zerop buffer-index)
|
(unless (zerop buffer-index)
|
||||||
(let ((remainder (- (length buffer) buffer-index)))
|
(let ((remainder (- (length buffer) buffer-index))
|
||||||
(declare (type fixnum remainder))
|
(length (- end start)))
|
||||||
|
(declare (type fixnum remainder length))
|
||||||
(replace buffer vector :start1 buffer-index :start2 start :end2 end)
|
(replace buffer vector :start1 buffer-index :start2 start :end2 end)
|
||||||
(when (>= (- end start) remainder)
|
;; Return if still unfilled buffer
|
||||||
(keccak-state-merge-input keccak-state bit-rate buffer 0)
|
(when (< length remainder)
|
||||||
(keccak-f keccak-state))
|
(incf (sha3-state-buffer-index state) length)
|
||||||
|
(return-from sha3-update))
|
||||||
|
;; Else handle now complete buffer
|
||||||
|
(keccak-state-merge-input keccak-state bit-rate buffer 0)
|
||||||
|
(keccak-f keccak-state)
|
||||||
(setf (sha3-state-buffer-index state) 0
|
(setf (sha3-state-buffer-index state) 0
|
||||||
start (min (+ start remainder) end))))
|
start (+ start remainder))))
|
||||||
;; Now handle full blocks, stuff any remainder into buffer
|
;; Now handle full blocks, stuff any remainder into buffer
|
||||||
(loop for block-offset of-type fixnum from start to end by rate-bytes
|
(loop for block-offset of-type fixnum from start to end by rate-bytes
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user