author | valeriep |
Fri, 12 Aug 2016 00:39:34 +0000 | |
changeset 40267 | 5936f75b27c1 |
parent 40266 | d198987d85e1 |
child 40268 | 5d2c9cf567a7 |
jdk/src/java.base/share/classes/com/sun/crypto/provider/HmacCore.java | file | annotate | diff | comparison | revisions |
--- a/jdk/src/java.base/share/classes/com/sun/crypto/provider/HmacCore.java Fri Aug 12 00:10:07 2016 +0000 +++ b/jdk/src/java.base/share/classes/com/sun/crypto/provider/HmacCore.java Fri Aug 12 00:39:34 2016 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,10 +53,37 @@ private final int blockLen; /** - * Standard constructor, creates a new HmacCore instance using the - * specified MessageDigest object. + * Standard constructor, creates a new HmacCore instance instantiating + * a MessageDigest of the specified name. */ - HmacCore(MessageDigest md, int bl) { + HmacCore(String digestAlgo, int bl) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance(digestAlgo); + if (!(md instanceof Cloneable)) { + // use SUN provider if the most preferred one does not support + // cloning + Provider sun = Security.getProvider("SUN"); + if (sun != null) { + md = MessageDigest.getInstance(digestAlgo, sun); + } else { + String noCloneProv = md.getProvider().getName(); + // if no Sun provider, use provider list + Provider[] provs = Security.getProviders(); + for (Provider p : provs) { + try { + if (!p.getName().equals(noCloneProv)) { + MessageDigest md2 = + MessageDigest.getInstance(digestAlgo, p); + if (md2 instanceof Cloneable) { + md = md2; + break; + } + } + } catch (NoSuchAlgorithmException nsae) { + continue; + } + } + } + } this.md = md; this.blockLen = bl; this.k_ipad = new byte[blockLen]; @@ -65,14 +92,6 @@ } /** - * Standard constructor, creates a new HmacCore instance instantiating - * a MessageDigest of the specified name. - */ - HmacCore(String digestAlgorithm, int bl) throws NoSuchAlgorithmException { - this(MessageDigest.getInstance(digestAlgorithm), bl); - } - - /** * Returns the length of the HMAC in bytes. * * @return the HMAC length in bytes.