From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id ACE4317D9944 for ; Tue, 29 Jul 2014 11:01:58 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 360E1B5D89D for ; Tue, 29 Jul 2014 10:39:46 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 690CD97A826 for ; Tue, 29 Jul 2014 10:39:47 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nz_bUXxgQjiI for ; Tue, 29 Jul 2014 10:39:47 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 05EDC97A820 for ; Tue, 29 Jul 2014 10:39:47 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id AEE2895243E for ; Tue, 29 Jul 2014 10:39:45 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 16FFE120433; Tue, 29 Jul 2014 10:39:28 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 5988112041F for ; Tue, 29 Jul 2014 10:39:25 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=UjZvTWI4HdUIummhY4ojPT9EMzM=; b=pUs61dp5ObSKBCYGzW Z1IwsgPMTULZFC6BFqFEh8mxEleYtOt07XXncVswhSS+ZQbWW6kWpRrtmT2vJSHX It0YffQsKRve4m0rmpNtphzyiH8OZytE4lalEFmHcFPPbgQXIo4AlP66GyFaak2f F91m790Q58XF3LFrE+id7rHp8= Received: by mf192.sendgrid.net with SMTP id mf192.37893.53D6FB4943 2014-07-29 01:39:21.871826115 +0000 UTC Received: from herokuapp.com (ec2-54-90-18-226.compute-1.amazonaws.com [54.90.18.226]) by ismtpd-016.iad1.sendgrid.net (SG) with ESMTP id 1477fc55000.68c.2eccb5 Tue, 29 Jul 2014 01:39:03 +0000 (GMT) Date: Tue, 29 Jul 2014 01:39:03 +0000 From: arrtchiu@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 38265 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 10098 X-Redmine-Issue-Author: arrtchiu X-Redmine-Sender: arrtchiu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: OOF Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4ygJUFHhxFz7mFVvoLouuFIZAbAvF8Kp+hZkuR9zU63bGIZo+X/IHJ+SA1SXcHFODzA7rTzFYEzgq17EFTmX9iuG5iwtsetUGSTjb8d3A61evZDgdaSAh9jf8PP+NbFak= X-ML-Name: ruby-core X-Mail-Count: 64107 Subject: [ruby-core:64107] [ruby-trunk - Feature #10098] [PATCH] Timing-safe string comparison for OpenSSL::HMAC X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #10098 has been updated by Matt U. Thanks for the feedback! Nobuyoshi Nakada wrote: > * Indent style mismatch > * Should try to convert the argument with `StringValue()` Will fix - sorry, this is my first contribution! > * Why HMAC only? Other digests don't need it? Good point, I thought since HMAC is for both redundancy and message authentication it made most sense on HMAC rather than all digests - but - I can see there would be use-cases for comparing other digests or other strings in a timing-safe manner. > * Probably we should provide timing-safe binary compare function? I think this makes the most sense :) How about moving this to a method on `String` - e.g. `String#slow_eql?` or `String::timing_safe_eql?`? I'm terrible at naming things :) ---------------------------------------- Feature #10098: [PATCH] Timing-safe string comparison for OpenSSL::HMAC https://bugs.ruby-lang.org/issues/10098#change-48118 * Author: Matt U * Status: Open * Priority: Normal * Assignee: * Category: ext/openssl * Target version: next minor ---------------------------------------- I could be totally wrong, but it seems the standard library doesn't provide a reliable way of comparing hashes in constant-time. * The docs for `OpenSSL::HMAC` encourage the use of `Digest#to_s` (see: http://ruby-doc.org/stdlib-2.1.0/libdoc/openssl/rdoc/OpenSSL/HMAC.html#method-c-new ) * Ruby's string comparison uses memcmp, which isn't timing safe (see: http://rxr.whitequark.org/mri/source/string.c#2382 ) With this patch I propose to add an additional method, `OpenSSL::HMAC#verify`, which takes a binary string with a digest and compares it against the computed hash. ---Files-------------------------------- hmac-timing.patch (2.5 KB) hmac-timing.patch (2.48 KB) -- https://bugs.ruby-lang.org/