1 ;;; hmac-util.el --- Utilities for HMAC functions.
3 ;; Copyright (C) 1999 Shuhei KOBAYASHI
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: HMAC, RFC 2104
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or
13 ;; (at your option) any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (defsubst hmac-hex-to-int (chr)
30 (cond ((<= ?a chr) (+ (- chr ?a) 10))
31 ((<= ?A chr) (+ (- chr ?A) 10))
32 ((<= ?0 chr) (- chr ?0))))
34 (defsubst hmac-int-to-hex (num)
35 (aref "0123456789abcdef" num))
37 (defun hmac-unhex-string (str)
38 (let* ((len (length str))
39 (dst (make-string (/ len 2) 0))
42 (aset dst idx (logior (lsh (hmac-hex-to-int (aref str pos)) 4)
43 (hmac-hex-to-int (aref str (1+ pos)))))
48 (defun hmac-hex-string (str)
49 (let* ((len (length str))
50 (dst (make-string (* len 2) 0))
53 (aset dst idx (hmac-int-to-hex (logand (lsh (aref str pos) -4) 15)))
55 (aset dst idx (hmac-int-to-hex (logand (aref str pos) 15)))
62 ;;; hmac-util.el ends here.