From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/66878 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel,gmane.emacs.gnus.general Subject: Re: rfc2104 change on 2008-02-01 Date: Fri, 25 Apr 2008 18:03:58 +0200 Organization: sometimes Message-ID: <87od7xq5u9.fsf@ambire.localdomain> References: <87iqy6cj1f.fsf@mocca.josefsson.org> <87od7yrr1k.fsf@mocca.josefsson.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1209139807 20138 80.91.229.12 (25 Apr 2008 16:10:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 25 Apr 2008 16:10:07 +0000 (UTC) Cc: ding@gnus.org To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 25 18:10:43 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JpQVN-0004cs-FW for ged-emacs-devel@m.gmane.org; Fri, 25 Apr 2008 18:10:33 +0200 Original-Received: from localhost ([127.0.0.1]:36172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JpQUh-0004SR-Ca for ged-emacs-devel@m.gmane.org; Fri, 25 Apr 2008 12:09:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JpQST-0003Kx-EH for emacs-devel@gnu.org; Fri, 25 Apr 2008 12:07:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JpQSR-0003K3-Qc for emacs-devel@gnu.org; Fri, 25 Apr 2008 12:07:33 -0400 Original-Received: from [199.232.76.173] (port=45990 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JpQSR-0003Jx-Lp for emacs-devel@gnu.org; Fri, 25 Apr 2008 12:07:31 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JpQSQ-0005GZ-U6 for emacs-devel@gnu.org; Fri, 25 Apr 2008 12:07:31 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JpQSH-0002Yz-L5 for emacs-devel@gnu.org; Fri, 25 Apr 2008 16:07:21 +0000 Original-Received: from 151.61.140.193 ([151.61.140.193]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Apr 2008 16:07:21 +0000 Original-Received: from ttn by 151.61.140.193 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Apr 2008 16:07:21 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 151 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 151.61.140.193 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:UzPJ4Qg+jHpOUBHsCOiaLuVzusA= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:95943 gmane.emacs.gnus.general:66878 Archived-At: --=-=-= () Simon Josefsson () Fri, 25 Apr 2008 15:40:39 +0200 I just tried my proposed change with Emacs 23, and it didn't work. How about changing: (encode-coding-string foo 'iso-latin-1) to: (string-make-unibyte foo) ? Better yet, attached is a rewrite for speed (plus some incidental Commentary correction). thi ___________________________________________________________ --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=rfc2104.el Content-Description: \"high-performance emacs lisp\"? hmmm... ;;; rfc2104.el --- RFC2104 Hashed Message Authentication Codes ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. ;; Author: Simon Josefsson ;; Keywords: mail ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;;; This is a high performance implementation of RFC2104. ;;; ;;; Example: ;;; ;;; (require 'md5) ;;; (rfc2104-hash 'md5 64 16 "Jefe" "what do ya want for nothing?") ;;; "750c783e6ab0b503eaa86e310a5db738" ;;; ;;; (require 'sha1) ;;; (rfc2104-hash 'sha1 64 20 "Jefe" "what do ya want for nothing?") ;;; "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79" ;;; ;;; 64 is block length of hash function (64 for MD5 and SHA), 16 is ;;; resulting hash length (16 for MD5, 20 for SHA). ;;; ;;; Tested with Emacs 20.2 and XEmacs 20.3. ;;; ;;; Test case reference: RFC 2202. ;;; Release history: ;;; ;;; 1998-08-16 initial release posted to gnu.emacs.sources ;;; 1998-08-17 use append instead of char-list-to-string ;;; 1998-08-26 don't require hexl ;;; 1998-09-25 renamed from hmac.el to rfc2104.el, also renamed functions ;;; 1999-10-23 included in pgnus ;;; 2000-08-15 `rfc2104-hexstring-to-bitstring' ;;; 2000-05-12 added sha-1 example, added test case reference ;;; 2003-11-13 change rfc2104-hexstring-to-bitstring to ...-byte-list ;;; 2008-04-25 rewrite rfc2104-hash for speed ;;; Code: (eval-when-compile (require 'cl)) ;; Magic character for inner HMAC round. 0x36 == 54 == '6' (defconst rfc2104-ipad ?\x36) ;; Magic character for outer HMAC round. 0x5C == 92 == '\' (defconst rfc2104-opad ?\x5C) (defconst rfc2104-nybbles (let ((v (make-vector ;; Find upper bound to save some space. (1+ (max ?0 ?9 ?a ?f ?A ?F)) ;; Use non-numeric default to catch bogus hex strings. nil)) (ls '((?0 . 0) (?a . 10) (?A . 10) (?1 . 1) (?b . 11) (?B . 11) (?2 . 2) (?c . 12) (?C . 12) (?3 . 3) (?d . 13) (?D . 13) (?4 . 4) (?e . 14) (?E . 14) (?5 . 5) (?f . 15) (?F . 15) (?6 . 6) (?7 . 7) (?8 . 8) (?9 . 9)))) (while ls (aset v (caar ls) (cdar ls)) (setq ls (cdr ls))) v)) (defun rfc2104-hash (hash block-length hash-length key text) (let* (;; if key is longer than B, reset it to HASH(key) (key (if (> (length key) block-length) (funcall hash key) key)) (len (length key)) (ipad (make-string block-length rfc2104-ipad)) (opad (make-string (+ block-length hash-length) rfc2104-opad)) c partial) ;; Prefix *pad with key, appropriately XORed. (do ((i 0 (1+ i))) ((= len i)) (setq c (aref key i)) (aset ipad i (logxor rfc2104-ipad c)) (aset opad i (logxor rfc2104-opad c))) ;; Perform inner hash. (setq partial (string-make-unibyte (funcall hash (concat ipad text)))) ;; Pack latter part of opad. (do ((r 0 (+ 2 r)) (w block-length (1+ w))) ((= (* 2 hash-length) r)) (aset opad w (+ (* 16 (aref rfc2104-nybbles (aref partial r))) ( aref rfc2104-nybbles (aref partial (1+ r)))))) ;; Perform outer hash. (string-make-unibyte (funcall hash opad)))) (provide 'rfc2104) ;;; arch-tag: cf671d5c-a45f-4a09-815e-704e59e43950 ;;; rfc2104.el ends here --=-=-=--