changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/cry/totp.lisp

changeset 239: 2596311106ae
parent: d7aa08025537
author: Richard Westhaver <ellis@rwest.io>
date: Sat, 23 Mar 2024 23:02:31 -0400
permissions: -rw-r--r--
description: img/cry init
1 ;;; crypto/totp.lisp --- Time-Based One-Time Passwords
2 
3 ;; see https://github.com/bhyde/cl-one-time-passwords/totp.lisp
4 
5 ;; RFC 6238
6 
7 ;;; Code:
8 (in-package :cry/totp)
9 
10 (defconstant .unix-epoch-zero. 2208988800)
11  ;; 00:00:00 UTC on 1 January 1970
12  ;; (encode-universal-time 0 0 0 1 1 1970 0)
13  ;; --> 2208988800
14 
15 (defvar *time-zero* 0) ; aka the unix epoch zero
16 (defvar *time-step-in-seconds* 30)
17 
18 (defmacro time-step (unix-time)
19  `(floor (- ,unix-time *time-zero*) *time-step-in-seconds*))
20 
21 (defun totp (key-hexstring &optional (offset 0) (time (- (get-universal-time) .unix-epoch-zero. offset)))
22  (hotp key-hexstring (time-step time)))