/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* KeyAgreement implementation for ECDH.
*
* @author Andreas Sterbenz
* @since 1.6
*/
// token instance
// algorithm name
// mechanism id
private final long mechanism;
// private key, if initialized
// encoded public point, non-null between doPhase() and generateSecret() only
private byte[] publicValue;
// length of the secret to be derived
private int secretLen;
super();
}
// see JCE spec
throws InvalidKeyException {
if (key instanceof PrivateKey == false) {
throw new InvalidKeyException
("Key must be instance of PrivateKey");
}
publicValue = null;
}
// see JCE spec
throw new InvalidAlgorithmParameterException
("Parameters not supported");
}
}
// see JCE spec
throws InvalidKeyException, IllegalStateException {
if (privateKey == null) {
throw new IllegalStateException("Not initialized");
}
if (publicValue != null) {
throw new IllegalStateException("Phase already executed");
}
if (lastPhase == false) {
throw new IllegalStateException
("Only two party agreement supported, lastPhase must be true");
}
if (key instanceof ECPublicKey == false) {
throw new InvalidKeyException
("Key must be a PublicKey with algorithm EC");
}
return null;
}
// see JCE spec
throw new IllegalStateException("Not initialized correctly");
}
try {
};
attributes = new CK_ATTRIBUTE[] {
new CK_ATTRIBUTE(CKA_VALUE)
};
return secret;
} catch (PKCS11Exception e) {
throw new ProviderException("Could not derive key", e);
} finally {
publicValue = null;
}
}
// see JCE spec
}
byte[] secret = engineGenerateSecret();
}
// see JCE spec
throw new NoSuchAlgorithmException("Algorithm must not be null");
}
throw new NoSuchAlgorithmException
("Only supported for algorithm TlsPremasterSecret");
}
return nativeGenerateSecret(algorithm);
}
throw new IllegalStateException("Not initialized correctly");
}
long keyType = CKK_GENERIC_SECRET;
try {
};
new CK_ATTRIBUTE(CKA_VALUE_LEN),
};
return key;
} catch (PKCS11Exception e) {
throw new InvalidKeyException("Could not derive key", e);
} finally {
publicValue = null;
}
}
}