Commit 6f5ce93b by Andreas Tobler Committed by Andreas Tobler

[multiple changes]

2004-09-21  Andreas Tobler  <a.tobler@schweiz.ch>

	Import the big Crypto/Jessie/Security merge from Classpath.

	* Makefile.am: Add imported files.
	* Makefile.in: Regenerate.

	2004-08-14  Casey Marshall <csm@gnu.org>

	The Big Crypto Merge of 2004.

	* javax/security/auth/x500/X500Principal.java: Replaced with GNU
	Crypto's version.

	Files imported from GNU Crypto.
	* javax/crypto/BadPaddingException.java
	* javax/crypto/Cipher.java
	* javax/crypto/CipherInputStream.java
	* javax/crypto/CipherOutputStream.java
	* javax/crypto/CipherSpi.java
	* javax/crypto/EncryptedPrivateKeyInfo.java
	* javax/crypto/ExemptionMechanism.java
	* javax/crypto/ExemptionMechanismException.java
	* javax/crypto/ExemptionMechanismSpi.java
	* javax/crypto/IllegalBlockSizeException.java
	* javax/crypto/KeyAgreement.java
	* javax/crypto/KeyAgreementSpi.java
	* javax/crypto/KeyGenerator.java
	* javax/crypto/KeyGeneratorSpi.java
	* javax/crypto/Mac.java
	* javax/crypto/MacSpi.java
	* javax/crypto/Makefile.am
	* javax/crypto/NoSuchPaddingException.java
	* javax/crypto/NullCipher.java
	* javax/crypto/NullCipherImpl.java
	* javax/crypto/SealedObject.java
	* javax/crypto/SecretKey.java
	* javax/crypto/SecretKeyFactory.java
	* javax/crypto/SecretKeyFactorySpi.java
	* javax/crypto/ShortBufferException.java
	* javax/crypto/interfaces/DHKey.java
	* javax/crypto/interfaces/DHPrivateKey.java
	* javax/crypto/interfaces/DHPublicKey.java
	* javax/crypto/interfaces/PBEKey.java
	* javax/crypto/spec/DESKeySpec.java
	* javax/crypto/spec/DESedeKeySpec.java
	* javax/crypto/spec/DHGenParameterSpec.java
	* javax/crypto/spec/DHParameterSpec.java
	* javax/crypto/spec/DHPrivateKeySpec.java
	* javax/crypto/spec/DHPublicKeySpec.java
	* javax/crypto/spec/IvParameterSpec.java
	* javax/crypto/spec/PBEKeySpec.java
	* javax/crypto/spec/PBEParameterSpec.java
	* javax/crypto/spec/RC2ParameterSpec.java
	* javax/crypto/spec/RC5ParameterSpec.java
	* javax/crypto/spec/SecretKeySpec.java
	* javax/security/auth/AuthPermission.java
	* javax/security/auth/DestroyFailedException.java
	* javax/security/auth/Destroyable.java
	* javax/security/auth/Policy.java
	* javax/security/auth/PrivateCredentialPermission.java
	* javax/security/auth/RefreshFailedException.java
	* javax/security/auth/Refreshable.java
	* javax/security/auth/Subject.java
	* javax/security/auth/SubjectDomainCombiner.java
	* javax/security/auth/callback/Callback.java
	* javax/security/auth/callback/CallbackHandler.java
	* javax/security/auth/callback/ChoiceCallback.java
	* javax/security/auth/callback/ConfirmationCallback.java
	* javax/security/auth/callback/LanguageCallback.java
	* javax/security/auth/callback/NameCallback.java
	* javax/security/auth/callback/PasswordCallback.java
	* javax/security/auth/callback/TextInputCallback.java
	* javax/security/auth/callback/TextOutputCallback.java
	* javax/security/auth/callback/UnsupportedCallbackException.java
	* javax/security/auth/login/AccountExpiredException.java
	* javax/security/auth/login/AppConfigurationEntry.java
	* javax/security/auth/login/Configuration.java
	* javax/security/auth/login/CredentialExpiredException.java
	* javax/security/auth/login/FailedLoginException.java
	* javax/security/auth/login/LoginContext.java
	* javax/security/auth/login/LoginException.java
	* javax/security/auth/login/NullConfiguration.java
	* javax/security/auth/x500/X500PrivateCredential.java
	* javax/security/sasl/AuthenticationException.java
	* javax/security/sasl/AuthorizeCallback.java
	* javax/security/sasl/RealmCallback.java
	* javax/security/sasl/RealmChoiceCallback.java
	* javax/security/sasl/Sasl.java
	* javax/security/sasl/SaslClient.java
	* javax/security/sasl/SaslClientFactory.java
	* javax/security/sasl/SaslException.java
	* javax/security/sasl/SaslServer.java
	* javax/security/sasl/SaslServerFactory.java
	* org/ietf/jgss/ChannelBinding.java
	* org/ietf/jgss/GSSContext.java
	* org/ietf/jgss/GSSCredential.java
	* org/ietf/jgss/GSSException.java
	* org/ietf/jgss/GSSManager.java
	* org/ietf/jgss/GSSName.java
	* org/ietf/jgss/MessageProp.java
	* org/ietf/jgss/Oid.java
	* org/ietf/jgss/MessagesBundle.properties

	Files imported from Jessie <http://www.nongnu.org/jessie/>
	* javax/net/ServerSocketFactory.java
	* javax/net/SocketFactory.java
	* javax/net/VanillaServerSocketFactory.java
	* javax/net/VanillaSocketFactory.java
	* javax/net/ssl/HandshakeCompletedEvent.java
	* javax/net/ssl/HandshakeCompletedListener.java
	* javax/net/ssl/HostnameVerifier.java
	* javax/net/ssl/HttpsURLConnection.java
	* javax/net/ssl/KeyManager.java
	* javax/net/ssl/KeyManagerFactory.java
	* javax/net/ssl/KeyManagerFactorySpi.java
	* javax/net/ssl/ManagerFactoryParameters.java
	* javax/net/ssl/SSLContext.java
	* javax/net/ssl/SSLContextSpi.java
	* javax/net/ssl/SSLException.java
	* javax/net/ssl/SSLHandshakeException.java
	* javax/net/ssl/SSLKeyException.java
	* javax/net/ssl/SSLPeerUnverifiedException.java
	* javax/net/ssl/SSLPermission.java
	* javax/net/ssl/SSLProtocolException.java
	* javax/net/ssl/SSLServerSocket.java
	* javax/net/ssl/SSLServerSocketFactory.java
	* javax/net/ssl/SSLSession.java
	* javax/net/ssl/SSLSessionBindingEvent.java
	* javax/net/ssl/SSLSessionBindingListener.java
	* javax/net/ssl/SSLSessionContext.java
	* javax/net/ssl/SSLSocket.java
	* javax/net/ssl/SSLSocketFactory.java
	* javax/net/ssl/TrivialHostnameVerifier.java
	* javax/net/ssl/TrustManager.java
	* javax/net/ssl/TrustManagerFactory.java
	* javax/net/ssl/TrustManagerFactorySpi.java
	* javax/net/ssl/X509KeyManager.java
	* javax/net/ssl/X509TrustManager.java
	* javax/security/cert/Certificate.java
	* javax/security/cert/CertificateEncodingException.java
	* javax/security/cert/CertificateException.java
	* javax/security/cert/CertificateExpiredException.java
	* javax/security/cert/CertificateNotYetValidException.java
	* javax/security/cert/CertificateParsingException.java
	* javax/security/cert/X509CertBridge.java
	* javax/security/cert/X509Certificate.java

	2004-08-20  Casey Marshall  <csm@gnu.org>

	* java/security/cert/X509CRLSelector.java: New file.
	* java/security/cert/X509CertSelector.java: New file.

