8157579: com/sun/crypto/provider/Mac/MacClone.java failed on solaris12(sparcv9 and x86)

Changed the MAC impl to fall back to SUN provider (or through provider list) if the most preferred impl does not support cloning

Reviewed-by: vinnie, mullan
This commit is contained in:
Valerie Peng 2016-08-12 00:39:34 +00:00
parent 27492ab667
commit 16b80b792d

@ -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 @@ abstract class HmacCore extends MacSpi implements Cloneable {
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];
@ -64,14 +91,6 @@ abstract class HmacCore extends MacSpi implements Cloneable {
first = true;
}
/**
* 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.
*