diff options
| author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-14 23:12:35 +0000 |
|---|---|---|
| committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-08-14 23:12:35 +0000 |
| commit | ffde862e033a0825e1e9972a89c0f1f80b261a8e (patch) | |
| tree | 97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java | |
| parent | b415ff10527e977c3758234fd930e2c027bfa17d (diff) | |
| download | ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.tar.gz ppe42-gcc-ffde862e033a0825e1e9972a89c0f1f80b261a8e.zip | |
2006-08-14 Mark Wielaard <mark@klomp.org>
Imported GNU Classpath 0.92
* HACKING: Add more importing hints. Update automake version
requirement.
* configure.ac (gconf-peer): New enable AC argument.
Add --disable-gconf-peer and --enable-default-preferences-peer
to classpath configure when gconf is disabled.
* scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and
gnu/java/awt/dnd/peer/gtk to bc. Classify
gnu/java/security/Configuration.java as generated source file.
* gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java,
gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java,
gnu/java/lang/management/VMClassLoadingMXBeanImpl.java,
gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java,
gnu/java/lang/management/VMThreadMXBeanImpl.java,
gnu/java/lang/management/VMMemoryMXBeanImpl.java,
gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub
classes.
* java/lang/management/VMManagementFactory.java: Likewise.
* java/net/VMURLConnection.java: Likewise.
* gnu/java/nio/VMChannel.java: Likewise.
* java/lang/Thread.java (getState): Add stub implementation.
* java/lang/Class.java (isEnum): Likewise.
* java/lang/Class.h (isEnum): Likewise.
* gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed.
* javax/naming/spi/NamingManager.java: New override for StackWalker
functionality.
* configure, sources.am, Makefile.in, gcj/Makefile.in,
include/Makefile.in, testsuite/Makefile.in: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java')
| -rw-r--r-- | libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java | 146 |
1 files changed, 43 insertions, 103 deletions
diff --git a/libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java b/libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java index bae7cbf88f4..a85c962235e 100644 --- a/libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java +++ b/libjava/classpath/gnu/javax/crypto/jce/params/BlockCipherParameters.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.javax.crypto.jce.params; +import gnu.java.security.Configuration; import gnu.javax.crypto.jce.spec.BlockCipherParameterSpec; import java.io.IOException; @@ -46,40 +47,34 @@ import java.math.BigInteger; import java.security.AlgorithmParametersSpi; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidParameterSpecException; +import java.util.logging.Logger; + +import javax.crypto.spec.IvParameterSpec; /** - * An implementation of algorithm parameters for the GNU Crypto block - * ciphers. This encompasses the cipher's block size, its key size, and - * an optional initialization vector (IV). + * An implementation of algorithm parameters for the GNU block ciphers. This + * encompasses the cipher's block size, its key size, and an optional + * initialization vector (IV). */ -public class BlockCipherParameters extends AlgorithmParametersSpi +public class BlockCipherParameters + extends AlgorithmParametersSpi { - - // Constants and variables. - // ----------------------------------------------------------------------- - - /** - * The underlying block cipher specification. - */ + private static final Logger log = Logger.getLogger(BlockCipherParameters.class.getName()); + /** The underlying block cipher specification. */ protected BlockCipherParameterSpec cipherSpec; - private static final String DEFAULT_FORMAT = "ASN.1"; - // Instance methods implementing AlgorithmParametersSpi. - // ----------------------------------------------------------------------- - /** * Return these parameters encoded in ASN.1 (DER). - * - * <p>For GNU Crypto block ciphers we will define these parameters as - * - * <blockquote> - * <pre>BlockCipherParameters ::= SEQUENCE { - * blockSize INTEGER, - * keySize INTEGER, - * initializationVector OCTET STRING OPTIONAL }</pre> - * </blockquote> - * + * <p> + * For GNU block ciphers we will define these parameters as + * <pre> + * BlockCipherParameters ::= SEQUENCE { + * blockSize INTEGER, + * keySize INTEGER, + * initializationVector OCTET STRING OPTIONAL } + * </pre> + * * @return The parameters, encoded an an ASN.1 DER sequence. * @throws java.io.IOException If encoding these parameters fails. */ @@ -90,114 +85,59 @@ public class BlockCipherParameters extends AlgorithmParametersSpi protected byte[] engineGetEncoded(String format) throws IOException { - if (!format.equalsIgnoreCase(DEFAULT_FORMAT) - && !format.equalsIgnoreCase("asn1")) - { - throw new IOException("unknown format \"" + format + "\""); - } - // This is probably a bad idea. - /* - int len = 12 + ((cipherSpec.getIV() != null) - ? cipherSpec.getIV().length + 2 : 0); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - out.write(0x30); - out.write(len); - out.write(0x02); - out.write(4); - out.write(cipherSpec.getBlockSize() >>> 24 & 0xff); - out.write(cipherSpec.getBlockSize() >>> 16 & 0xff); - out.write(cipherSpec.getBlockSize() >>> 8 & 0xff); - out.write(cipherSpec.getBlockSize() & 0xff); - out.write(0x02); - out.write(4); - out.write(cipherSpec.getKeySize() >>> 24 & 0xff); - out.write(cipherSpec.getKeySize() >>> 16 & 0xff); - out.write(cipherSpec.getKeySize() >>> 8 & 0xff); - out.write(cipherSpec.getKeySize() & 0xff); - if (cipherSpec.getIV() != null) { - out.write(0x04); - len = cipherSpec.getIV().length; - out.write(len & 0xff); - out.write(cipherSpec.getIV()); - } - out.write(0); out.write(0); - return out.toByteArray();*/ + if (! format.equalsIgnoreCase(DEFAULT_FORMAT) + && ! format.equalsIgnoreCase("asn1")) + throw new IOException("unknown format \"" + format + "\""); DERWriter writer = new DERWriter(); + int cipherBlockSize = cipherSpec.getBlockSize(); + int cipherKeySize = cipherSpec.getKeySize(); + byte[] iv = cipherSpec.getIV(); return writer.joinarrays( - writer.writeBigInteger(BigInteger.valueOf(cipherSpec.getBlockSize())), - writer.writeBigInteger(BigInteger.valueOf(cipherSpec.getKeySize())), - (cipherSpec.getIV() != null) ? writer.writeBigInteger(new BigInteger( - cipherSpec.getIV())) - : new byte[0]); + writer.writeBigInteger(BigInteger.valueOf(cipherBlockSize)), + writer.writeBigInteger(BigInteger.valueOf(cipherKeySize)), + (iv != null) ? writer.writeBigInteger(new BigInteger(iv)) + : new byte[0]); } protected void engineInit(AlgorithmParameterSpec spec) throws InvalidParameterSpecException { if (spec instanceof BlockCipherParameterSpec) - { - cipherSpec = (BlockCipherParameterSpec) spec; - } + cipherSpec = (BlockCipherParameterSpec) spec; else - { - throw new InvalidParameterSpecException(); - } + throw new InvalidParameterSpecException(); } protected void engineInit(byte[] encoded, String format) throws IOException { - if (!format.equalsIgnoreCase(DEFAULT_FORMAT) - && !format.equalsIgnoreCase("ASN1")) - { - throw new IOException("invalid format: only accepts ASN.1"); - } + if (! format.equalsIgnoreCase(DEFAULT_FORMAT) + && ! format.equalsIgnoreCase("ASN1")) + throw new IOException("invalid format: only accepts ASN.1"); engineInit(encoded); } protected void engineInit(byte[] encoded) throws IOException { - // This is probably an equally bad idea. - /*if (encoded[0] != 0x30) { - throw new IOException("malformed ASN.1 sequence"); - } - if (encoded[2] != 0x02 || encoded[3] != 4) { - throw new IOException("malformed ASN.1 sequence"); - } - int blockSize = encoded[4] << 24 | encoded[5] << 16 - | encoded[6] << 8 | encoded[7]; - if (encoded[8] != 0x02 || encoded[9] != 4) { - throw new IOException("malformed ASN.1 sequence"); - } - int keySize = encoded[10] << 24 | encoded[11] << 16 - | encoded[12] << 8 | encoded[13]; - if (encoded[14] == 0x04) { - int len = encoded[15] & 0xff; - byte[] iv = new byte[len]; - System.arraycopy(encoded, 16, iv, 0, len); - cipherSpec = new BlockCipherParameterSpec(iv, blockSize, keySize); - } else if (encoded[14] == 0) { - cipherSpec = new BlockCipherParameterSpec(blockSize, keySize); - } else { - throw new IOException("malformed ASN.1 sequence"); - }*/ DERReader reader = new DERReader(encoded); int bs = reader.getBigInteger().intValue(); int ks = reader.getBigInteger().intValue(); byte[] iv = null; if (reader.hasMorePrimitives()) - { - iv = reader.getBigInteger().toByteArray(); - } + iv = reader.getBigInteger().toByteArray(); cipherSpec = new BlockCipherParameterSpec(iv, bs, ks); - System.out.println(cipherSpec); + if (Configuration.DEBUG) + log.fine("cipherSpec: " + cipherSpec); } protected AlgorithmParameterSpec engineGetParameterSpec(Class c) throws InvalidParameterSpecException { if (c.isInstance(cipherSpec)) + return cipherSpec; + if (IvParameterSpec.class.isAssignableFrom(c)) { - return cipherSpec; + IvParameterSpec result = new IvParameterSpec(cipherSpec.getIV()); + return result; } throw new InvalidParameterSpecException(); } @@ -206,4 +146,4 @@ public class BlockCipherParameters extends AlgorithmParametersSpi { return cipherSpec.toString(); } -}
\ No newline at end of file +} |