From-SVN: r87795
parent c93320c4
2004-09-21 Andreas Tobler <a.tobler@schweiz.ch>
Import the big Crypto/Jessie/Security merge from Classpath.
* Makefile.am: Add imported files.
* Makefile.in: Regenerate.
2004-08-14 Casey Marshall <csm@gnu.org>
The Big Crypto Merge of 2004.
* javax/security/auth/x500/X500Principal.java: Replaced with GNU
Crypto's version.
Files imported from GNU Crypto.
* javax/crypto/BadPaddingException.java
* javax/crypto/Cipher.java
* javax/crypto/CipherInputStream.java
* javax/crypto/CipherOutputStream.java
* javax/crypto/CipherSpi.java
* javax/crypto/EncryptedPrivateKeyInfo.java
* javax/crypto/ExemptionMechanism.java
* javax/crypto/ExemptionMechanismException.java
* javax/crypto/ExemptionMechanismSpi.java
* javax/crypto/IllegalBlockSizeException.java
* javax/crypto/KeyAgreement.java
* javax/crypto/KeyAgreementSpi.java
* javax/crypto/KeyGenerator.java
* javax/crypto/KeyGeneratorSpi.java
* javax/crypto/Mac.java
* javax/crypto/MacSpi.java
* javax/crypto/Makefile.am
* javax/crypto/NoSuchPaddingException.java
* javax/crypto/NullCipher.java
* javax/crypto/NullCipherImpl.java
* javax/crypto/SealedObject.java
* javax/crypto/SecretKey.java
* javax/crypto/SecretKeyFactory.java
* javax/crypto/SecretKeyFactorySpi.java
* javax/crypto/ShortBufferException.java
* javax/crypto/interfaces/DHKey.java
* javax/crypto/interfaces/DHPrivateKey.java
* javax/crypto/interfaces/DHPublicKey.java
* javax/crypto/interfaces/PBEKey.java
* javax/crypto/spec/DESKeySpec.java
* javax/crypto/spec/DESedeKeySpec.java
* javax/crypto/spec/DHGenParameterSpec.java
* javax/crypto/spec/DHParameterSpec.java
* javax/crypto/spec/DHPrivateKeySpec.java
* javax/crypto/spec/DHPublicKeySpec.java
* javax/crypto/spec/IvParameterSpec.java
* javax/crypto/spec/PBEKeySpec.java
* javax/crypto/spec/PBEParameterSpec.java
* javax/crypto/spec/RC2ParameterSpec.java
* javax/crypto/spec/RC5ParameterSpec.java
* javax/crypto/spec/SecretKeySpec.java
* javax/security/auth/AuthPermission.java
* javax/security/auth/DestroyFailedException.java
* javax/security/auth/Destroyable.java
* javax/security/auth/Policy.java
* javax/security/auth/PrivateCredentialPermission.java
* javax/security/auth/RefreshFailedException.java
* javax/security/auth/Refreshable.java
* javax/security/auth/Subject.java
* javax/security/auth/SubjectDomainCombiner.java
* javax/security/auth/callback/Callback.java
* javax/security/auth/callback/CallbackHandler.java
* javax/security/auth/callback/ChoiceCallback.java
* javax/security/auth/callback/ConfirmationCallback.java
* javax/security/auth/callback/LanguageCallback.java
* javax/security/auth/callback/NameCallback.java
* javax/security/auth/callback/PasswordCallback.java
* javax/security/auth/callback/TextInputCallback.java
* javax/security/auth/callback/TextOutputCallback.java
* javax/security/auth/callback/UnsupportedCallbackException.java
* javax/security/auth/login/AccountExpiredException.java
* javax/security/auth/login/AppConfigurationEntry.java
* javax/security/auth/login/Configuration.java
* javax/security/auth/login/CredentialExpiredException.java
* javax/security/auth/login/FailedLoginException.java
* javax/security/auth/login/LoginContext.java
* javax/security/auth/login/LoginException.java
* javax/security/auth/login/NullConfiguration.java
* javax/security/auth/x500/X500PrivateCredential.java
* javax/security/sasl/AuthenticationException.java
* javax/security/sasl/AuthorizeCallback.java
* javax/security/sasl/RealmCallback.java
* javax/security/sasl/RealmChoiceCallback.java
* javax/security/sasl/Sasl.java
* javax/security/sasl/SaslClient.java
* javax/security/sasl/SaslClientFactory.java
* javax/security/sasl/SaslException.java
* javax/security/sasl/SaslServer.java
* javax/security/sasl/SaslServerFactory.java
* org/ietf/jgss/ChannelBinding.java
* org/ietf/jgss/GSSContext.java
* org/ietf/jgss/GSSCredential.java
* org/ietf/jgss/GSSException.java
* org/ietf/jgss/GSSManager.java
* org/ietf/jgss/GSSName.java
* org/ietf/jgss/MessageProp.java
* org/ietf/jgss/Oid.java
* org/ietf/jgss/MessagesBundle.properties
Files imported from Jessie <http://www.nongnu.org/jessie/>
* javax/net/ServerSocketFactory.java
* javax/net/SocketFactory.java
* javax/net/VanillaServerSocketFactory.java
* javax/net/VanillaSocketFactory.java
* javax/net/ssl/HandshakeCompletedEvent.java
* javax/net/ssl/HandshakeCompletedListener.java
* javax/net/ssl/HostnameVerifier.java
* javax/net/ssl/HttpsURLConnection.java
* javax/net/ssl/KeyManager.java
* javax/net/ssl/KeyManagerFactory.java
* javax/net/ssl/KeyManagerFactorySpi.java
* javax/net/ssl/ManagerFactoryParameters.java
* javax/net/ssl/SSLContext.java
* javax/net/ssl/SSLContextSpi.java
* javax/net/ssl/SSLException.java
* javax/net/ssl/SSLHandshakeException.java
* javax/net/ssl/SSLKeyException.java
* javax/net/ssl/SSLPeerUnverifiedException.java
* javax/net/ssl/SSLPermission.java
* javax/net/ssl/SSLProtocolException.java
* javax/net/ssl/SSLServerSocket.java
* javax/net/ssl/SSLServerSocketFactory.java
* javax/net/ssl/SSLSession.java
* javax/net/ssl/SSLSessionBindingEvent.java
* javax/net/ssl/SSLSessionBindingListener.java
* javax/net/ssl/SSLSessionContext.java
* javax/net/ssl/SSLSocket.java
* javax/net/ssl/SSLSocketFactory.java
* javax/net/ssl/TrivialHostnameVerifier.java
* javax/net/ssl/TrustManager.java
* javax/net/ssl/TrustManagerFactory.java
* javax/net/ssl/TrustManagerFactorySpi.java
* javax/net/ssl/X509KeyManager.java
* javax/net/ssl/X509TrustManager.java
* javax/security/cert/Certificate.java
* javax/security/cert/CertificateEncodingException.java
* javax/security/cert/CertificateException.java
* javax/security/cert/CertificateExpiredException.java
* javax/security/cert/CertificateNotYetValidException.java
* javax/security/cert/CertificateParsingException.java
* javax/security/cert/X509CertBridge.java
* javax/security/cert/X509Certificate.java
2004-08-20 Casey Marshall <csm@gnu.org>
* java/security/cert/X509CRLSelector.java: New file.
* java/security/cert/X509CertSelector.java: New file.
2004-09-15 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/file/Handler.java
......
......@@ -99,7 +99,8 @@ else
cond_gtk_ltlibrary =
endif
toolexeclib_LTLIBRARIES = libgcj.la libgij.la lib-org-xml-sax.la lib-org-w3c-dom.la \
toolexeclib_LTLIBRARIES = libgcj.la libgij.la lib-org-xml-sax.la \
lib-org-w3c-dom.la lib-org-ietf-jgss.la \
$(cond_gtk_ltlibrary) $(cond_xlib_ltlibrary)
toolexecmainlib_DATA = libgcj.spec
......@@ -353,6 +354,24 @@ lib_gnu_java_awt_peer_gtk_la_LDFLAGS = \
-version-info `grep -v '^\#' $(srcdir)/libtool-version`
lib_gnu_java_awt_peer_gtk_la_LINK = $(LIBLINK)
lib_org_ietf_jgss_la_SOURCES = \
org/ietf/jgss/ChannelBinding.java \
org/ietf/jgss/GSSContext.java \
org/ietf/jgss/GSSCredential.java \
org/ietf/jgss/GSSException.java \
org/ietf/jgss/GSSManager.java \
org/ietf/jgss/GSSName.java \
org/ietf/jgss/MessageProp.java \
org/ietf/jgss/Oid.java
lib_org_ietf_jgss_la_DEPENDENCIES= $(jgss_propertyo_files)
## See jv_convert_LDADD.
lib_org_ietf_jgss_la_LIBADD = -L$(here)/.libs $(jgss_propertyo_files)
## The mysterious backslash in the grep pattern is consumed by make.
lib_org_ietf_jgss_la_LDFLAGS = -rpath $(toolexeclibdir) \
-version-info `grep -v '^\#' $(srcdir)/libtool-version`
lib_org_w3c_dom_la_SOURCES = org/w3c/dom/Attr.java \
org/w3c/dom/CDATASection.java \
org/w3c/dom/CharacterData.java \
......@@ -440,6 +459,7 @@ lib_gnu_awt_xlib_la_LINK = $(LIBLINK)
all_java_source_files = \
$(java_source_files) \
$(built_java_source_files) \
$(lib_org_ietf_jgss_la_SOURCES) \
$(lib_org_xml_sax_la_SOURCES) \
$(lib_org_w3c_dom_la_SOURCES) \
$(gtk_awt_peer_sources) \
......@@ -450,13 +470,22 @@ all_java_class_files = $(all_java_source_files:.java=.class)
## Build property files into the library.
property_files = \
gnu/regexp/MessagesBundle.properties \
gnu/regexp/MessagesBundle_fr.properties
gnu/regexp/MessagesBundle_fr.properties
propertyo_files = $(property_files:.properties=.properties.lo)
%.properties.lo: %.properties
$(LTGCJCOMPILE) -o $@ -c $< -Wc,--resource,`echo $@ | sed "s/\.lo$$//"`
## Build property files into the lib-org-ietf-jgss library.
jgss_property_files = \
org/ietf/jgss/MessagesBundle.properties
jgss_propertyo_files = $(jgss_property_files:.properties=.properties.lo)
%.properties.lo: %.properties
$(LTGCJCOMPILE) -o $@ -c $< -Wc,--resource,`echo $@ | sed "s/\.lo$$//"`
if ONESTEP
# Compile all classfiles in one go.
......@@ -520,7 +549,7 @@ SUFFIXES = .class .java .h .properties
## Note: we omit StackTrace here, since it has an explicit rule a bit
## later, and GNU make will warn in this case.
$(filter-out gnu/gcj/runtime/StackTrace.lo, $(javao_files)) $(xlib_javao_files) $(lib_org_w3c_dom_la_OBJECTS) $(lib_org_xml_sax_la_OBJECTS): %.lo: %.java
$(filter-out gnu/gcj/runtime/StackTrace.lo, $(javao_files)) $(xlib_javao_files) $(lib_org_w3c_dom_la_OBJECTS) $(lib_org_xml_sax_la_OBJECTS) $(lib_org_ietf_jgss_la_OBJECTS): %.lo: %.java
$(LTGCJCOMPILE) -o $@ -c $<
$(gtk_awt_peer_sources:.java=.lo): %.lo: %.java
......@@ -1797,6 +1826,46 @@ javax/accessibility/AccessibleTable.java \
javax/accessibility/AccessibleTableModelChange.java \
javax/accessibility/AccessibleText.java \
javax/accessibility/AccessibleValue.java \
javax/crypto/BadPaddingException.java \
javax/crypto/Cipher.java \
javax/crypto/CipherInputStream.java \
javax/crypto/CipherOutputStream.java \
javax/crypto/CipherSpi.java \
javax/crypto/EncryptedPrivateKeyInfo.java \
javax/crypto/KeyGeneratorSpi.java \
javax/crypto/ExemptionMechanism.java \
javax/crypto/ExemptionMechanismException.java \
javax/crypto/ExemptionMechanismSpi.java \
javax/crypto/IllegalBlockSizeException.java \
javax/crypto/KeyAgreement.java \
javax/crypto/KeyAgreementSpi.java \
javax/crypto/KeyGenerator.java \
javax/crypto/Mac.java \
javax/crypto/MacSpi.java \
javax/crypto/NoSuchPaddingException.java \
javax/crypto/NullCipher.java \
javax/crypto/NullCipherImpl.java \
javax/crypto/SealedObject.java \
javax/crypto/SecretKey.java \
javax/crypto/SecretKeyFactory.java \
javax/crypto/SecretKeyFactorySpi.java \
javax/crypto/ShortBufferException.java \
javax/crypto/interfaces/DHKey.java \
javax/crypto/interfaces/DHPrivateKey.java \
javax/crypto/interfaces/DHPublicKey.java \
javax/crypto/interfaces/PBEKey.java \
javax/crypto/spec/DESKeySpec.java \
javax/crypto/spec/DESedeKeySpec.java \
javax/crypto/spec/DHGenParameterSpec.java \
javax/crypto/spec/DHParameterSpec.java \
javax/crypto/spec/DHPrivateKeySpec.java \
javax/crypto/spec/DHPublicKeySpec.java \
javax/crypto/spec/IvParameterSpec.java \
javax/crypto/spec/PBEKeySpec.java \
javax/crypto/spec/PBEParameterSpec.java \
javax/crypto/spec/RC2ParameterSpec.java \
javax/crypto/spec/RC5ParameterSpec.java \
javax/crypto/spec/SecretKeySpec.java \
javax/imageio/IIOException.java \
javax/imageio/ImageReader.java \
javax/imageio/ImageTranscoder.java \
......@@ -1904,6 +1973,40 @@ javax/naming/ldap/UnsolicitedNotification.java \
javax/naming/ldap/UnsolicitedNotificationEvent.java \
javax/naming/ldap/UnsolicitedNotificationListener.java \
javax/naming/OperationNotSupportedException.java \
javax/net/ServerSocketFactory.java \
javax/net/SocketFactory.java \
javax/net/ssl/HandshakeCompletedEvent.java \
javax/net/ssl/HandshakeCompletedListener.java \
javax/net/ssl/HostnameVerifier.java \
javax/net/ssl/HttpsURLConnection.java \
javax/net/ssl/KeyManager.java \
javax/net/ssl/KeyManagerFactory.java \
javax/net/ssl/KeyManagerFactorySpi.java \
javax/net/ssl/ManagerFactoryParameters.java \
javax/net/ssl/SSLProtocolException.java \
javax/net/ssl/SSLContext.java \
javax/net/ssl/SSLContextSpi.java \
javax/net/ssl/SSLException.java \
javax/net/ssl/SSLHandshakeException.java \
javax/net/ssl/SSLKeyException.java \
javax/net/ssl/SSLPeerUnverifiedException.java \
javax/net/ssl/SSLPermission.java \
javax/net/ssl/SSLServerSocket.java \
javax/net/ssl/SSLServerSocketFactory.java \
javax/net/ssl/SSLSession.java \
javax/net/ssl/SSLSessionBindingEvent.java \
javax/net/ssl/SSLSessionBindingListener.java \
javax/net/ssl/SSLSessionContext.java \
javax/net/ssl/SSLSocket.java \
javax/net/ssl/SSLSocketFactory.java \
javax/net/ssl/TrivialHostnameVerifier.java \
javax/net/ssl/TrustManager.java \
javax/net/ssl/TrustManagerFactory.java \
javax/net/ssl/TrustManagerFactorySpi.java \
javax/net/ssl/X509KeyManager.java \
javax/net/ssl/X509TrustManager.java \
javax/net/VanillaSocketFactory.java \
javax/net/VanillaServerSocketFactory.java \
javax/print/AttributeException.java \
javax/print/CancelablePrintJob.java \
javax/print/Doc.java \
......@@ -2016,7 +2119,53 @@ javax/print/event/PrintJobEvent.java \
javax/print/event/PrintJobListener.java \
javax/print/event/PrintServiceAttributeEvent.java \
javax/print/event/PrintServiceAttributeListener.java \
javax/security/auth/AuthPermission.java \
javax/security/auth/Destroyable.java \
javax/security/auth/DestroyFailedException.java \
javax/security/auth/login/AccountExpiredException.java \
javax/security/auth/login/AppConfigurationEntry.java \
javax/security/auth/login/Configuration.java \
javax/security/auth/login/CredentialExpiredException.java \
javax/security/auth/login/FailedLoginException.java \
javax/security/auth/login/LoginContext.java \
javax/security/auth/login/LoginException.java \
javax/security/auth/login/NullConfiguration.java \
javax/security/auth/Policy.java \
javax/security/auth/PrivateCredentialPermission.java \
javax/security/auth/Refreshable.java \
javax/security/auth/RefreshFailedException.java \
javax/security/auth/Subject.java \
javax/security/auth/SubjectDomainCombiner.java \
javax/security/auth/x500/X500Principal.java \
javax/security/auth/x500/X500PrivateCredential.java \
javax/security/auth/callback/Callback.java \
javax/security/auth/callback/CallbackHandler.java \
javax/security/auth/callback/ChoiceCallback.java \
javax/security/auth/callback/ConfirmationCallback.java \
javax/security/auth/callback/LanguageCallback.java \
javax/security/auth/callback/NameCallback.java \
javax/security/auth/callback/PasswordCallback.java \
javax/security/auth/callback/TextInputCallback.java \
javax/security/auth/callback/TextOutputCallback.java \
javax/security/auth/callback/UnsupportedCallbackException.java \
javax/security/cert/Certificate.java \
javax/security/cert/CertificateEncodingException.java \
javax/security/cert/CertificateException.java \
javax/security/cert/CertificateExpiredException.java \
javax/security/cert/CertificateNotYetValidException.java \
javax/security/cert/CertificateParsingException.java \
javax/security/cert/X509CertBridge.java \
javax/security/cert/X509Certificate.java \
javax/security/sasl/AuthenticationException.java \
javax/security/sasl/AuthorizeCallback.java \
javax/security/sasl/RealmCallback.java \
javax/security/sasl/RealmChoiceCallback.java \
javax/security/sasl/Sasl.java \
javax/security/sasl/SaslClient.java \
javax/security/sasl/SaslClientFactory.java \
javax/security/sasl/SaslException.java \
javax/security/sasl/SaslServer.java \
javax/security/sasl/SaslServerFactory.java \
javax/sql/ConnectionEvent.java \
javax/sql/ConnectionEventListener.java \
javax/sql/ConnectionPoolDataSource.java \
......@@ -2848,7 +2997,9 @@ java/security/cert/PolicyQualifierInfo.java \
java/security/cert/TrustAnchor.java \
java/security/cert/X509CRL.java \
java/security/cert/X509CRLEntry.java \
java/security/cert/X509CRLSelector.java \
java/security/cert/X509Certificate.java \
java/security/cert/X509CertSelector.java \
java/security/cert/X509Extension.java \
java/security/interfaces/DSAKey.java \
java/security/interfaces/DSAKeyPairGenerator.java \
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/* BadPaddingException -- Signals bad padding bytes on decryption.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.GeneralSecurityException;
/**
* This exception is thrown during decryption when the decrypted input
* does not have the proper padding bytes that are expected by the padding
* mechanism.
*
* @author Casey Marshall (csm@gnu.org)
*/
public class BadPaddingException extends GeneralSecurityException
{
// Constant.
// ------------------------------------------------------------------------
/** Serialization constant. */
private static final long serialVersionUID = -5315033893984728443L;
// Constructors.
// ------------------------------------------------------------------------
/**
* Creates a new bad padding exception with no detail message.
*/
public BadPaddingException()
{
super();
}
/**
* Creates a new bad padding exception with a detail message.
*
* @param message The detail message.
*/
public BadPaddingException(String message)
{
super(message);
}
}
/* CipherOutputStream.java -- Filters output through a cipher.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* A filtered output stream that transforms data written to it with a
* {@link Cipher} before sending it to the underlying output stream.
*
* @author Casey Marshall (csm@gnu.org)
*/
public class CipherOutputStream extends FilterOutputStream
{
// Fields.
// ------------------------------------------------------------------------
/** The underlying cipher. */
private Cipher cipher;
private byte[][] inBuffer;
private int inLength;
private byte[] outBuffer;
private static final int FIRST_TIME = 0;
private static final int SECOND_TIME = 1;
private static final int SEASONED = 2;
private int state;
/** True if the cipher is a stream cipher (blockSize == 1) */
private boolean isStream;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new cipher output stream. The cipher argument must have
* already been initialized.
*
* @param out The sink for transformed data.
* @param cipher The cipher to transform data with.
*/
public CipherOutputStream(OutputStream out, Cipher cipher)
{
super(out);
if (cipher != null)
{
this.cipher = cipher;
if (!(isStream = cipher.getBlockSize() == 1))
{
inBuffer = new byte[2][];
inBuffer[0] = new byte[cipher.getBlockSize()];
inBuffer[1] = new byte[cipher.getBlockSize()];
inLength = 0;
state = FIRST_TIME;
}
}
else
this.cipher = new NullCipher();
}
/**
* Create a cipher output stream with no cipher.
*
* @param out The sink for transformed data.
*/
protected CipherOutputStream(OutputStream out)
{
super(out);
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Close this output stream, and the sink output stream.
*
* <p>This method will first invoke the {@link Cipher#doFinal()}
* method of the underlying {@link Cipher}, and writes the output of
* that method to the sink output stream.
*
* @throws java.io.IOException If an I/O error occurs, or if an error
* is caused by finalizing the transformation.
*/
public void close() throws IOException
{
try
{
int len;
if (state != FIRST_TIME)
{
len = cipher.update(inBuffer[0], 0, inBuffer[0].length, outBuffer);
out.write(outBuffer, 0, len);
}
len = cipher.doFinal(inBuffer[0], 0, inLength, outBuffer);
out.write(outBuffer, 0, len);
}
catch (javax.crypto.IllegalBlockSizeException ibse)
{
throw new IOException(ibse.toString());
}
catch (javax.crypto.BadPaddingException bpe)
{
throw new IOException(bpe.toString());
}
catch (ShortBufferException sbe)
{
throw new IOException(sbe.toString());
}
out.flush();
out.close();
}
/**
* Flush any pending output.
*
* @throws java.io.IOException If an I/O error occurs.
*/
public void flush() throws IOException
{
out.flush();
}
/**
* Write a single byte to the output stream.
*
* @param b The next byte.
* @throws java.io.IOException If an I/O error occurs, or if the
* underlying cipher is not in the correct state to transform
* data.
*/
public void write(int b) throws IOException
{
if (isStream)
{
byte[] buf = new byte[] { (byte) b };
try
{
cipher.update(buf, 0, 1, buf, 0);
}
catch (ShortBufferException sbe)
{
throw new IOException(sbe.toString());
}
out.write(buf);
return;
}
inBuffer[1][inLength++] = (byte) b;
if (inLength == inBuffer[1].length)
process();
}
/**
* Write a byte array to the output stream.
*
* @param buf The next bytes.
* @throws java.io.IOException If an I/O error occurs, or if the
* underlying cipher is not in the correct state to transform
* data.
*/
public void write(byte[] buf) throws IOException
{
write(buf, 0, buf.length);
}
/**
* Write a portion of a byte array to the output stream.
*
* @param buf The next bytes.
* @param off The offset in the byte array to start.
* @param len The number of bytes to write.
* @throws java.io.IOException If an I/O error occurs, or if the
* underlying cipher is not in the correct state to transform
* data.
*/
public void write(byte[] buf, int off, int len) throws IOException
{
if (isStream)
{
out.write(cipher.update(buf, off, len));
return;
}
int count = 0;
while (count < len)
{
int l = Math.min(inBuffer[1].length - inLength, len - count);
System.arraycopy(buf, off+count, inBuffer[1], inLength, l);
count += l;
inLength += l;
if (inLength == inBuffer[1].length)
process();
}
}
// Own method.
// -------------------------------------------------------------------------
private void process() throws IOException
{
if (state == SECOND_TIME)
{
state = SEASONED;
}
else
{
byte[] temp = inBuffer[0];
inBuffer[0] = inBuffer[1];
inBuffer[1] = temp;
}
if (state == FIRST_TIME)
{
inLength = 0;
state = SECOND_TIME;
return;
}
try
{
cipher.update(inBuffer[0], 0, inBuffer[0].length, outBuffer);
}
catch (ShortBufferException sbe)
{
throw new IOException(sbe.toString());
}
out.write(outBuffer);
inLength = 0;
}
}
/* EncryptedPrivateKeyInfo.java -- As in PKCS #8.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import gnu.java.security.OID;
import gnu.java.security.der.DER;
import gnu.java.security.der.DERReader;
import gnu.java.security.der.DERValue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.security.AlgorithmParameters;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
/**
* An implementation of the <code>EncryptedPrivateKeyInfo</code> ASN.1
* type as specified in <a
* href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-8/">PKCS #8 -
* Private-Key Information Syntax Standard</a>.
*
* <p>The ASN.1 type <code>EncryptedPrivateKeyInfo</code> is:
*
* <blockquote>
* <pre>EncryptedPrivateKeyInfo ::= SEQUENCE {
* encryptionAlgorithm EncryptionAlgorithmIdentifier,
* encryptedData EncryptedData }
*
* EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
*
* EncrytpedData ::= OCTET STRING
*
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL }</pre>
* </blockquote>
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see java.security.spec.PKCS8EncodedKeySpec
*/
public class EncryptedPrivateKeyInfo
{
// Fields.
// ------------------------------------------------------------------------
/** The encrypted data. */
private byte[] encryptedData;
/** The encoded, encrypted key. */
private byte[] encoded;
/** The OID of the encryption algorithm. */
private OID algOid;
/** The encryption algorithm's parameters. */
private AlgorithmParameters params;
/** The encoded ASN.1 algorithm parameters. */
private byte[] encodedParams;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new <code>EncryptedPrivateKeyInfo</code> object from raw
* encrypted data and the parameters used for encryption.
*
* <p>The <code>encryptedData</code> array is cloned.
*
* @param params The encryption algorithm parameters.
* @param encryptedData The encrypted key data.
* @throws java.lang.IllegalArgumentException If the
* <code>encryptedData</code> array is empty (zero-length).
* @throws java.security.NoSuchAlgorithmException If the algorithm
* specified in the parameters is not supported.
* @throws java.lang.NullPointerException If <code>encryptedData</code>
* is null.
*/
public EncryptedPrivateKeyInfo(AlgorithmParameters params,
byte[] encryptedData)
throws IllegalArgumentException, NoSuchAlgorithmException
{
if (encryptedData.length == 0)
{
throw new IllegalArgumentException("0-length encryptedData");
}
this.params = params;
algOid = new OID(params.getAlgorithm());
this.encryptedData = (byte[]) encryptedData.clone();
}
/**
* Create a new <code>EncryptedPrivateKeyInfo</code> from an encoded
* representation, parsing the ASN.1 sequence.
*
* @param encoded The encoded info.
* @throws java.io.IOException If parsing the encoded data fails.
* @throws java.lang.NullPointerException If <code>encoded</code> is
* null.
*/
public EncryptedPrivateKeyInfo(byte[] encoded)
throws IOException
{
this.encoded = (byte[]) encoded.clone();
decode();
}
/**
* Create a new <code>EncryptedPrivateKeyInfo</code> from the cipher
* name and the encrytpedData.
*
* <p>The <code>encryptedData</code> array is cloned.
*
* @param algName The name of the algorithm (as an object identifier).
* @param encryptedData The encrypted key data.
* @throws java.lang.IllegalArgumentException If the
* <code>encryptedData</code> array is empty (zero-length).
* @throws java.security.NoSuchAlgorithmException If algName is not
* the name of a supported algorithm.
* @throws java.lang.NullPointerException If <code>encryptedData</code>
* is null.
*/
public EncryptedPrivateKeyInfo(String algName, byte[] encryptedData)
throws IllegalArgumentException, NoSuchAlgorithmException,
NullPointerException
{
if (encryptedData.length == 0)
{
throw new IllegalArgumentException("0-length encryptedData");
}
this.algOid = new OID(algName);
this.encryptedData = (byte[]) encryptedData.clone();
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Return the name of the cipher used to encrypt this key.
*
* @return The algorithm name.
*/
public String getAlgName()
{
return algOid.toString();
}
public AlgorithmParameters getAlgParameters()
{
if (params == null && encodedParams != null)
{
try
{
params = AlgorithmParameters.getInstance(getAlgName());
params.init(encodedParams);
}
catch (NoSuchAlgorithmException ignore)
{
}
catch (IOException ignore)
{
}
}
return params;
}
public synchronized byte[] getEncoded() throws IOException
{
if (encoded == null) encode();
return (byte[]) encoded.clone();
}
public byte[] getEncryptedData()
{
return encryptedData;
}
public PKCS8EncodedKeySpec getKeySpec(Cipher cipher)
throws InvalidKeySpecException
{
try
{
return new PKCS8EncodedKeySpec(cipher.doFinal(encryptedData));
}
catch (Exception x)
{
throw new InvalidKeySpecException(x.toString());
}
}
// Own methods.
// -------------------------------------------------------------------------
private void decode() throws IOException
{
DERReader der = new DERReader(encoded);
DERValue val = der.read();
if (val.getTag() != DER.SEQUENCE)
throw new IOException("malformed EncryptedPrivateKeyInfo");
val = der.read();
if (val.getTag() != DER.SEQUENCE)
throw new IOException("malformed AlgorithmIdentifier");
int algpLen = val.getLength();
DERValue oid = der.read();
if (oid.getTag() != DER.OBJECT_IDENTIFIER)
throw new IOException("malformed AlgorithmIdentifier");
algOid = (OID) oid.getValue();
if (algpLen == 0)
{
val = der.read();
if (val.getTag() != 0)
{
encodedParams = val.getEncoded();
der.read();
}
}
else if (oid.getEncodedLength() < val.getLength())
{
val = der.read();
encodedParams = val.getEncoded();
}
val = der.read();
if (val.getTag() != DER.OCTET_STRING)
throw new IOException("malformed AlgorithmIdentifier");
encryptedData = (byte[]) val.getValue();
}
private void encode() throws IOException
{
List algId = new ArrayList(2);
algId.add(new DERValue(DER.OBJECT_IDENTIFIER, algOid));
getAlgParameters();
if (params != null)
{
algId.add(DERReader.read(params.getEncoded()));
}
List epki = new ArrayList(2);
epki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, algId));
epki.add(new DERValue(DER.OCTET_STRING, encryptedData));
encoded = new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, epki).getEncoded();
}
}
/* ExemptionMechanism.java -- Generic crypto-weakening mechanism.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.lang.reflect.InvocationTargetException;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Security;
import java.security.spec.AlgorithmParameterSpec;
import gnu.java.security.Engine;
/**
* An exemption mechanism, which will conditionally allow cryptography
* where it is not normally allowed, implements things such as <i>key
* recovery</i>, <i>key weakening</i>, or <i>key escrow</i>.
*
* <p><b>Implementation note</b>: this class is present for
* API-compatibility only; it is not actually used anywhere in this library
* and this library does not, in general, support crypto weakening.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class ExemptionMechanism
{
// Constants and fields.
// ------------------------------------------------------------------------
private static final String SERVICE = "ExemptionMechanism";
private ExemptionMechanismSpi emSpi;
private Provider provider;
private String mechanism;
private boolean virgin;
// Constructor.
// ------------------------------------------------------------------------
protected ExemptionMechanism(ExemptionMechanismSpi emSpi, Provider provider,
String mechanism)
{
this.emSpi = emSpi;
this.provider = provider;
this.mechanism = mechanism;
virgin = true;
}
// Class methods.
// ------------------------------------------------------------------------
public static final ExemptionMechanism getInstance(String mechanism)
throws NoSuchAlgorithmException
{
Provider[] provs = Security.getProviders();
String msg = "";
for (int i = 0; i < provs.length; i++)
{
try
{
return getInstance(mechanism, provs[i]);
}
catch (NoSuchAlgorithmException nsae)
{
msg = nsae.getMessage();
}
}
throw new NoSuchAlgorithmException(msg);
}
public static final ExemptionMechanism getInstance(String mechanism,
String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
{
throw new NoSuchProviderException(provider);
}
return getInstance(mechanism, p);
}
public static final ExemptionMechanism getInstance(String mechanism,
Provider provider)
throws NoSuchAlgorithmException
{
try
{
return new ExemptionMechanism((ExemptionMechanismSpi)
Engine.getInstance(SERVICE, mechanism, provider),
provider, mechanism);
}
catch (InvocationTargetException ite)
{
if (ite.getCause() instanceof NoSuchAlgorithmException)
throw (NoSuchAlgorithmException) ite.getCause();
else
throw new NoSuchAlgorithmException(mechanism);
}
catch (ClassCastException cce)
{
throw new NoSuchAlgorithmException(mechanism);
}
}
// Instance methods.
// ------------------------------------------------------------------------
public final byte[] genExemptionBlob()
throws IllegalStateException, ExemptionMechanismException
{
if (virgin)
{
throw new IllegalStateException("not initialized");
}
return emSpi.engineGenExemptionBlob();
}
public final int genExemptionBlob(byte[] output)
throws IllegalStateException, ExemptionMechanismException,
ShortBufferException
{
return genExemptionBlob(output, 0);
}
public final int genExemptionBlob(byte[] output, int outputOffset)
throws IllegalStateException, ExemptionMechanismException,
ShortBufferException
{
if (virgin)
{
throw new IllegalStateException("not initialized");
}
return emSpi.engineGenExemptionBlob(output, outputOffset);
}
public final String getName()
{
return mechanism;
}
public final int getOutputSize(int inputLength) throws IllegalStateException
{
if (virgin)
{
throw new IllegalStateException("not initialized");
}
return emSpi.engineGetOutputSize(inputLength);
}
public final Provider getProvider()
{
return provider;
}
public final void init(Key key)
throws ExemptionMechanismException, InvalidKeyException
{
emSpi.engineInit(key);
virgin = false;
}
public final void init(Key key, AlgorithmParameters params)
throws ExemptionMechanismException, InvalidAlgorithmParameterException,
InvalidKeyException
{
emSpi.engineInit(key, params);
virgin = false;
}
public final void init(Key key, AlgorithmParameterSpec params)
throws ExemptionMechanismException, InvalidAlgorithmParameterException,
InvalidKeyException
{
emSpi.engineInit(key, params);
virgin = false;
}
public final boolean isCryptoAllowed(Key key)
throws ExemptionMechanismException
{
return true;
}
}
/* ExemptionMechanismException -- An error in an exemption mechanism.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is a part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License along
with GNU Classpath; if not, write to the
Free Software Foundation, Inc.,
59 Temple Place, Suite 330,
Boston, MA 02111-1307
USA
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under terms
of your choice, provided that you also meet, for each linked independent
module, the terms and conditions of the license of that module. An
independent module is a module which is not derived from or based on
this library. If you modify this library, you may extend this exception
to your version of the library, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from your
version. */
package javax.crypto;
import java.security.GeneralSecurityException;
/**
* Signals a general exception in an {@link ExemptionMechanism}.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class ExemptionMechanismException extends GeneralSecurityException
{
// Constant.
// ------------------------------------------------------------------------
/** Compatible with JDK1.4. */
private static final long serialVersionUID = 1572699429277957109L;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new exception with no detail message.
*/
public ExemptionMechanismException()
{
super();
}
/**
* Create a new exception with a detail message.
*
* @param message The detail message.
*/
public ExemptionMechanismException(String message)
{
super(message);
}
}
/* ExemptionMechanismSpi.java -- Exemption mechanism service provider interface.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
/**
* The <i>Service Provider Interface</i> (<b>SPI</b>) for the {@link
* ExemptionMechanism} class.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public abstract class ExemptionMechanismSpi
{
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new exemption mechanism SPI.
*/
public ExemptionMechanismSpi()
{
}
// Abstract instance methods.
// ------------------------------------------------------------------------
/**
* Return a key blob for the key that this mechanism was initialized
* with.
*
* @return The key blob.
* @throws javax.crypto.ExemptionMechanismException If generating the
* blob fails.
*/
protected abstract byte[] engineGenExemptionBlob()
throws ExemptionMechanismException;
/**
* Generate a key blob for the key that this mechanism was initialized
* with, storing it into the given byte array.
*
* @param output The destination for the key blob.
* @param outputOffset The index in the output array to start.
* @return The size of the key blob.
* @throws javax.crypto.ExemptionMechanismException If generating the
* blob fails.
* @throws javax.crypto.ShortBufferException If the output array is
* not large enough for the key blob.
*/
protected abstract int engineGenExemptionBlob(byte[] output, int outputOffset)
throws ExemptionMechanismException, ShortBufferException;
/**
* Get the size of the output blob given an input key size. The actual
* blob may be shorter than the value returned by this method. Both
* values are in bytes.
*
* @param inputLength The input size.
* @return The output size.
*/
protected abstract int engineGetOutputSize(int inputLength);
/**
* Initialize this mechanism with a key.
*
* @param key The key.
* @throws javax.crypto.ExemptionMechanismException If generating the
* blob fails.
* @throws java.security.InvalidKeyException If the supplied key
* cannot be used.
*/
protected abstract void engineInit(Key key)
throws ExemptionMechanismException, InvalidKeyException;
/**
* Initialize this mechanism with a key and parameters.
*
* @param key The key.
* @param params The parameters.
* @throws javax.crypto.ExemptionMechanismException If generating the
* blob fails.
* @throws java.security.InvalidAlgorithmParameterExceptin If the
* supplied parameters are inappropriate.
* @throws java.security.InvalidKeyException If the supplied key
* cannot be used.
*/
protected abstract void engineInit(Key key, AlgorithmParameters params)
throws ExemptionMechanismException, InvalidAlgorithmParameterException,
InvalidKeyException;
/**
* Initialize this mechanism with a key and parameters.
*
* @param key The key.
* @param params The parameters.
* @throws javax.crypto.ExemptionMechanismException If generating the
* blob fails.
* @throws java.security.InvalidAlgorithmParameterExceptin If the
* supplied parameters are inappropriate.
* @throws java.security.InvalidKeyException If the supplied key
* cannot be used.
*/
protected abstract void engineInit(Key key, AlgorithmParameterSpec params)
throws ExemptionMechanismException, InvalidAlgorithmParameterException,
InvalidKeyException;
}
/* IllegalBlockSizeException.java -- Signals illegal block sizes.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.GeneralSecurityException;
/**
* This exception is thrown when finishing encryption without padding or
* decryption and the input is not a multiple of the cipher's block
* size.
*
* @author Casey Marshall (csm@gnu.org)
*/
public class IllegalBlockSizeException extends GeneralSecurityException
{
// Constant.
// ------------------------------------------------------------------------
/** Serialization constant. */
private static final long serialVersionUID = -1965144811953540392L;
// Constructors.
// ------------------------------------------------------------------------
public IllegalBlockSizeException()
{
super();
}
public IllegalBlockSizeException(String message)
{
super(message);
}
}
/* KeyAgreementSpi.java -- The key agreement service provider interface.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
/**
* This is the <i>Service Provider Interface</i> (<b>SPI</b>) for the
* {@link javax.crypto.KeyAgreement} class.
*
* <p>Providers wishing to implement a key agreement algorithm must
* subclass this and provide an appropriate implementation for all the
* abstract methods below, and provide an appropriate entry in the
* master {@link java.security.Provider} class (the service name for key
* agreement algorithms is <code>"KeyAgreement"</code>).
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see KeyAgreement
* @see SecretKey
*/
public abstract class KeyAgreementSpi
{
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new KeyAgreementSpi instance.
*/
public KeyAgreementSpi()
{
}
// Abstract instance methods.
// ------------------------------------------------------------------------
/**
* Do a phase in the key agreement.
*
* @param key The key to use for this phase.
* @param lastPhase <code>true</code> if this call should be the last
* phase.
* @return The intermediate result, or <code>null</code> if there is
* no intermediate result.
* @throws java.lang.IllegalStateException If this instance has not
* been initialized.
* @throws java.security.InvalidKeyException If the supplied key is
* not appropriate.
*/
protected abstract Key engineDoPhase(Key key, boolean lastPhase)
throws IllegalStateException, InvalidKeyException;
/**
* Generate the shared secret in a new byte array.
*
* @return The shared secret in a new byte array.
* @throws java.lang.IllegalStateException If this key agreement is
* not ready to generate the secret.
*/
protected abstract byte[] engineGenerateSecret()
throws IllegalStateException;
/**
* Generate the shared secret, storing it into the specified array.
*
* @param sharedSecret The byte array in which to store the secret.
* @param offset The offset into the byte array to start.
* @return The size of the shared secret.
* @throws java.lang.IllegalStateException If this key agreement is
* not ready to generate the secret.
* @throws javax.crypto.ShortBufferException If there is not enough
* space in the supplied array for the shared secret.
*/
protected abstract int engineGenerateSecret(byte[] sharedSecret, int offset)
throws IllegalStateException, ShortBufferException;
/**
* Generate the shared secret and return it as a {@link SecretKey}.
*
* @param algorithm The algorithm with which to generate the secret key.
* @return The shared secret as a secret key.
* @throws java.lang.IllegalStateException If this key agreement is
* not ready to generate the secret.
* @throws java.security.InvalidKeyException If the shared secret
* cannot be made into a {@link SecretKey}.
* @throws java.security.NoSuchAlgorithmException If
* <code>algorithm</code> cannot be found.
*/
protected abstract SecretKey engineGenerateSecret(String algorithm)
throws IllegalStateException, InvalidKeyException, NoSuchAlgorithmException;
/**
* Initialize this key agreement with a key, parameters, and source of
* randomness.
*
* @param key The key to initialize with, usually a private key.
* @param params The parameters to initialize with.
* @param random The source of randomness to use.
* @throws java.security.InvalidAlgorithmParameterException If the
* supplied parameters are inappropriate.
* @throws java.security.InvalidKeyException If the supplied key is
* inappropriate.
*/
protected abstract void engineInit(Key key, AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidAlgorithmParameterException, InvalidKeyException;
/**
* Initialize this key agreement with a key and source of randomness.
*
* @param key The key to initialize with, usually a private key.
* @param random The source of randomness to use.
* @throws java.security.InvalidKeyException If the supplied key is
* inappropriate.
*/
protected abstract void engineInit(Key key, SecureRandom random)
throws InvalidKeyException;
}
/* KeyGenerator.java -- Interface to a symmetric key generator.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.lang.reflect.InvocationTargetException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
import java.security.spec.AlgorithmParameterSpec;
import gnu.java.security.Engine;
/**
* A generic producer of keys for symmetric cryptography. The keys
* returned may be simple wrappers around byte arrays, or, if the
* target cipher requires them, more complex objects.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see Cipher
* @see Mac
*/
public class KeyGenerator
{
// Constants and fields.
// ------------------------------------------------------------------------
private static final String SERVICE = "KeyGenerator";
/** The underlying generator implementation. */
private KeyGeneratorSpi kgSpi;
/** The provider of the implementation. */
private Provider provider;
/** The name of the algorithm. */
private String algorithm;
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new key generator.
*
* @param kgSpi The underlying generator.
* @param provider The provider of this implementation.
* @param algorithm The algorithm's name.
*/
protected KeyGenerator(KeyGeneratorSpi kgSpi, Provider provider,
String algorithm)
{
this.kgSpi = kgSpi;
this.provider = provider;
this.algorithm = algorithm;
}
// Class methods.
// ------------------------------------------------------------------------
/**
* Create a new key generator, returning the first available
* implementation.
*
* @param algorithm The generator algorithm name.
* @throws java.security.NoSuchAlgorithmException If the specified
* algorithm does not exist.
*/
public static final KeyGenerator getInstance(String algorithm)
throws NoSuchAlgorithmException
{
Provider[] provs = Security.getProviders();
String msg = algorithm;
for (int i = 0; i < provs.length; i++)
{
try
{
return getInstance(algorithm, provs[i]);
}
catch (NoSuchAlgorithmException nsae)
{
msg = nsae.getMessage();
}
}
throw new NoSuchAlgorithmException(msg);
}
/**
* Create a new key generator from the named provider.
*
* @param algorithm The generator algorithm name.
* @param provider The name of the provider to use.
* @return An appropriate key generator, if found.
* @throws java.security.NoSuchAlgorithmException If the specified
* algorithm is not implemented by the named provider.
* @throws java.security.NoSuchProviderException If the named provider
* does not exist.
*/
public static final KeyGenerator getInstance(String algorithm, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
{
throw new NoSuchProviderException(provider);
}
return getInstance(algorithm, p);
}
/**
* Create a new key generator from the supplied provider.
*
* @param algorithm The generator algorithm name.
* @param provider The provider to use.
* @return An appropriate key generator, if found.
* @throws java.security.NoSuchAlgorithmException If the specified
* algorithm is not implemented by the provider.
*/
public static final KeyGenerator getInstance(String algorithm, Provider provider)
throws NoSuchAlgorithmException
{
try
{
return new KeyGenerator((KeyGeneratorSpi)
Engine.getInstance(SERVICE, algorithm, provider),
provider, algorithm);
}
catch (InvocationTargetException ite)
{
if (ite.getCause() == null)
throw new NoSuchAlgorithmException(algorithm);
if (ite.getCause() instanceof NoSuchAlgorithmException)
throw (NoSuchAlgorithmException) ite.getCause();
throw new NoSuchAlgorithmException(algorithm);
}
catch (ClassCastException cce)
{
throw new NoSuchAlgorithmException(algorithm);
}
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Generate a key.
*
* @return The new key.
*/
public final SecretKey generateKey()
{
return kgSpi.engineGenerateKey();
}
/**
* Return the name of this key generator.
*
* @return The algorithm name.
*/
public final String getAlgorithm()
{
return algorithm;
}
/**
* Return the provider of the underlying implementation.
*
* @return The provider.
*/
public final Provider getProvider()
{
return provider;
}
/**
* Initialize this key generator with a set of parameters; the
* highest-priority {@link java.security.SecureRandom} implementation
* will be used.
*
* @param params The algorithm parameters.
* @throws java.security.InvalidAlgorithmParameterException If the
* supplied parameters are inapproprate.
*/
public final void init(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException
{
init(params, new SecureRandom());
}
/**
* Initialize this key generator with a set of parameters and a source
* of randomness.
*
* @param params The algorithm parameters.
* @param random The source of randomness.
* @throws java.security.InvalidAlgorithmParameterException If the
* supplied parameters are inapproprate.
*/
public final void init(AlgorithmParameterSpec params, SecureRandom random)
throws InvalidAlgorithmParameterException
{
kgSpi.engineInit(params, random);
}
/**
* Initialize this key generator with a key size (in bits); the
* highest-priority {@link java.security.SecureRandom} implementation
* will be used.
*
* @param keySize The target key size, in bits.
* @throws java.security.InvalidParameterException If the
* key size is unsupported.
*/
public final void init(int keySize)
{
init(keySize, new SecureRandom());
}
/**
* Initialize this key generator with a key size (in bits) and a
* source of randomness.
*
* @param keySize The target key size, in bits.
* @param random The source of randomness.
* @throws java.security.InvalidAlgorithmParameterException If the
* key size is unsupported.
*/
public final void init(int keySize, SecureRandom random)
{
kgSpi.engineInit(keySize, random);
}
/**
* Initialize this key generator with a source of randomness. The
* implementation-specific default parameters (such as key size) will
* be used.
*
* @param random The source of randomness.
*/
public final void init(SecureRandom random)
{
kgSpi.engineInit(random);
}
}
/* KeyGeneratorSpi.java -- The key generator service provider interface.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.InvalidAlgorithmParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
/**
* The <i>Service Provider Interface</i> (<b>SPI</b>) for the {@link
* KeyGenerator} class.
*
* <p>Providers wishing to implement a key generator must subclass this
* and provide an appropriate implementation for all the abstract
* methods below, and provide an appropriate entry in the master {@link
* java.security.Provider} class (the service name for key generators is
* <code>"KeyGenerator"</code>).
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see KeyGenerator
*/
public abstract class KeyGeneratorSpi
{
// Constructor.
// ------------------------------------------------------------------------
/** Create a new key generator SPI. */
public KeyGeneratorSpi()
{
}
// Abstract instance methods.
// ------------------------------------------------------------------------
/**
* Generate a key, returning it as a {@link SecretKey}.
*
* @return The generated key.
*/
protected abstract SecretKey engineGenerateKey();
/**
* Initialize this key generator with parameters and a source of
* randomness.
*
* @param params The parameters.
* @param random The source of randomness.
* @throws java.security.InvalidAlgorithmParameterException If the
* parameters are inappropriate for this instance.
*/
protected abstract void engineInit(AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidAlgorithmParameterException;
/**
* Initialize this key generator with a key size (in bits) and a
* source of randomness.
*
* @param keySize The target key size, in bits.
* @param random The source of randomness.
* @throws java.security.InvalidParameterException If the
* key size is illogical or unsupported.
*/
protected abstract void engineInit(int keySize, SecureRandom random);
/**
* Initialize this key generator with a source of randomness; the
* implementation should use reasonable default parameters (such as
* generated key size).
*
* @param random The source of randomness.
*/
protected abstract void engineInit(SecureRandom random);
}
/* MacSpi.java -- The MAC service provider interface.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
/**
* This is the <i>Service Provider Interface</i> (<b>SPI</b>) for the
* {@link Mac} class.
*
* <p>Providers wishing to implement a Mac must subclass this class and
* provide appropriate implementations of all its abstract methods,
* then provide an entry pointing to this implementation in the master
* {@link java.security.Provider} class.
*
* <p>Implemetations may optionally implement the {@link
* java.lang.Cloneable} interface.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public abstract class MacSpi
{
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new MacSpi instance.
*/
public MacSpi()
{
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Returns a clone of this instance if cloning is supported.
*
* @return A clone of this instance.
* @throws java.lang.CloneNotSupportedException If this instance does
* not support cloneing.
*/
public Object clone() throws CloneNotSupportedException
{
throw new CloneNotSupportedException();
}
// Abstract instance methods.
// ------------------------------------------------------------------------
/**
* Finalize the computation of this MAC and return the result as a
* byte array.
*
* @return The MAC.
*/
protected abstract byte[] engineDoFinal();
/**
* Return the total length, in bytes, of the computed MAC (the length
* of the byte array returned by {@link #doFinal()}.
*
* @return The MAC length.
*/
protected abstract int engineGetMacLength();
/**
* Initialize (or re-initialize) this instance.
*
* @param key The key to use.
* @param params The parameters to use.
* @throws java.security.InvalidAlgorithmParameterException If this
* instance rejects the specified parameters.
* @throws java.security.InvalidKeyException If this instance rejects
* the specified key.
*/
protected abstract void engineInit(Key key, AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException, InvalidKeyException;
/**
* Reset this instance. After this method succeeds, the state of this
* instance should be the same as it was before any data was input
* (possibly after a call to {@link
* #init(java.security.Key,java.security.spec.AlgorithmParameterSpec)},
* possibly not).
*/
protected abstract void engineReset();
/**
* Update this MAC with a single byte.
*
* @param input The next byte.
*/
protected abstract void engineUpdate(byte input);
/**
* Update this MAC with a portion of a byte array.
*
* @param input The next bytes.
* @param offset The index in <code>input</code> at which to start.
* @param length The number of bytes to update.
*/
protected abstract void engineUpdate(byte[] input, int offset, int length);
}
/* NoSuchPaddingException.java -- Signals an unknown padding scheme.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.GeneralSecurityException;
/**
* This exception is thrown when a particular padding scheme is
* requested but is not available.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class NoSuchPaddingException extends GeneralSecurityException
{
// Constant.
// ------------------------------------------------------------------------
/** Serialization constant. */
private static final long serialVersionUID = -4572885201200175466L;
// Constructors.
// ------------------------------------------------------------------------
public NoSuchPaddingException()
{
super();
}
public NoSuchPaddingException(String message)
{
super(message);
}
}
/* NullCipher.java -- The identity cipher.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
/**
* Trivial subclass of Cipher that implements the <i>identity
* transformation</i>, where the input is always copied to the output
* unchanged. Null ciphers can be instantiated with the public
* constructor.
*
* @author Casey Marshall (csm@gnu.org)
*/
public class NullCipher extends Cipher
{
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new identity cipher.
*/
public NullCipher()
{
super(new NullCipherImpl(), null, "NULL");
}
}
/* NullCipherImpl.java -- implementation of NullCipher.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.AlgorithmParameters;
import java.security.Key;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
/**
* Implementation of the identity cipher.
*/
final class NullCipherImpl extends CipherSpi
{
// Constructor.
// -------------------------------------------------------------------------
NullCipherImpl()
{
super();
}
// Instance methods.
// -------------------------------------------------------------------------
protected void engineSetMode(String mode) { }
protected void engineSetPadding(String padding) { }
protected int engineGetBlockSize()
{
return 1;
}
protected int engineGetOutputSize(int inputLen)
{
return inputLen;
}
protected byte[] engineGetIV()
{
return null;
}
protected AlgorithmParameters engineGetParameters()
{
return null;
}
protected void engineInit(int mode, Key key, SecureRandom random) { }
protected void engineInit(int mode, Key key, AlgorithmParameterSpec spec, SecureRandom random) { }
protected void engineInit(int mode, Key key, AlgorithmParameters params, SecureRandom random) { }
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)
{
if (input == null)
return new byte[0];
if (inputOffset < 0 || inputLen < 0 || inputOffset + inputLen > input.length)
throw new ArrayIndexOutOfBoundsException();
byte[] output = new byte[inputLen];
System.arraycopy(input, inputOffset, output, 0, inputLen);
return output;
}
protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
byte[] output, int outputOffset)
throws ShortBufferException
{
if (input == null)
return 0;
if (inputOffset < 0 || inputLen < 0 || inputOffset + inputLen > input.length
|| outputOffset < 0)
throw new ArrayIndexOutOfBoundsException();
if (output.length - outputOffset < inputLen)
throw new ShortBufferException();
System.arraycopy(input, inputOffset, output, outputOffset, inputLen);
return inputLen;
}
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
{
return engineUpdate(input, inputOffset, inputLen);
}
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
byte[] output, int outputOffset)
throws ShortBufferException
{
return engineUpdate(input, inputOffset, inputLen, output, outputOffset);
}
}
/* SecretKey.java -- A key for symmetric cryptography.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is a part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License along
with GNU Classpath; if not, write to the
Free Software Foundation, Inc.,
59 Temple Place, Suite 330,
Boston, MA 02111-1307
USA
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under terms
of your choice, provided that you also meet, for each linked independent
module, the terms and conditions of the license of that module. An
independent module is a module which is not derived from or based on
this library. If you modify this library, you may extend this exception
to your version of the library, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from your
version. */
package javax.crypto;
import java.security.Key;
/**
* A secret key for symmetric cryptography.
*
* <p>This interface defines no new methods over {@link
* java.security.Key}, but rather is intended to be a <i>marker
* interface</i> and to provide type safety for secret keys.</p>
*
* <p>The format of secret keys should be <code>RAW</code>, as returned
* by {@link java.security.Key#getFormat()}.</p>
*
* <p>Concrete implementations of this interface should override the
* {@link java.lang.Object#equals} and {@link java.lang.Object#hashCode}
* methods of {@link java.lang.Object} to use the actual key data rather
* than the identity-based default methods.</p>
*
* @author Casey Marshall (csm@gnu.org)
* @see javax.crypto.SecretKeyFactory
* @see javax.crypto.Cipher
*/
public interface SecretKey extends Key
{
}
/* SecretKeyFactory.java -- Factory for creating secret keys.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.lang.reflect.InvocationTargetException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
import gnu.java.security.Engine;
/**
* A secret key factory translates {@link SecretKey} objects to and from
* {@link java.security.spec.KeySpec} objects, and can translate between
* different vendors' representations of {@link SecretKey} objects (for
* security or semantics; whichever applies).
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see SecretKey
*/
public class SecretKeyFactory
{
// Constants and fields.
// ------------------------------------------------------------------------
private static final String SERVICE = "SecretKeyFactory";
/** The underlying factory implementation. */
private SecretKeyFactorySpi skfSpi;
/** The provider of the implementation. */
private Provider provider;
/** The name of the algorithm. */
private String algorithm;
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new secret key factory.
*
* @param skfSpi The underlying factory implementation.
* @param provider The provider.
* @param algorithm The algorithm name.
*/
protected SecretKeyFactory(SecretKeyFactorySpi skfSpi, Provider provider,
String algorithm)
{
this.skfSpi = skfSpi;
this.provider = provider;
this.algorithm = algorithm;
}
// Class methods.
// ------------------------------------------------------------------------
/**
* Create a new secret key factory from the first appropriate
* instance.
*
* @param algorithm The algorithm name.
* @return The appropriate key factory, if found.
* @throws java.security.NoSuchAlgorithmException If no provider
* implements the specified algorithm.
*/
public static final SecretKeyFactory getInstance(String algorithm)
throws NoSuchAlgorithmException
{
Provider[] provs = Security.getProviders();
for (int i = 0; i < provs.length; i++)
{
try
{
return getInstance(algorithm, provs[i]);
}
catch (NoSuchAlgorithmException nsae)
{
}
}
throw new NoSuchAlgorithmException(algorithm);
}
/**
* Create a new secret key factory from the named provider.
*
* @param algorithm The algorithm name.
* @param provider The provider name.
* @return The appropriate key factory, if found.
* @throws java.security.NoSuchAlgorithmException If the named
* provider does not implement the algorithm.
* @throws java.security.NoSuchProviderException If the named provider
* does not exist.
*/
public static final SecretKeyFactory getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
{
throw new NoSuchProviderException(provider);
}
return getInstance(algorithm, p);
}
/**
* Create a new secret key factory from the specified provider.
*
* @param algorithm The algorithm name.
* @param provider The provider.
* @return The appropriate key factory, if found.
* @throws java.security.NoSuchAlgorithmException If the provider
* does not implement the algorithm.
*/
public static final SecretKeyFactory getInstance(String algorithm,
Provider provider)
throws NoSuchAlgorithmException
{
try
{
return new SecretKeyFactory((SecretKeyFactorySpi)
Engine.getInstance(SERVICE, algorithm, provider),
provider, algorithm);
}
catch (InvocationTargetException ite)
{
if (ite.getCause() == null)
throw new NoSuchAlgorithmException(algorithm);
if (ite.getCause() instanceof NoSuchAlgorithmException)
throw (NoSuchAlgorithmException) ite.getCause();
throw new NoSuchAlgorithmException(algorithm);
}
catch (ClassCastException cce)
{
throw new NoSuchAlgorithmException(algorithm);
}
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Generate a secret key from a key specification, if possible.
*
* @param keySpec The key specification.
* @return The secret key.
* @throws java.security.InvalidKeySpecException If the key specification
* cannot be transformed into a secret key.
*/
public final SecretKey generateSecret(KeySpec keySpec)
throws InvalidKeySpecException
{
return skfSpi.engineGenerateSecret(keySpec);
}
/**
* Get the algorithm name.
*
* @return The algorithm name.
*/
public final String getAlgorithm()
{
return algorithm;
}
/**
* Get the key specification from a secret key.
*
* @param key The secret key.
* @param keySpec The target key specification class.
* @return The key specification.
* @throws java.security.spec.InvalidKeySpecException If the secret key cannot
* be transformed into the specified key specification.
*/
public final KeySpec getKeySpec(SecretKey key, Class keySpec)
throws InvalidKeySpecException
{
return skfSpi.engineGetKeySpec(key, keySpec);
}
/**
* Get the provider of this implementation.
*
* @return The provider.
*/
public final Provider getProvider()
{
return provider;
}
/**
* Translate a secret key into another form.
*
* @param key The key to translate.
* @return The translated key.
* @throws java.security.InvalidKeyException If the argument cannot be
* translated.
*/
public final SecretKey translateKey(SecretKey key)
throws InvalidKeyException
{
return skfSpi.engineTranslateKey(key);
}
}
/* SecretKeyFactorySpi.java -- Secret key factory service provider interface.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.InvalidKeyException;
import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
/**
* The <i>Service Provider Interface</i> (<b>SPI</b>) for the {@link
* SecretKeyFactory} class.
*
* <p>Providers wishing to implement a secret key factory must
* subclass this and provide an appropriate implementation for all the
* abstract methods below, and provide an appropriate entry in the
* master {@link java.security.Provider} class (the service name for
* secret key factories is <code>"SecretKeyFactory"</code>).
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see SecretKeyFactory
*/
public abstract class SecretKeyFactorySpi
{
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new secret key factory SPI.
*/
public SecretKeyFactorySpi()
{
}
// Abstract instance methods.
// ------------------------------------------------------------------------
/**
* Translate a {@link java.security.KeySpec} into a {@link SecretKey}.
*
* @param keySpec The key specification.
* @return The secret key.
* @throws java.security.spec.InvalidKeySpecException If the key specification
* cannot be translated into a secret key.
*/
protected abstract SecretKey engineGenerateSecret(KeySpec keySpec)
throws InvalidKeySpecException;
/**
* Translate a {@link SecretKey} into a {@link java.security.KeySpec}.
*
* @param key The secret key.
* @param keySpec The desired key specification class.
* @return The key specification.
* @throws java.security.spec.InvalidKeySpecException If the secret key cannot
* be translated into the desired key specification.
*/
protected abstract KeySpec engineGetKeySpec(SecretKey key, Class keySpec)
throws InvalidKeySpecException;
/**
* Translate a secret key into a different representation.
*
* @param key The secret key to translate.
* @return The translated key.
* @throws java.security.InvalidKeyException If the specified secret
* key cannot be translated.
*/
protected abstract SecretKey engineTranslateKey(SecretKey key)
throws InvalidKeyException;
}
/* ShortBufferException.java -- Signals a short output buffer.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto;
import java.security.GeneralSecurityException;
/**
* This exception is thrown on an attempt to transform bytes into a
* buffer that is too short to contain the data.
*
* @author Casey Marshall (csm@gnu.org)
*/
public class ShortBufferException extends GeneralSecurityException
{
// Constant.
// ------------------------------------------------------------------------
/** Serialization constant. */
private static final long serialVersionUID = 8427718640832943747L;
// Constructors.
// ------------------------------------------------------------------------
public ShortBufferException()
{
super();
}
public ShortBufferException(String message)
{
super(message);
}
}
/* DHKey.java -- General interface for a Diffie-Hellman key.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.interfaces;
import javax.crypto.spec.DHParameterSpec;
/**
* This interface marks public/private keys in the Diffie-Hellman key
* exchange algorithm. Implementations of Diffie-Hellman keys should
* implement this interface, and applications can safely cast keys that
* are known to be Diffie-Hellman keys to this interface.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public interface DHKey
{
/**
* Returns the Diffie-Hellman parameters for this key, which includes
* the generator and the prime.
*
* @return The Diffie-Hellman parameters.
*/
DHParameterSpec getParams();
}
/* DHPrivateKey.java -- A Diffie-Hellman private key.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.interfaces;
import java.math.BigInteger;
import java.security.PrivateKey;
/**
* This interface marks a private key in the Diffie-Hellman key exchange
* algorithm. It should be treated with as much care as any {@link
* java.security.PrivateKey}.
*
* <p>Implementations of Diffie-Hellman private keys should implement
* this interface. Applications that know a particular key is a
* Diffie-Hellman private key can safely cast it to this interface.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see DHKey
* @see DHPublicKey
*/
public interface DHPrivateKey extends DHKey, PrivateKey
{
/** Compatible with JDK1.4. */
static final long serialVersionUID = 2211791113380396553L;
/**
* Returns the private value <i>x</i>.
*
* @return The private value <i>x</i>.
*/
BigInteger getX();
}
/* DHPublicKey.java -- A Diffie-Hellman public key.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.interfaces;
import java.math.BigInteger;
import java.security.PublicKey;
/**
* This interface marks a public key in the Diffie-Hellman key-exchange
* algorithm.
*
* <p>Implementations of Diffie-Hellman public keys should implement
* this interface. Applications that know that a particular key is a
* Diffie-Hellman public key it can be safely cast to this interface.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see DHKey
* @see DHPrivateKey
*/
public interface DHPublicKey extends DHKey, PublicKey
{
/** Compatible with JDK1.4. */
static final long serialVersionUID = -6628103563352519193L;
/**
* Get the public value <i>y</i>.
*
* @return The public value <i>y</i>.
*/
BigInteger getY();
}
/* PBEKey.java -- A key derived from a password.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.interfaces;
import javax.crypto.SecretKey;
/**
* Interface to a password-derived key for password-based encryption
* (PBE). Applications working with a {@link javax.crypto.SecretKey}
* that is known to be a password-based key can safely cast such keys to
* this interface.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public interface PBEKey extends SecretKey
{
/** Compatible with JDK1.4. */
static final long serialVersionUID = -1430015993304333921L;
/**
* Retruns the iteration count, or 0 if not specified.
*
* @return The iteration count.
*/
int getIterationCount();
/**
* Returns a copy of the password as a character array. It is the
* caller's responsibility to zero-out the password when it is no
* longer in use.
*
* <p>Although it is not specified in the documentation,
* implementations should not copy or clone the password array, but
* rather return the reference to the array itself, so the caller has
* the ability to erase the password.
*
* @return The password.
*/
char[] getPassword();
/**
* Returns a copy of the salt. It is the caller's responsibility to
* zero-out the salt when it is no longer in use.
*
* <p>Although it is not specified in the documentation,
* implementations should not copy or clone the salt array, but
* rather return the reference to the array itself, so the caller has
* the ability to erase the salt.
*
* @return The salt.
*/
byte[] getSalt();
}
/* DESKeySpec -- Keys for DES.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.InvalidKeyException;
import java.security.spec.KeySpec;
/**
* This class is a transparent wrapper for DES keys, which are arrays
* of 8 bytes.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class DESKeySpec implements KeySpec
{
// Constants.
// ------------------------------------------------------------------------
/**
* The length of a DES key, in bytes.
*/
public static final int DES_KEY_LEN = 8;
/**
* The key bytes.
*/
private byte[] key;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new DES key spec, copying the first 8 bytes from the
* byte array.
*
* @param key The key bytes.
* @throws java.security.InvalidKeyException If there are less than 8
* bytes in the array.
*/
public DESKeySpec(byte[] key) throws InvalidKeyException
{
this(key, 0);
}
/**
* Create a new DES key spec, starting at <code>offset</code> in
* the byte array. The first 8 bytes starting at <code>offset</code>
* are copied.
*
* @param key The key bytes.
* @param offset The offset into the byte array at which to begin.
* @throws java.security.InvalidKeyException If there are less than 8
* bytes starting at <code>offset</code>.
*/
public DESKeySpec(byte[] key, int offset) throws InvalidKeyException
{
if (key.length - offset < DES_KEY_LEN)
{
throw new InvalidKeyException("DES keys must be 8 bytes long");
}
this.key = new byte[DES_KEY_LEN];
System.arraycopy(key, offset, this.key, 0, DES_KEY_LEN);
}
// Class methods.
// ------------------------------------------------------------------------
/**
* Returns whether or not the given key is <i>parity adjusted</i>;
* i.e. every byte in the key has an odd number of "1" bits.
*
* @param key The key bytes, considered between <code>[offset,
* offset+7]</code>
* @param offset The offset into the byte array at which to begin.
* @return True if all bytes have an odd number of "1" bits.
* @throws java.security.InvalidKeyException If there are not enough
* bytes in the array.
*/
public static boolean isParityAdjusted(byte[] key, int offset)
throws InvalidKeyException
{
if (key.length - offset < DES_KEY_LEN)
{
throw new InvalidKeyException("DES keys must be 8 bytes long");
}
boolean parity = false;
boolean oddbits = false;
for (int i = 0; i < DES_KEY_LEN; i++)
{
oddbits = false;
for (int j = 0; j < 8; j++)
{
oddbits ^= (key[i+offset] & 1 << j) != 0;
}
parity &= oddbits;
}
return parity;
}
/**
* One-half of the weak and semiweak DES keys (the other half are the
* complements of these).
*/
private static final byte[][] WEAK_KEYS = new byte[][] {
{ 0, 0, 0, 0, 0, 0, 0, 0 }, // 0000 0000 0000 0000
{ -1, -1, -1, -1, 0, 0, 0, 0 }, // ffff ffff 0000 0000
{ 1, 1, 1, 1, 1, 1, 1, 1 }, // 0101 0101 0101 0101
{ 31, 31, 31, 31, 14, 14, 14, 14 }, // 1f1f 1f1f 0e0e 0e0e
{ 1, -2, 1, -2, 1, -2, 1, -2 }, // 01fe 01fe 01fe 01fe
{ 31, -32, 31, -32, -32, 31, -32, 31 }, // 1fe0 1fe0 0e1f 0e1f
{ 1, -32, 1, -32, 1, -15, 1, -15 }, // 01e0 01e0 01f1 01f1
{ 31, -2, 31, -2, 14, -2, 14, -2 }, // 1ffe 1ffe 0efe 0efe
{ 1, 31, 1, 31, 1, 14, 1, 14 }, // 011f 011f 010e 010e
{ -32, -2, -32, -2, -15, -2, -15, -2 }, // e0fe e0fe f1fe f1fe
};
/**
* Tests if the bytes between <code>[offset, offset+7]</code>
* constitute a weak or semi-weak DES key.
*
* @param key The key bytes to check.
* @param offset The offset in the byte array to start.
* @return true If the key bytes are a weak key.
*/
public static boolean isWeak(byte[] key, int offset)
throws InvalidKeyException
{
if (key.length - offset < DES_KEY_LEN)
{
throw new InvalidKeyException("DES keys must be 8 bytes long");
}
for (int i = 0; i < WEAK_KEYS.length; i++)
{
if (equalsOrComplementEquals(key, offset, WEAK_KEYS[i]))
{
return true;
}
}
return false;
}
/**
* This method returns true if the first 8 bytes starting at
* <code>off</code> in <code>a</code> equal the first 8 bytes in
* <code>b</code>, or equal the <i>complement</i> of the first 8 bytes
* in <code>b</code>.
*
* @param a The first byte array.
* @param off The index into the first byte array.
* @param b The second byte array.
* @return <code>a == b || a == ~b</code>
*/
private static boolean equalsOrComplementEquals(byte[] a, int off, byte[] b)
{
boolean result = true;
for (int i = 0; i < DES_KEY_LEN; i++)
{
result &= a[off+i] == b[i];
}
if (result) return true;
result = true;
for (int i = 0; i < DES_KEY_LEN; i++)
{
result &= a[off+i] == (~b[i]);
}
return result;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Return the key as a byte array. This method does not copy the byte
* array.
*
* @return The key bytes.
*/
public byte[] getKey()
{
return key;
}
}
/* DESedeKeySpec.java -- Keys for triple-DES.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.InvalidKeyException;
import java.security.spec.KeySpec;
/**
* This class is a transparent wrapper for DES-EDE (Triple-DES) keys,
* which are arrays of 24 bytes.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class DESedeKeySpec implements KeySpec
{
// Constants.
// ------------------------------------------------------------------------
/**
* The length of a triple-DES key, in bytes.
*/
public static final int DES_EDE_KEY_LEN = 24;
/**
* The key bytes.
*/
private byte[] key;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new DES-EDE key spec, copying the first 24 bytes from the
* byte array.
*
* @param key The key bytes.
* @throws java.security.InvalidKeyException If there are less than 24
* bytes in the array.
*/
public DESedeKeySpec(byte[] key) throws InvalidKeyException
{
this(key, 0);
}
/**
* Create a new DES-EDE key spec, starting at <code>offset</code> in
* the byte array. The first 24 bytes starting at <code>offset</code>
* are copied.
*
* @param key The key bytes.
* @param offset The offset into the byte array at which to begin.
* @throws java.security.InvalidKeyException If there are less than 24
* bytes starting at <code>offset</code>.
*/
public DESedeKeySpec(byte[] key, int offset) throws InvalidKeyException
{
if (key.length - offset < DES_EDE_KEY_LEN)
{
throw new InvalidKeyException("DES-EDE keys must be 24 bytes long");
}
this.key = new byte[DES_EDE_KEY_LEN];
System.arraycopy(key, offset, this.key, 0, DES_EDE_KEY_LEN);
}
// Class methods.
// ------------------------------------------------------------------------
/**
* Returns whether or not the given key is <i>parity adjusted</i>;
* i.e. every byte in the key has an odd number of "1" bits.
*
* @param key The key bytes, considered between <code>[offset,
* offset+23]</code>
* @param offset The offset into the byte array at which to begin.
* @return True if all bytes have an odd number of "1" bits.
* @throws java.security.InvalidKeyException If there are not enough
* bytes in the array.
*/
public static boolean isParityAdjusted(byte[] key, int offset)
throws InvalidKeyException
{
if (key.length - offset < DES_EDE_KEY_LEN)
{
throw new InvalidKeyException("DES-EDE keys must be 24 bytes long");
}
boolean parity = false;
boolean oddbits = false;
for (int i = 0; i < DES_EDE_KEY_LEN; i++)
{
oddbits = false;
for (int j = 0; j < 8; j++)
{
oddbits ^= (key[i+offset] & 1 << j) != 0;
}
parity &= oddbits;
}
return parity;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Return the key as a byte array. This method does not copy the byte
* array.
*
* @return The key bytes.
*/
public byte[] getKey()
{
return key;
}
}
/* DHGenParameterSpec.java -- Diffie-Hellman parameter generator spec.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* This class represents the parameters needed for generating
* Diffie-Hellman parameters.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see DHParameterSpec
*/
public class DHGenParameterSpec implements AlgorithmParameterSpec
{
// Variables.
// ------------------------------------------------------------------------
/** The length of the prime, in bits. */
private int primeSize;
/** The length of the exponent, in bits. */
private int exponentSize;
// Constructor.
// ------------------------------------------------------------------------
/**
* Create a new Diffie-Hellman parameter generator spec.
*
* @param primeSize The size of the prime, in bits.
* @param exponentSize The size of the exponent, in bits.
*/
public DHGenParameterSpec(int primeSize, int exponentSize)
{
this.primeSize = primeSize;
this.exponentSize = exponentSize;
}
// Intance methods.
// ------------------------------------------------------------------------
/**
* Get the size of the exponent, in bits.
*
* @return The exponent size.
*/
public int getExponentSize()
{
return exponentSize;
}
/**
* Get the size of the prime, in bits.
*
* @return The prime size.
*/
public int getPrimeSize()
{
return primeSize;
}
}
/* DHParameterSpec.java -- Parameters for Diffie-Hellman keys.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
/**
* The base set of parameters necessary to perform Diffie-Hellman key
* exchange. Each party in the key exchange shares these parameters.
*
* <p>Each set of parameters consists of a <i>base generator</i>
* <code>g</code>, a <i>prime modulus</i> <code>p</code>, and an
* optional length, in bits, of the private exponent.
*
* <p>See <a href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-3/">PKCS
* #3 - Diffie-Hellman Key Agreement Standard</a> for more information.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see javax.crypto.KeyAgreement
*/
public class DHParameterSpec implements AlgorithmParameterSpec
{
// Variables.
// ------------------------------------------------------------------------
/** The base generator g. */
private BigInteger g;
/** The prime modulus p. */
private BigInteger p;
/** The length, in bits, of the private exponent. */
private int l;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new set of Diffie-Hellman parameters.
*
* @param p The prime modulus.
* @param g The base generator.
*/
public DHParameterSpec(BigInteger p, BigInteger g)
{
this(p, g, 0);
}
/**
* Create a new set of Diffie-Hellman parameters.
*
* @param p The prime modulus.
* @param g The base generator.
* @param l The size of the private exponent, in bits.
*/
public DHParameterSpec(BigInteger p, BigInteger g, int l)
{
this.p = p;
this.g = g;
this.l = l;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Get the base generator, <i>g</i>.
*
* @return The base generator <i>g</i>.
*/
public BigInteger getG()
{
return g;
}
/**
* Get the length of the private exponent, in bits.
*
* @return The length of the private exponent, in bits, or 0 if this
* has not been explicitly set.
*/
public int getL()
{
return l;
}
/**
* Get the prime modulus, <i>p</i>.
*
* @return The prime modulus, <i>p</i>.
*/
public BigInteger getP()
{
return p;
}
}
/* DHPrivateKeySpec.java -- Wrapper for Diffie-Hellman private keys.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.math.BigInteger;
import java.security.spec.KeySpec;
/**
* A wrapper for Diffie-Hellman private key data.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see DHPublicKeySpec
*/
public class DHPrivateKeySpec implements KeySpec
{
// Variables.
// ------------------------------------------------------------------------
/** The base generator. */
private BigInteger g;
/** The prime modulus. */
private BigInteger p;
/** The private exponent. */
private BigInteger x;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new Diffie-Hellman private key spec.
*
* @param x The private exponent.
* @param p The prime modulus.
* @param g The base generator.
*/
public DHPrivateKeySpec(BigInteger x, BigInteger p, BigInteger g)
{
this.x = x;
this.p = p;
this.g = g;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Get the base generator.
*
* @return The base generator.
*/
public BigInteger getG()
{
return g;
}
/**
* Get the prime modulus.
*
* @return The prime modulus.
*/
public BigInteger getP()
{
return p;
}
/**
* Get the private exponent.
*
* @return The private exponent.
*/
public BigInteger getX()
{
return x;
}
}
/* DHPublicKeySpec.java -- Wrapper for Diffie-Hellman public keys.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.math.BigInteger;
import java.security.spec.KeySpec;
/**
* A wrapper for Diffie-Hellman public key data.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see DHPrivateKeySpec
*/
public class DHPublicKeySpec implements KeySpec
{
// Variables.
// ------------------------------------------------------------------------
/** The base generator. */
private BigInteger g;
/** The prime modulus. */
private BigInteger p;
/** The public value. */
private BigInteger y;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new Diffie-Hellman public key spec.
*
* @param y The public value.
* @param p The prime modulus.
* @param g The base generator.
*/
public DHPublicKeySpec(BigInteger y, BigInteger p, BigInteger g)
{
this.y = y;
this.p = p;
this.g = g;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Get the base generator.
*
* @return The base generator.
*/
public BigInteger getG()
{
return g;
}
/**
* Get the prime modulus.
*
* @return The prime modulus.
*/
public BigInteger getP()
{
return p;
}
/**
* Get the public value.
*
* @return The public value.
*/
public BigInteger getY()
{
return y;
}
}
/* IvParameterSpec.java -- A simple wrapper for initialization vectors.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* A wrapper for an initialization vector. An initialization vector is
* necessary for any cipher in any <i>feedback mode</i>, e.g. CBC.
*
* @author Casey Marshall (csm@gnu.org)
*/
public class IvParameterSpec implements AlgorithmParameterSpec
{
// Fields.
// ------------------------------------------------------------------------
/** The IV. */
private byte[] iv;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new initialization vector spec from an entire byte array.
*
* @param iv The IV bytes.
*/
public IvParameterSpec(byte[] iv)
{
this(iv, 0, iv.length);
}
/**
* Create a new initialization vector spec from part of a byte array.
*
* @param iv The IV bytes.
* @param off The offset into the IV bytes.
* @param len The number of IV bytes.
*/
public IvParameterSpec(byte[] iv, int off, int len)
{
this.iv = new byte[len];
System.arraycopy(iv, off, this.iv, 0, len);
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Returns the IV. This method does not copy the byte array.
*
* @return The IV.
*/
public byte[] getIV()
{
return iv;
}
}
/* PBEKeySpec.java -- Wrapper for password-based keys.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.KeySpec;
/**
* A wrapper for a password-based key, used for password-based
* encryption (PBE).
*
* <p>Examples of password-based encryption algorithms include:
*
* <ul>
* <li><a href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-5/">PKCS #5
* - Password-Based Cryptography Standard</a></li>
* <li><a href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-12/">PKCS
* #12 - Personal Information Exchange Syntax Standard</a></li>
* </ul>
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
* @see javax.crypto.SecretKeyFactory
* @see PBEParameterSpec
*/
public class PBEKeySpec implements KeySpec
{
// Fields.
// ------------------------------------------------------------------------
/** The iteration count. */
private int iterationCount;
/** The generated key length. */
private int keyLength;
/** The password. */
private char[] password;
/** The salt. */
private byte[] salt;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new PBE key spec with just a password.
*
* @param password The password char array.
*/
public PBEKeySpec(char[] password)
{
this(password, null, 0, 0);
}
/**
* Create a PBE key spec with a password, salt, and iteration count.
*
* @param password The password char array.
* @param salt The salt bytes.
* @param iterationCount The iteration count.
*/
public PBEKeySpec(char[] password, byte[] salt, int iterationCount)
{
this(password, salt, iterationCount, 0);
}
/**
* Create a PBE key spec with a password, salt, iteration count, and
* key length.
*
* @param password The password char array.
* @param salt The salt bytes.
* @param iterationCount The iteration count.
* @param keyLength The generated key length.
*/
public PBEKeySpec(char[] password, byte[] salt, int iterationCount,
int keyLength)
{
this.password = password;
this.salt = salt;
this.iterationCount = iterationCount;
this.keyLength = keyLength;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Clear the password array by filling it with null characters.
*/
public final void clearPassword()
{
if (password == null) return;
for (int i = 0; i < password.length; i++)
{
password[i] = '\u0000';
}
}
/**
* Get the iteration count, or 0 if it has not been specified.
*
* @return The iteration count, or 0 if it has not been specified.
*/
public final int getIterationCount()
{
return iterationCount;
}
/**
* Get the generated key length, or 0 if it has not been specified.
*
* @return The key length, or 0 if it has not been specified.
*/
public final int getKeyLength()
{
return keyLength;
}
/**
* Get the password character array.
*
* @return The password.
*/
public final char[] getPassword()
{
return password;
}
/**
* Get the salt bytes.
*
* @return The salt.
*/
public final byte[] getSalt()
{
return salt;
}
}
/* PBEParameterSpec.java -- A wrapper for PBE parameters.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* A wrapper for the parameters used in <a
* href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-5/">PKCS #5 -
* Password-Based Cryptography Standard</a>.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class PBEParameterSpec implements AlgorithmParameterSpec
{
// Fields.
// ------------------------------------------------------------------------
/** The iteration count. */
private int iterationCount;
/** The salt. */
private byte[] salt;
// Constructor.
// ------------------------------------------------------------------------
/**
* Creates a new password-based encryption parameter specification.
*
* @param salt The salt.
* @param iterationCount The iteration count.
*/
public PBEParameterSpec(byte[] salt, int iterationCount)
{
this.salt = salt;
this.iterationCount = iterationCount;
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Get the iteration count.
*
* @return The iteration count.
*/
public int getIterationCount()
{
return iterationCount;
}
/**
* Get the salt.
*
* @return The salt.
*/
public byte[] getSalt()
{
return salt;
}
}
/* RC2ParameterSpec.java -- Wrapper for RC2 parameters.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* A wrapper for parameters for the <a
* href="http://www.rsasecurity.com/rsalabs/faq/3-6-2.html">RC2</a>
* block cipher ("RC" means either "Rivest Cipher" or "Ron's Code",
* depending upon who you ask and when).
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class RC2ParameterSpec implements AlgorithmParameterSpec
{
// Constants and fields.
// ------------------------------------------------------------------------
/** The length of an RC2 IV, in bytes. */
private static final int RC2_IV_LENGTH = 8;
/** The effective key length, in bits. */
private int effectiveKeyBits;
/** The initialization vector. */
private byte[] iv;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create RC2 parameters without an IV.
*
* @param effectiveKeyBits The number of effective key bits.
*/
public RC2ParameterSpec(int effectiveKeyBits)
{
this.effectiveKeyBits = effectiveKeyBits;
}
/**
* Create RC2 parameters with an IV.
*
* @param effectiveKeyBits The number of effective key bits.
* @param iv The IV; the first eight bytes of this array
* are used.
*/
public RC2ParameterSpec(int effectiveKeyBits, byte[] iv)
{
this(effectiveKeyBits, iv, 0);
}
/**
* Create RC2 parameters with an IV.
*
* @param effectiveKeyBits The number of effective key bits.
* @param iv The IV; the first eight bytes of this array
* after <code>offset</code> are used.
* @param offset From whence to start in the array.
*/
public RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset)
{
if (iv.length - offset < RC2_IV_LENGTH)
{
throw new IllegalArgumentException("IV too short");
}
this.effectiveKeyBits = effectiveKeyBits;
this.iv = new byte[RC2_IV_LENGTH];
System.arraycopy(iv, offset, this.iv, 0, RC2_IV_LENGTH);
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Get the number of effective key bits.
*
* @return The numer of effective key bits.
*/
public int getEffectiveKeyBits()
{
return effectiveKeyBits;
}
/**
* Return the initialization vector, or <code>null</code> if none was
* specified.
*
* @return The IV, or null.
*/
public byte[] getIV()
{
return iv;
}
public boolean equals(Object o)
{
if (this == o) return true;
byte[] oiv = ((RC2ParameterSpec) o).getIV();
if (iv != oiv)
{
if (iv == null || oiv == null) return false;
if (iv.length != oiv.length) return false;
for (int i = 0; i < iv.length; i++)
{
if (iv[i] != oiv[i])
{
return false;
}
}
}
return effectiveKeyBits == ((RC2ParameterSpec) o).getEffectiveKeyBits();
}
public int hashCode()
{
int code = effectiveKeyBits;
if (iv != null)
{
for (int i = 0; i < RC2_IV_LENGTH; i++)
{
code += iv[i];
}
}
return code;
}
}
/* RC5ParameterSpec.java -- parameters for RC5.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* A wrapper for parameters to the <a
* href="http://www.rsasecurity.com/rsalabs/faq/3-6-4.html">RC5</a>
* block cipher.
*
* @author Casey Marshall (csm@gnu.org)
* @since 1.4
*/
public class RC5ParameterSpec implements AlgorithmParameterSpec
{
// Fields.
// ------------------------------------------------------------------------
/** The IV. */
private byte[] iv;
/** The number of rounds. */
private int rounds;
/** The version number. */
private int version;
/** The word size, in bits. */
private int wordSize;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create RC5 parameters without an IV.
*
* @param version The version number.
* @param rounds The number of rounds.
* @param wordSize The size of a word, in bits.
*/
public RC5ParameterSpec(int version, int rounds, int wordSize)
{
this.version = version;
this.rounds = rounds;
this.wordSize = wordSize;
}
/**
* Create RC5 parameters with an IV. The bytes in <code>iv</code> in
* the range <code>[0, 2*(wordSize/8)-1]</code> are used.
*
* @param version The version number.
* @param rounds The number of rounds.
* @param wordSize The size of a word, in bits.
* @param iv The IV data.
*/
public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv)
{
this(version, rounds, wordSize, iv, 0);
}
/**
* Create RC5 parameters with an IV. The bytes in <code>iv</code> in
* the range <code>[off, off+2*(wordSize/8)-1]</code> are used.
*
* @param version The version number.
* @param rounds The number of rounds.
* @param wordSize The size of a word, in bits.
* @param iv The IV data.
* @param off From where in the array the IV starts.
*/
public
RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv, int off)
{
this(version, rounds, wordSize);
int ivLength = 2 * (wordSize / 8);
if (off < 0)
throw new IllegalArgumentException();
if (iv.length - off < ivLength)
{
throw new IllegalArgumentException("IV too short");
}
this.iv = new byte[ivLength];
System.arraycopy(iv, off, this.iv, 0, ivLength);
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Return the initializaiton vector, or <code>null</code> if none was
* specified.
*
* @return The IV, or null.
*/
public byte[] getIV()
{
return iv;
}
/**
* Get the number of rounds.
*
* @return The number of rounds.
*/
public int getRounds()
{
return rounds;
}
/**
* Get the version number.
*
* @return The version number.
*/
public int getVersion()
{
return version;
}
/**
* Get the word size, in bits.
*
* @return The word size, in bits.
*/
public int getWordSize()
{
return wordSize;
}
public boolean equals(Object o)
{
if (this == o) return true;
byte[] oiv = ((RC5ParameterSpec) o).getIV();
if (iv != oiv)
{
if (iv == null || oiv == null) return false;
if (iv.length != oiv.length) return false;
for (int i = 0; i < iv.length; i++)
{
if (iv[i] != oiv[i])
{
return false;
}
}
}
return rounds == ((RC5ParameterSpec) o).getRounds()
&& version == ((RC5ParameterSpec) o).getVersion()
&& wordSize == ((RC5ParameterSpec) o).getWordSize();
}
public int hashCode()
{
int code = rounds + version + wordSize;
if (iv != null)
{
for (int i = 0; i < iv.length; i++)
{
code += iv[i];
}
}
return code;
}
}
/* SecretKeySpec.java -- Wrapper for secret keys.
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.crypto.spec;
import java.security.spec.KeySpec;
import javax.crypto.SecretKey;
/**
* This is a simple wrapper around a raw byte array, for ciphers that do
* not require any key parameters other than the bytes themselves.
*
* <p>Since this class implements {@link javax.crypto.SecretKey}, which
* in turn extends {@link java.security.Key}, so instances of this class
* may be passed directly to the <code>init()</code> methods of {@link
* javax.crypto.Cipher}.
*
* @see javax.crypto.SecretKey
* @see javax.crypto.SecretKeyFactory
*/
public class SecretKeySpec implements KeySpec, SecretKey
{
// Constants and fields.
// ------------------------------------------------------------------------
/** Compatible with JDK1.4. */
private static final long serialVersionUID = 6577238317307289933L;
/** The key bytes. */
private byte[] key;
/** The algorithm's name. */
private String algorithm;
// Constructors.
// ------------------------------------------------------------------------
/**
* Create a new secret key spec from an entire byte array.
*
* @param key The key material.
* @param algorithm The name of the algorithm using this key.
*/
public SecretKeySpec(byte[] key, String algorithm)
{
this(key, 0, key.length, algorithm);
}
/**
* Create a new secret key spec from part of a byte array.
*
* @param key The key material.
* @param off The offset at which key material begins.
* @param len The length of key material.
* @param algorithm The name of the algorithm using this key.
*/
public SecretKeySpec(byte[] key, int off, int len, String algorithm)
{
this.key = new byte[len];
this.algorithm = algorithm;
System.arraycopy(key, off, this.key, 0, len);
}
// Instance methods.
// ------------------------------------------------------------------------
/**
* Return the name of the algorithm associated with this secret key.
*
* @return The algorithm's name.
*/
public String getAlgorithm()
{
return algorithm;
}
/**
* Return the key as a byte array.
*
* @return The key material.
*/
public byte[] getEncoded()
{
return key;
}
/**
* This key's format, which is always "RAW".
*
* @return "RAW"
*/
public String getFormat()
{
return "RAW";
}
public boolean equals(Object o)
{
byte[] okey = ((SecretKeySpec) o).getEncoded();
if (key.length != okey.length) return false;
for (int i = 0; i < key.length; i++)
{
if (key[i] != okey[i])
return false;
}
return algorithm.equals(((SecretKeySpec) o).getAlgorithm());
}
public int hashCode()
{
int code = 0;
for (int i = 0; i < key.length; i++)
{
code ^= (key[i] & 0xff) << (i << 3 & 31);
}
return code ^ algorithm.hashCode();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment