From patchwork Mon Oct 29 10:28:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 194946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 873712C008B for ; Mon, 29 Oct 2012 21:28:18 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352111298; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=cD0eqSq3OIdaUYGtZhYd iKz8/QY=; b=k0zwfipINuD8wNgooaqDq/o4iSI4urO+WEZqEwV3b2v8ADpwtHrG 7HljhiBp6UntKxF9RGRH+8MC3J5GO9cvMW3UKZAiujajdhzdNpyty2SxP08850GO q9R+XGI78gThcQggavN+A9unpP/h1fkNCW1Kwqctn2SmfG9oGd4WXnM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=bmMe3hu1kExglrFmYA70wHbtBBubc4bc7dnKmwjXa+rlR4v+FxdNH4IxU3BQlP Wl/yx80ggKZsFSTLWM+M37MYfgtYk/SbwP8XBVaN6SYu9wQNylnRXkbcFcpU9phm u0NfITUMkOqB/0H0QIWRsIQGG7I2imEJbYN6Dirhtl+jc=; Received: (qmail 25275 invoked by alias); 29 Oct 2012 10:28:13 -0000 Received: (qmail 25267 invoked by uid 22791); 29 Oct 2012 10:28:12 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 29 Oct 2012 10:28:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D12F81C79C5; Mon, 29 Oct 2012 06:28:02 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id hS3e1CbsV2Zs; Mon, 29 Oct 2012 06:28:02 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id B73BF1C780A; Mon, 29 Oct 2012 06:28:02 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id B385E3FF09; Mon, 29 Oct 2012 06:28:02 -0400 (EDT) Date: Mon, 29 Oct 2012 06:28:02 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Pascal Obry Subject: [Ada] Add support for returning binary message digest Message-ID: <20121029102802.GA30545@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org If a binary digest is needed it is a waste of time to recompute it from the string encoded digest. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-10-29 Pascal Obry * g-sechas.adb, g-sechas.ads: (Binary_Message_Digest): New subtype. (Digest): New versions returning a Binary_Message_Digest. (Wide_Digest): Likewise. Index: g-sechas.adb =================================================================== --- g-sechas.adb (revision 192920) +++ g-sechas.adb (working copy) @@ -184,6 +184,30 @@ return Digest (C); end Digest; + function Digest (C : Context) return Binary_Message_Digest is + Hash_Bits : Stream_Element_Array + (1 .. Stream_Element_Offset (Hash_Length)); + begin + Final (C, Hash_Bits); + return Hash_Bits; + end Digest; + + function Digest (S : String) return Binary_Message_Digest is + C : Context; + begin + Update (C, S); + return Digest (C); + end Digest; + + function Digest + (A : Stream_Element_Array) return Binary_Message_Digest + is + C : Context; + begin + Update (C, A); + return Digest (C); + end Digest; + ----------- -- Final -- ----------- @@ -325,6 +349,13 @@ return Digest (C); end Wide_Digest; + function Wide_Digest (W : Wide_String) return Binary_Message_Digest is + C : Context; + begin + Wide_Update (C, W); + return Digest (C); + end Wide_Digest; + end H; ------------------------- Index: g-sechas.ads =================================================================== --- g-sechas.ads (revision 192920) +++ g-sechas.ads (working copy) @@ -156,6 +156,22 @@ Word_Length : constant Natural := Hash_State.Word'Size / 8; Hash_Length : constant Natural := Hash_Words * Word_Length; + subtype Binary_Message_Digest is + Stream_Element_Array (1 .. Stream_Element_Offset (Hash_Length)); + -- The fixed-length byte array returned by Digest, providing + -- the hash in binary representation. + + function Digest (C : Context) return Binary_Message_Digest; + -- Return hash for the data accumulated with C + + function Digest (S : String) return Binary_Message_Digest; + function Wide_Digest (W : Wide_String) return Binary_Message_Digest; + function Digest + (A : Stream_Element_Array) return Binary_Message_Digest; + -- These functions are equivalent to the corresponding Update (or + -- Wide_Update) on a default initialized Context, followed by Digest + -- on the resulting Context. + subtype Message_Digest is String (1 .. 2 * Hash_Length); -- The fixed-length string returned by Digest, providing the hash in -- hexadecimal representation.