Skip to content

Instantly share code, notes, and snippets.

@joekarma
Last active December 15, 2015 20:58
Show Gist options
  • Save joekarma/5321929 to your computer and use it in GitHub Desktop.
Save joekarma/5321929 to your computer and use it in GitHub Desktop.
sha512 password digesting function
(defun 5-random-base64-encoded-bytes ()
(base64:usb8-array-to-base64-string
(map 'vector (lambda (place)
(declare (ignore place))
(random 255))
(make-sequence 'vector 5))))
(defun digest-password (password &optional (salt (5-random-base64-encoded-bytes)))
(values
(base64:usb8-array-to-base64-string
(ironclad:digest-sequence 'ironclad::sha512
(babel:string-to-octets (concatenate 'string password salt))))
salt))
@zkat
Copy link

zkat commented Apr 5, 2013

(defparameter *key-derivation-iterations* 720)
(defparameter *key-length* 32)
(defun hash-password (password salt
                      &key
                        (key-iterations *key-derivation-iterations*)
                        (key-length *key-length*))
  "Password hashing function."
  (ironclad:derive-key
   (make-instance 'ironclad:pbkdf2 :digest :sha256)
   (ironclad:ascii-string-to-byte-array password)
   salt
   key-iterations
   key-length))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment