220 12469 <833080F6-5FAB-4C71-860D-DB6BFA8CF2EF@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Howard Hinnant <howard.hinnant@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Cryptographic hash functions reloaded [was
 Interest in cryptographic functions within the standard library]
Date: Sun, 24 Aug 2014 19:21:17 -0400
Lines: 74
Approved: news@gmane.org
Message-ID: <833080F6-5FAB-4C71-860D-DB6BFA8CF2EF@gmail.com>
References: <53F8F620.3090701@gmx.de> <B33BCE97-51A4-4880-9C26-5347D6C8A02A@gmail.com> <53F989E9.5090701@gmx.net> <B0F486D7-A068-4A30-8D5E-69E826F1C943@gmail.com> <dc3e5ee2-bc65-426a-91f1-90d875fd3422@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1408922492 21566 80.91.229.3 (24 Aug 2014 23:21:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 24 Aug 2014 23:21:32 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCK2HM4L6YERB4PG5GPQKGQEED2UE5Q@isocpp.org Mon Aug 25 01:21:24 2014
Return-path: <std-proposals+bncBCK2HM4L6YERB4PG5GPQKGQEED2UE5Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f70.google.com ([209.85.218.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCK2HM4L6YERB4PG5GPQKGQEED2UE5Q@isocpp.org>)
	id 1XLh6A-0001Lt-TZ
	for gclcip-std-proposals@m.gmane.org; Mon, 25 Aug 2014 01:21:23 +0200
Original-Received: by mail-oi0-f70.google.com with SMTP id u20sf66860030oif.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 24 Aug 2014 16:21:21 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:subject:from:in-reply-to:date
         :message-id:references:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type:content-transfer-encoding;
        bh=qWtHcziI6hzRBLBcBfTqw5ppahaXQ+jh+5A5M8fates=;
        b=KEpFv4q/VWx3mXp0rfrDDRlshtMylDdngMBtjcx+S1oz9fgoo8xkQE9B4AoQtW7FMz
         ffxp4oXLdFrsM15asUAR442qHdOTq8Is4UgGv65D7jAMmKLzMzEvLZlJFihxZ50CgWdF
         /20V+EHNqmGeUW0Yks973WbYimj9buN8HaSZdKX6T1QfCKWwiOk+G5+x/LKKVeHYSwih
         ZD89ZdusSrVuGNyYrOmCFY8vRxAWYZ81/zt+l7fUdoJ1kDiO5tZTWHgxhUHyYlVof28T
         t7+O0e7ovK/W7LRPKnn5NPoGNT7Eck7tm/iZTGtm9w8BZQUk7w7JVG64dACqu8RyWpTz
         vzdA==
X-Gm-Message-State: ALoCoQnmA8NfeoK3XO+ViSiy4d02nmw+uOLCjcvxFG9J8gv7B9dxDYz/BREwI1beY3yvsaAs1mcb
X-Received: by 10.42.97.138 with SMTP id o10mr2031963icn.33.1408922481708;
        Sun, 24 Aug 2014 16:21:21 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.164.169 with SMTP id yr9ls953299igb.11.canary; Sun, 24 Aug
 2014 16:21:20 -0700 (PDT)
X-Received: by 10.43.75.7 with SMTP id yy7mr238585icb.15.1408922480857;
        Sun, 24 Aug 2014 16:21:20 -0700 (PDT)
Original-Received: from mail-ig0-x236.google.com (mail-ig0-x236.google.com [2607:f8b0:4001:c05::236])
        by mx.google.com with ESMTPS id qc5si14769688icb.107.2014.08.24.16.21.20
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 24 Aug 2014 16:21:20 -0700 (PDT)
Received-SPF: pass (google.com: domain of howard.hinnant@gmail.com designates 2607:f8b0:4001:c05::236 as permitted sender) client-ip=2607:f8b0:4001:c05::236;
Original-Received: by mail-ig0-f182.google.com with SMTP id c1so1992968igq.15
        for <std-proposals@isocpp.org>; Sun, 24 Aug 2014 16:21:20 -0700 (PDT)
X-Received: by 10.50.176.202 with SMTP id ck10mr12207456igc.2.1408922480735;
        Sun, 24 Aug 2014 16:21:20 -0700 (PDT)
Original-Received: from [10.0.1.2] (cpe-24-58-234-96.twcny.res.rr.com. [24.58.234.96])
        by mx.google.com with ESMTPSA id ig14sm30123391igb.13.2014.08.24.16.21.19
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 24 Aug 2014 16:21:19 -0700 (PDT)
In-Reply-To: <dc3e5ee2-bc65-426a-91f1-90d875fd3422@isocpp.org>
X-Mailer: Apple Mail (2.1878.6)
X-Original-Sender: howard.hinnant@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of howard.hinnant@gmail.com designates 2607:f8b0:4001:c05::236 as
 permitted sender) smtp.mail=howard.hinnant@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:12469
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/12469>


On Aug 24, 2014, at 5:01 PM, Myriachan <myriachan@gmail.com> wrote:

> On Sunday, August 24, 2014 10:39:58 AM UTC-7, Howard Hinnant wrote:
>>> I agree there is a choice for std::uhash<> when
>>> converting a, say, "int" to a sequence of "unsigned char"s whether to
>>> perform endian conversion or not, and that influences the cross-platfor=
m
>>> reproducibility of the hash when e.g. hashing a sequence of "int"
>>> values.
>=20
> Sadly, C++ still supports non-two's-complement architectures, so what hap=
pens when you hash a negative int?

I presume the int's bytes would be hashed just like any other scalar.

>=20
>> This is the only role of the endian specifier, which can be any one of:
>>=20
>>   static constexpr std::endian endian =3D std::endian::big;
>>   static constexpr std::endian endian =3D std::endian::little;
>>   static constexpr std::endian endian =3D std::endian::native;
>>=20
>> std::endian::native will be equal to one of std::endian::little or std::=
endian::big.  These enums are nothing more than the C++ version of the alre=
ady popular macros:  __BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_BIG_E=
NDIAN__.
>=20
> What about PDP-endian?

I stand corrected.  On PDP-endian std::endian::native has a value that is n=
ot equal to either of std::endian::little or std::endian::big.  If the Hash=
Algorithm specifies little or big endian, the implementation is required to=
 map the bytes of the int (or whatever) to little or big endian prior to fe=
eding it to the HashAlgorithm.  For std::endian::big, this is the exact sam=
e thing as inserting a call to hton() prior to the HashAlgorithm.

> By the late 1990s, not only DEC but most of the New England computer indu=
stry which had been built around minicomputers similar to the PDP-11 collap=
sed in the face of microcomputer-based workstations and servers.

>> A correct hash_append will be chosen (at compile time), which for scalar
>> types that have endian issues, may or may not reverse the bytes of t
>> depending on what the hash algorithm has requested, and what the
>> platform's native endian is.
>=20
> Does this mechanism support handling multiple scalars at once?  On some s=
ystems, byte swapping may be more efficient if does as vector math.

An implementation could conceivably create a hash_append overload on arrays=
 of int and optimize that.

>=20
>> See https://github.com/HowardHinnant/hash_append for complete code.
>=20
> Its SHA-256 code is unsuitable for any platform for which "int" is larger=
 than 32 bits.  It will have undefined behavior in those cases due to signe=
d integer overflow or shifting left a negative number.

Thanks, I'll put in a static_assert.

Howard

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.
