220 12599 <54035829.8060600@gmx.de> article
Path: news.gmane.org!not-for-mail
From: Markus Mayer <lotharlutz@gmx.de>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Cryptographic hash functions reloaded [was
 Interest in cryptographic functions within the standard library]
Date: Sun, 31 Aug 2014 19:15:21 +0200
Lines: 84
Approved: news@gmane.org
Message-ID: <54035829.8060600@gmx.de>
References: <53F8F620.3090701@gmx.de> <53F9AAF7.8030602@gmx.de> <53FA1DE1.9000603@gmx.de>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Trace: ger.gmane.org 1409505333 21446 80.91.229.3 (31 Aug 2014 17:15:33 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 31 Aug 2014 17:15:33 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDL3H4GM24GBBK5QRWQAKGQEW7R4RGQ@isocpp.org Sun Aug 31 19:15:26 2014
Return-path: <std-proposals+bncBDL3H4GM24GBBK5QRWQAKGQEW7R4RGQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f198.google.com ([209.85.212.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDL3H4GM24GBBK5QRWQAKGQEW7R4RGQ@isocpp.org>)
	id 1XO8ir-0007RA-6O
	for gclcip-std-proposals@m.gmane.org; Sun, 31 Aug 2014 19:15:25 +0200
Original-Received: by mail-wi0-f198.google.com with SMTP id ho1sf3018191wib.9
        for <gclcip-std-proposals@m.gmane.org>; Sun, 31 Aug 2014 10:15:24 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-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;
        bh=QRHJAfd5cC924kxU48VJG95WC+0IsVIbdQc0xCRFOCw=;
        b=UfdO/D0sAw1Qi2yOmh6LAmoQsFCiejyKe5sucq6GY5eRAEf3T4z/BOXjXb0imIvrdg
         ppCUWrSFtabzaOlgrxQ53nqHuJNnIJEQw2FgFgEucK2+sbMNuXS1/vlJ3vKl43tAdoRE
         CR106WYieTUBKYquqGCjbk73mi3aotDnY3s6B4tcnUfLMEwbnaZ0TQjep3r2JaLpvVTM
         P+YBR83ZGrb1NneH9TZMSo5LZTPLa5VMf21fxRg5dOleZFqG58TSfrdnMuYaw2MF/qo5
         B6ItDomKmBS+ztkug43XNqwYuKpjmCjKL3sm2eSF49ECicEngmRvZyNayBw+W87pPnoY
         fZZg==
X-Gm-Message-State: ALoCoQl96exc2vfM5RS3GfP0qBnHM+x9osoYqbYBDnBC2JdNNQ/5AHnRMnddc0ZSEM4MlZUoCaNv
X-Received: by 10.194.79.34 with SMTP id g2mr218914wjx.3.1409505324619;
        Sun, 31 Aug 2014 10:15:24 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.115.231 with SMTP id jr7ls364199lab.102.gmail; Sun, 31 Aug
 2014 10:15:22 -0700 (PDT)
X-Received: by 10.112.157.132 with SMTP id wm4mr3027006lbb.89.1409505322948;
        Sun, 31 Aug 2014 10:15:22 -0700 (PDT)
Original-Received: from mout.gmx.net (mout.gmx.net. [212.227.15.18])
        by mx.google.com with ESMTPS id y10si8596630laj.52.2014.08.31.10.15.22
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 31 Aug 2014 10:15:22 -0700 (PDT)
Received-SPF: pass (google.com: domain of lotharlutz@gmx.de designates 212.227.15.18 as permitted sender) client-ip=212.227.15.18;
Original-Received: from [192.168.178.22] ([92.194.87.220]) by mail.gmx.com (mrgmx002)
 with ESMTPSA (Nemesis) id 0M4nYT-1YMPTz0jsL-00yves for
 <std-proposals@isocpp.org>; Sun, 31 Aug 2014 19:15:22 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0
In-Reply-To: <53FA1DE1.9000603@gmx.de>
X-Provags-ID: V03:K0:hdyzc3Nq02a8keiFVBk3p78Q5dVQL2R4SIb4UQ+6K8ElbVKCykv
 2pDD+I5KGrzXubNctLa6wSlbusFkym9Y+wMdSJAaBQlQsJmD54ttM+2Qup/VwKe0PnYhQu3
 vBXq0meOp+NtokiOx+Ig1W5ZMJ78lbIs6BmohNACn8io7uOkSXVU6J9p9oqwlATVQuT9UTx
 kN7UDFh5Tzx0LOwkB0aKQ==
X-UI-Out-Filterresults: notjunk:1;
X-Original-Sender: lotharlutz@gmx.de
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of lotharlutz@gmx.de designates 212.227.15.18 as permitted sender) smtp.mail=lotharlutz@gmx.de
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:12599
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/12599>

Thanks for your valuable feedback.

If checked the proposal for its feasibility for different byte-orders 
and for odd-sized architectures. Here are my findings and fixes:
- The result type is a array of std::uint_least8_t. Each cell contains a 
value between 0 and 255 (including 0 and 255). This can be represented 
by every architecture. Byte-order is no problem because it is sequence 
of single bytes.

- process_bytes take an address and a count. It hashes 'count' bytes 
(which have CHAR_BITS bits) starting a the given address in the order 
they are represented in memory. Every bit of this range contributes to 
the result. No byte-order conversion is performed. It is not the job of 
the hash function. It must be handled by an upper layer.

With the current proposal your are unable to hash a range that is not a 
multiple of a byte. It is possible to add a process_bits(unsigned char 
byte, std::size_t bit_count), but I thinks it is not that useful. We can 
add it once we have experience how it is actually used.


Regarding the 'const void* buffer vs. const unsinged char* buffer':
I think 'const unsigned char*' is clearer, because it requires an 
explicit cast. This is like a warning sign "Warning: you have to care 
about byte-order, padding and other stuff by yourself!".

The 'const void*' solution is more convenient when you want to hash a 
struct or a single variable.

I came to the conclusion that it depends on how common the 'interprete 
this as a byte range' case is. I tried to come up with some actual 
numbers, but my google fun isn't strong enough.

For my usage in 80% I do not have a unsigned char*. But what about your 
experience?


Other changes:
- Add a constexpr block_size. It specifies the smallest number of bytes 
(having CHAR_BITS bits), the buffer length have to be to achieve optimal 
performance. It is implementation defined, because it is a property of 
the specific implementation.


Open questions:
- process_bytes vs. operator(), or keep both
- const void* buffer vs. const unsinged char* buffer

class hash_function
{
public:
    typedef std::array<std::uint_least8_t, ALGORITHM_DEFINED> result_type;
    static constexpr std::size_t block_size = IMPLEMENTATION_DEFINED;
    //Default contructable
    //Copyable
    //Moveable

    hash_function& process_bytes( const void *buffer, std::size_t 
byte_count);

    hash_function& operator() ( const void *buffer, std::size_t byte_count);

    void reset();

    result_type hash_value() const;

};

template<class InputIt, class Hasher>
process_blockwise(InputIt first, InputIt last, Hasher& hash_fn);

//Maybe add process_blockwise_n

regards
    Markus

-- 

--- 
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 email 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-proposals/.

.
