[PATCH] Add class java.security.StandardMessageDigests

Xuelei Fan xuelei.fan at oracle.com
Mon May 5 12:31:28 UTC 2014


Comparing with the call:
   MessageDigest md = MessageDigest.getInstance("SHA-1");

What's the benefit of the following call?

   MessageDigest md = StandardMessageDigests.newSHA1();

What's the context that this new class is supposed to use?

Thanks & Regards,
Xuelei

On 5/5/2014 7:51 PM, Florian Weimer wrote:
> On 03/24/2014 05:30 PM, Florian Weimer wrote:
>> This CR adds a new class java.security.StandardMessageDigests:
>>
>> <http://fweimer.fedorapeople.org/openjdk/standard-message-digests/>
>>
>> Could I get a bug number if this change is fine in principle?
>>
>> Cryptographic hash functions are frequently used directly, often for
>> non-cryptographic purposes, so I think it makes sense to provide a
>> convenient way to access implementations for the most common hashes. The
>> new class follows the java.nio.charset.StandardCharsets precedent
>> (separate class, "Standard" in the name).
>>
>> I deliberately did not include support for MD5.  It would be nice if we
>> could drop the NoSuchAlgorithmException, but this would be problematic
>> once there are providers that do not support SHA-1.
>>
>> Instantiating digest objects through cloning should be quite a bit
>> faster than the provider route (but I measured this some time ago only,
>> so these results could be outdated by now).
> 
> Ping?  This change proposal is in response to an earlier discussion:
> 
> <http://mail.openjdk.java.net/pipermail/security-dev/2010-December/002531.html>
> 
> 
> I fixed the webrev so that the fast path actually runs, and now JMH
> reports a speedup:
> 
> Benchmark                                       Mode   Samples Mean  
> Mean error    Units
> o.o.j.b.StandardMessageDigestsBenchmark.get    thrpt       200
> 1650.350       53.388   ops/ms
> o.o.j.b.StandardMessageDigestsBenchmark.smd    thrpt       200
> 1814.137       59.414   ops/ms
> 




More information about the security-dev mailing list