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:
2013-09-14 23:46:44 +02:00
parent 4cb18313ac
commit 9391b65603

View File

@ -110,14 +110,19 @@ and `end', which must be numeric bounding-indices."
#.*optimize-declaration*)
;; Handle potential remaining bytes
(unless (zerop buffer-index)
(let ((remainder (- (length buffer) buffer-index)))
(declare (type fixnum remainder))
(let ((remainder (- (length buffer) buffer-index))
(length (- end start)))
(declare (type fixnum remainder length))
(replace buffer vector :start1 buffer-index :start2 start :end2 end)
(when (>= (- end start) remainder)
;; Return if still unfilled buffer
(when (< length remainder)
(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))
(keccak-f keccak-state)
(setf (sha3-state-buffer-index state) 0
start (min (+ start remainder) end))))
start (+ start remainder))))
;; Now handle full blocks, stuff any remainder into buffer
(loop for block-offset of-type fixnum from start to end by rate-bytes
do