sharplispers / ironclad

A cryptographic toolkit written in Common Lisp
BSD 3-Clause "New" or "Revised" License
166 stars 28 forks source link

Code in STRONG-RANDOM craps out for large integer limits #3

Closed dbmcclain closed 6 years ago

dbmcclain commented 6 years ago

The code in the INTEGER branch of the ETYPECASE on LIMIT craps out with floating point exception on NAN's when very large integer limits are requested. The use of LOG and EXPT should be replaced with INTEGER-LENGTH and ASH:

From this.... (integer (let* ((log-limit (log limit 2)) ;; <-- (A) (num-bytes (ceiling log-limit 8)) (mask (1- (expt 2 (ceiling log-limit))))) ;; <-- (B) (loop for random = (logand (ironclad:octets-to-integer

To this... (integer (let* ((log-limit (integer-length limit)) ;; <-- (A') (num-bytes (ceiling log-limit 8)) (mask (1- (ash 1 log-limit)))) ;; <-- (B') (loop for random = (logand (ironclad:octets-to-integer

glv2 commented 6 years ago

Done in commit d7cce95f0218c8715d500f1aba015753e35354ab. Thanks.