Skip to content

Commit

Permalink
Work around a miscompilation on ECL
Browse files Browse the repository at this point in the history
  • Loading branch information
glv2 committed Oct 11, 2024
1 parent d4fe172 commit f651945
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/util.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

(in-package :crypto)

(declaim (inline byte-array-to-hex-string
hex-string-to-byte-array
ascii-string-to-byte-array))

(defun byte-array-to-hex-string (vector &key (start 0) end (element-type 'base-char))
"Return a string containing the hexadecimal representation of the
subsequence of VECTOR between START and END. ELEMENT-TYPE controls
Expand All @@ -17,7 +13,7 @@ the element-type of the returned string."
(optimize (speed 3) (safety 1)))
(let* ((end (or end (length vector)))
(length (- end start))
(hexdigits #.(coerce "0123456789abcdef" 'simple-base-string)))
(hexdigits (load-time-value (coerce "0123456789abcdef" 'simple-base-string) t)))
(loop with string = (ecase element-type
;; so that the compiler optimization can jump in
(base-char (make-string (* length 2)
Expand All @@ -27,7 +23,6 @@ the element-type of the returned string."
for i from start below end
for j from 0 below (* length 2) by 2
do (let ((byte (aref vector i)))
(declare (optimize (safety 0)))
(setf (aref string j)
(aref hexdigits (ldb (byte 4 4) byte))
(aref string (1+ j))
Expand Down Expand Up @@ -73,10 +68,6 @@ STRING contains any character whose CHAR-CODE is greater than 255."
(setf (aref vec i) byte))
finally (return vec))))

(declaim (notinline byte-array-to-hex-string
hex-string-to-byte-array
ascii-string-to-byte-array))

(defun constant-time-equal (data1 data2)
"Returns T if the elements in DATA1 and DATA2 are identical, NIL otherwise.
All the elements of DATA1 and DATA2 are compared to prevent timing attacks."
Expand Down

0 comments on commit f651945

Please sign in to comment.