diff options
31 files changed, 245 insertions, 203 deletions
diff --git a/src/main/java/org/bouncycastle/asn1/cmp/PKIFreeText.java b/src/main/java/org/bouncycastle/asn1/cmp/PKIFreeText.java index 72d7c013..5b63c194 100644 --- a/src/main/java/org/bouncycastle/asn1/cmp/PKIFreeText.java +++ b/src/main/java/org/bouncycastle/asn1/cmp/PKIFreeText.java @@ -74,7 +74,8 @@ public class PKIFreeText String[] strs) { ASN1EncodableVector v = new ASN1EncodableVector(); - for (int i = 0; i < strs.length; i++) { + for (int i = 0; i < strs.length; i++) + { v.add(new DERUTF8String(strs[i])); } strings = new DERSequence(v); diff --git a/src/main/java/org/bouncycastle/asn1/eac/BidirectionalMap.java b/src/main/java/org/bouncycastle/asn1/eac/BidirectionalMap.java index 5c755ff0..3cf14503 100644 --- a/src/main/java/org/bouncycastle/asn1/eac/BidirectionalMap.java +++ b/src/main/java/org/bouncycastle/asn1/eac/BidirectionalMap.java @@ -2,20 +2,22 @@ package org.bouncycastle.asn1.eac; import java.util.Hashtable; -public class BidirectionalMap extends Hashtable{ +public class BidirectionalMap + extends Hashtable +{ private static final long serialVersionUID = -7457289971962812909L; - + Hashtable reverseMap = new Hashtable(); - + public Object getReverse(Object o) { return reverseMap.get(o); } - + public Object put(Object key, Object o) { reverseMap.put(o, key); return super.put(key, o); } - + } diff --git a/src/main/java/org/bouncycastle/asn1/icao/CscaMasterList.java b/src/main/java/org/bouncycastle/asn1/icao/CscaMasterList.java index 1e154153..2cae261f 100644 --- a/src/main/java/org/bouncycastle/asn1/icao/CscaMasterList.java +++ b/src/main/java/org/bouncycastle/asn1/icao/CscaMasterList.java @@ -13,17 +13,17 @@ import org.bouncycastle.asn1.x509.Certificate; /** * The CscaMasterList object. This object can be wrapped in a * CMSSignedData to be published in LDAP. - * + * <p/> * <pre> * CscaMasterList ::= SEQUENCE { * version CscaMasterListVersion, * certList SET OF Certificate } - * + * * CscaMasterListVersion :: INTEGER {v0(0)} * </pre> */ -public class CscaMasterList +public class CscaMasterList extends ASN1Object { private ASN1Integer version = new ASN1Integer(0); @@ -38,29 +38,31 @@ public class CscaMasterList } else if (obj != null) { - return new CscaMasterList(ASN1Sequence.getInstance(obj)); + return new CscaMasterList(ASN1Sequence.getInstance(obj)); } return null; - } - + } + private CscaMasterList( ASN1Sequence seq) { if (seq == null || seq.size() == 0) { throw new IllegalArgumentException( - "null or empty sequence passed."); + "null or empty sequence passed."); } - if (seq.size() != 2) { + if (seq.size() != 2) + { throw new IllegalArgumentException( - "Incorrect sequence size: " + seq.size()); + "Incorrect sequence size: " + seq.size()); } - + version = ASN1Integer.getInstance(seq.getObjectAt(0)); ASN1Set certSet = ASN1Set.getInstance(seq.getObjectAt(1)); certList = new Certificate[certSet.size()]; - for (int i = 0; i < certList.length; i++) { + for (int i = 0; i < certList.length; i++) + { certList[i] = Certificate.getInstance(certSet.getObjectAt(i)); } @@ -101,12 +103,12 @@ public class CscaMasterList seq.add(version); ASN1EncodableVector certSet = new ASN1EncodableVector(); - for (int i = 0; i < certList.length; i++) + for (int i = 0; i < certList.length; i++) { certSet.add(certList[i]); - } - seq.add(new DERSet(certSet)); + } + seq.add(new DERSet(certSet)); return new DERSequence(seq); - } + } } diff --git a/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java b/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java index 9886b731..5302552b 100644 --- a/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java +++ b/src/main/java/org/bouncycastle/asn1/util/ASN1Dump.java @@ -184,7 +184,8 @@ public class ASN1Dump { buf.append(dumpBinaryDataAsString(indent, oct.getOctets())); } - else{ + else + { buf.append(nl); } } @@ -208,7 +209,8 @@ public class ASN1Dump { buf.append(dumpBinaryDataAsString(indent, bt.getBytes())); } - else{ + else + { buf.append(nl); } } diff --git a/src/main/java/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java b/src/main/java/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java index a1992827..d250bf1e 100644 --- a/src/main/java/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java +++ b/src/main/java/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java @@ -6,7 +6,6 @@ import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.ASN1Sequence; -import org.bouncycastle.asn1.ASN1SequenceParser; import org.bouncycastle.asn1.ASN1TaggedObject; import org.bouncycastle.asn1.DERNull; import org.bouncycastle.asn1.DERObjectIdentifier; diff --git a/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java b/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java index efdb6bca..802cdf91 100644 --- a/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java +++ b/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java @@ -1,6 +1,8 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; import java.util.Vector; /** diff --git a/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java b/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java index 2c83b48d..9e51fa12 100644 --- a/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java +++ b/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java @@ -1,6 +1,7 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.IOException; +import java.io.OutputStream; import java.util.Enumeration; import java.util.Hashtable; diff --git a/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java b/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java index 393bea34..640310b4 100644 --- a/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java +++ b/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java @@ -1,6 +1,7 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.IOException; +import java.io.OutputStream; /** * Basic output stream. diff --git a/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java b/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java index 4c7730c2..0b400591 100644 --- a/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java +++ b/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java @@ -1,6 +1,6 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.IOException; /** * generic compressed data object. diff --git a/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java b/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java index b0111eaa..fca0078c 100644 --- a/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java +++ b/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java @@ -1,6 +1,7 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; /** * Basic type for a PGP packet. diff --git a/src/main/java/org/bouncycastle/bcpg/S2K.java b/src/main/java/org/bouncycastle/bcpg/S2K.java index 8b775031..167e7155 100644 --- a/src/main/java/org/bouncycastle/bcpg/S2K.java +++ b/src/main/java/org/bouncycastle/bcpg/S2K.java @@ -1,6 +1,8 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; /** * The string to key specifier class diff --git a/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java b/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java index 3c55776b..c44e9eac 100644 --- a/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java +++ b/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java @@ -1,6 +1,7 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.IOException; +import java.io.OutputStream; /** * Basic type for a PGP Signature sub-packet. diff --git a/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java b/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java index 524bfae0..edf6e2ad 100644 --- a/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java +++ b/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java @@ -1,6 +1,6 @@ package org.bouncycastle.bcpg; -import java.io.*; +import java.io.IOException; /** */ diff --git a/src/main/java/org/bouncycastle/bcpg/sig/Features.java b/src/main/java/org/bouncycastle/bcpg/sig/Features.java index 9efd7139..6e309c93 100644 --- a/src/main/java/org/bouncycastle/bcpg/sig/Features.java +++ b/src/main/java/org/bouncycastle/bcpg/sig/Features.java @@ -89,7 +89,7 @@ public class Features System.arraycopy(data, 0, temp, 0, i);
System.arraycopy(data, i + 1, temp, i, temp.length - i);
data = temp;
- i = data.length + 1;
+ break;
}
}
}
diff --git a/src/main/java/org/bouncycastle/crypto/ec/ECNewPublicKeyTransform.java b/src/main/java/org/bouncycastle/crypto/ec/ECNewPublicKeyTransform.java index d7202b4c..32ba0706 100644 --- a/src/main/java/org/bouncycastle/crypto/ec/ECNewPublicKeyTransform.java +++ b/src/main/java/org/bouncycastle/crypto/ec/ECNewPublicKeyTransform.java @@ -6,7 +6,6 @@ import java.security.SecureRandom; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; import org.bouncycastle.crypto.params.ParametersWithRandom; -import org.bouncycastle.math.ec.ECConstants; import org.bouncycastle.math.ec.ECPoint; /** diff --git a/src/main/java/org/bouncycastle/crypto/encodings/OAEPEncoding.java b/src/main/java/org/bouncycastle/crypto/encodings/OAEPEncoding.java index a19a0481..17d8e3b0 100644 --- a/src/main/java/org/bouncycastle/crypto/encodings/OAEPEncoding.java +++ b/src/main/java/org/bouncycastle/crypto/encodings/OAEPEncoding.java @@ -1,14 +1,13 @@ package org.bouncycastle.crypto.encodings; +import java.security.SecureRandom; + import org.bouncycastle.crypto.AsymmetricBlockCipher; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.digests.SHA1Digest; import org.bouncycastle.crypto.params.ParametersWithRandom; -import org.bouncycastle.util.encoders.Hex; - -import java.security.SecureRandom; /** * Optimal Asymmetric Encryption Padding (OAEP) - see PKCS 1 V 2. diff --git a/src/main/java/org/bouncycastle/crypto/signers/ISO9796d2PSSSigner.java b/src/main/java/org/bouncycastle/crypto/signers/ISO9796d2PSSSigner.java index 3296d3c3..e3dcc08e 100644 --- a/src/main/java/org/bouncycastle/crypto/signers/ISO9796d2PSSSigner.java +++ b/src/main/java/org/bouncycastle/crypto/signers/ISO9796d2PSSSigner.java @@ -9,9 +9,6 @@ import org.bouncycastle.crypto.CryptoException; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.SignerWithRecovery; -import org.bouncycastle.crypto.digests.RIPEMD128Digest; -import org.bouncycastle.crypto.digests.RIPEMD160Digest; -import org.bouncycastle.crypto.digests.SHA1Digest; import org.bouncycastle.crypto.params.ParametersWithRandom; import org.bouncycastle.crypto.params.ParametersWithSalt; import org.bouncycastle.crypto.params.RSAKeyParameters; diff --git a/src/main/java/org/bouncycastle/dvcs/CCPDRequestBuilder.java b/src/main/java/org/bouncycastle/dvcs/CCPDRequestBuilder.java index 5e0f106c..d8ed653a 100644 --- a/src/main/java/org/bouncycastle/dvcs/CCPDRequestBuilder.java +++ b/src/main/java/org/bouncycastle/dvcs/CCPDRequestBuilder.java @@ -1,12 +1,8 @@ package org.bouncycastle.dvcs; -import java.io.IOException; - import org.bouncycastle.asn1.dvcs.DVCSRequestInformationBuilder; import org.bouncycastle.asn1.dvcs.Data; import org.bouncycastle.asn1.dvcs.ServiceType; -import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.asn1.x509.DigestInfo; /** * Builder of CCPD requests (Certify Claim of Possession of Data). diff --git a/src/main/java/org/bouncycastle/dvcs/DVCSRequest.java b/src/main/java/org/bouncycastle/dvcs/DVCSRequest.java index d09d0b30..b82f1f17 100644 --- a/src/main/java/org/bouncycastle/dvcs/DVCSRequest.java +++ b/src/main/java/org/bouncycastle/dvcs/DVCSRequest.java @@ -1,7 +1,5 @@ package org.bouncycastle.dvcs; -import java.io.IOException; - import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.ASN1Sequence; diff --git a/src/main/java/org/bouncycastle/dvcs/MessageImprint.java b/src/main/java/org/bouncycastle/dvcs/MessageImprint.java index 66cbba67..5f4fbc12 100644 --- a/src/main/java/org/bouncycastle/dvcs/MessageImprint.java +++ b/src/main/java/org/bouncycastle/dvcs/MessageImprint.java @@ -30,4 +30,9 @@ public class MessageImprint return false; } + + public int hashCode() + { + return messageImprint.hashCode(); + } } diff --git a/src/main/java/org/bouncycastle/dvcs/VPKCRequestData.java b/src/main/java/org/bouncycastle/dvcs/VPKCRequestData.java index 2b67fb3f..9624ef7f 100644 --- a/src/main/java/org/bouncycastle/dvcs/VPKCRequestData.java +++ b/src/main/java/org/bouncycastle/dvcs/VPKCRequestData.java @@ -1,7 +1,6 @@ package org.bouncycastle.dvcs; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; diff --git a/src/main/java/org/bouncycastle/eac/operator/jcajce/JcaEACSignerBuilder.java b/src/main/java/org/bouncycastle/eac/operator/jcajce/JcaEACSignerBuilder.java index 4e3ab4f5..380ec143 100644 --- a/src/main/java/org/bouncycastle/eac/operator/jcajce/JcaEACSignerBuilder.java +++ b/src/main/java/org/bouncycastle/eac/operator/jcajce/JcaEACSignerBuilder.java @@ -152,16 +152,18 @@ public class JcaEACSignerBuilder return ret; } - private static int unsignedIntLength(byte [] i) + private static int unsignedIntLength(byte[] i) { int len = i.length; if (i[0] == 0) + { len--; + } return len; } - private static void copyUnsignedInt(byte [] src, byte [] dst, int offset) + private static void copyUnsignedInt(byte[] src, byte[] dst, int offset) { int len = src.length; int readoffset = 0; diff --git a/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dh/IESCipher.java b/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dh/IESCipher.java index 4df65812..c29ff2dc 100644 --- a/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dh/IESCipher.java +++ b/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dh/IESCipher.java @@ -53,14 +53,14 @@ import org.bouncycastle.util.Strings; public class IESCipher extends CipherSpi { - private IESEngine engine; - private int state = -1; - private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - private AlgorithmParameters engineParam = null; - private IESParameterSpec engineSpec = null; - private AsymmetricKeyParameter key; - private SecureRandom random; - private boolean dhaesMode = false; + private IESEngine engine; + private int state = -1; + private ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + private AlgorithmParameters engineParam = null; + private IESParameterSpec engineSpec = null; + private AsymmetricKeyParameter key; + private SecureRandom random; + private boolean dhaesMode = false; private AsymmetricKeyParameter otherKeyParameter = null; public IESCipher(IESEngine engine) @@ -69,24 +69,24 @@ public class IESCipher } - public int engineGetBlockSize() + public int engineGetBlockSize() { if (engine.getCipher() != null) { return engine.getCipher().getBlockSize(); } - else + else { return 0; } } - public int engineGetKeySize(Key key) + public int engineGetKeySize(Key key) { if (key instanceof DHKey) { - return ((DHKey) key).getParams().getP().bitLength(); + return ((DHKey)key).getParams().getP().bitLength(); } else { @@ -95,22 +95,24 @@ public class IESCipher } - public byte[] engineGetIV() + public byte[] engineGetIV() { return null; } - public AlgorithmParameters engineGetParameters() + public AlgorithmParameters engineGetParameters() { if (engineParam == null && engineSpec != null) - try { + try + { engineParam = AlgorithmParameters.getInstance("IES", BouncyCastleProvider.PROVIDER_NAME); engineParam.init(engineSpec); - } - catch (Exception e) - { - throw new RuntimeException(e.toString()); + } + catch (Exception e) + { + throw new RuntimeException(e.toString()); + } } return engineParam; @@ -118,33 +120,33 @@ public class IESCipher public void engineSetMode(String mode) - throws NoSuchAlgorithmException - { - String modeName = Strings.toUpperCase(mode); + throws NoSuchAlgorithmException + { + String modeName = Strings.toUpperCase(mode); - if (modeName.equals("NONE")) - { + if (modeName.equals("NONE")) + { dhaesMode = false; - } - else if (modeName.equals("DHAES")) - { - dhaesMode = true; - } - else - { - throw new IllegalArgumentException("can't support mode " + mode); - } - } - - public int engineGetOutputSize(int inputLen) - { + } + else if (modeName.equals("DHAES")) + { + dhaesMode = true; + } + else + { + throw new IllegalArgumentException("can't support mode " + mode); + } + } + + public int engineGetOutputSize(int inputLen) + { int len1, len2, len3; len1 = engine.getMac().getMacSize(); if (key != null) { - len2 = ((DHKey) key).getParams().getP().bitLength()/8+1; + len2 = ((DHKey)key).getParams().getP().bitLength() / 8 + 1; } else { @@ -161,7 +163,7 @@ public class IESCipher } else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE) { - len3 = engine.getCipher().getOutputSize(inputLen - len1 -len2); + len3 = engine.getCipher().getOutputSize(inputLen - len1 - len2); } else { @@ -184,41 +186,41 @@ public class IESCipher } public void engineSetPadding(String padding) - throws NoSuchPaddingException - { - String paddingName = Strings.toUpperCase(padding); + throws NoSuchPaddingException + { + String paddingName = Strings.toUpperCase(padding); - // TDOD: make this meaningful... - if (paddingName.equals("NOPADDING")) - { + // TDOD: make this meaningful... + if (paddingName.equals("NOPADDING")) + { - } - else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING")) - { + } + else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING")) + { - } - else - { - throw new NoSuchPaddingException("padding not available with IESCipher"); - } - } + } + else + { + throw new NoSuchPaddingException("padding not available with IESCipher"); + } + } // Initialisation methods - + public void engineInit( - int opmode, - Key key, - AlgorithmParameters params, - SecureRandom random) - throws InvalidKeyException, InvalidAlgorithmParameterException + int opmode, + Key key, + AlgorithmParameters params, + SecureRandom random) + throws InvalidKeyException, InvalidAlgorithmParameterException { - AlgorithmParameterSpec paramSpec = null; + AlgorithmParameterSpec paramSpec = null; if (params != null) { try { - paramSpec = params.getParameterSpec(IESParameterSpec.class); + paramSpec = params.getParameterSpec(IESParameterSpec.class); } catch (Exception e) { @@ -226,17 +228,17 @@ public class IESCipher } } - engineParam = params; + engineParam = params; engineInit(opmode, key, paramSpec, random); } - + public void engineInit( - int opmode, - Key key, - AlgorithmParameterSpec engineSpec, - SecureRandom random) - throws InvalidAlgorithmParameterException, InvalidKeyException + int opmode, + Key key, + AlgorithmParameterSpec engineSpec, + SecureRandom random) + throws InvalidAlgorithmParameterException, InvalidKeyException { // Use default parameters (including cipher key size) if none are specified if (engineSpec == null) @@ -247,7 +249,7 @@ public class IESCipher { this.engineSpec = (IESParameterSpec)engineSpec; } - else + else { throw new InvalidAlgorithmParameterException("must be passed IES parameters"); } @@ -257,7 +259,7 @@ public class IESCipher { if (key instanceof DHPublicKey) { - this.key = DHUtil.generatePublicKeyParameter((PublicKey) key); + this.key = DHUtil.generatePublicKeyParameter((PublicKey)key); } else if (key instanceof IESKey) { @@ -275,7 +277,7 @@ public class IESCipher { if (key instanceof DHPrivateKey) { - this.key = DHUtil.generatePrivateKeyParameter((PrivateKey) key); + this.key = DHUtil.generatePrivateKeyParameter((PrivateKey)key); } else if (key instanceof IESKey) { @@ -291,7 +293,7 @@ public class IESCipher } else { - throw new InvalidKeyException("must be passed EC key"); + throw new InvalidKeyException("must be passed EC key"); } this.random = random; @@ -302,14 +304,14 @@ public class IESCipher public void engineInit( - int opmode, - Key key, - SecureRandom random) - throws InvalidKeyException - { + int opmode, + Key key, + SecureRandom random) + throws InvalidKeyException + { try { - engineInit(opmode, key, (AlgorithmParameterSpec) null, random); + engineInit(opmode, key, (AlgorithmParameterSpec)null, random); } catch (InvalidAlgorithmParameterException e) { @@ -318,13 +320,13 @@ public class IESCipher } - + // Update methods - buffer the input public byte[] engineUpdate( - byte[] input, - int inputOffset, - int inputLen) + byte[] input, + int inputOffset, + int inputLen) { buffer.write(input, inputOffset, inputLen); return null; @@ -332,11 +334,11 @@ public class IESCipher public int engineUpdate( - byte[] input, - int inputOffset, - int inputLen, - byte[] output, - int outputOffset) + byte[] input, + int inputOffset, + int inputLen, + byte[] output, + int outputOffset) { buffer.write(input, inputOffset, inputLen); return 0; @@ -344,12 +346,12 @@ public class IESCipher // Finalisation methods - + public byte[] engineDoFinal( - byte[] input, - int inputOffset, - int inputLen) - throws IllegalBlockSizeException, BadPaddingException + byte[] input, + int inputOffset, + int inputLen) + throws IllegalBlockSizeException, BadPaddingException { if (inputLen != 0) { @@ -361,11 +363,11 @@ public class IESCipher // Convert parameters for use in IESEngine IESParameters params = new IESWithCipherParameters(engineSpec.getDerivationV(), - engineSpec.getEncodingV(), - engineSpec.getMacKeySize(), - engineSpec.getCipherKeySize()); + engineSpec.getEncodingV(), + engineSpec.getMacKeySize(), + engineSpec.getCipherKeySize()); - DHParameters dhParams = ((DHKeyParameters) key).getParameters(); + DHParameters dhParams = ((DHKeyParameters)key).getParameters(); byte[] V; if (otherKeyParameter != null) @@ -435,7 +437,7 @@ public class IESCipher return engine.processBlock(in, 0, in.length); } - catch(InvalidCipherTextException e) + catch (InvalidCipherTextException e) { throw new BadPaddingException(e.getMessage()); } @@ -449,12 +451,12 @@ public class IESCipher public int engineDoFinal( - byte[] input, - int inputOffset, - int inputLength, - byte[] output, - int outputOffset) - throws ShortBufferException, IllegalBlockSizeException, BadPaddingException + byte[] input, + int inputOffset, + int inputLength, + byte[] output, + int outputOffset) + throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { byte[] buf = engineDoFinal(input, inputOffset, inputLength); @@ -469,13 +471,13 @@ public class IESCipher */ static public class IES - extends IESCipher + extends IESCipher { public IES() { - super(new IESEngine(new DHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()))); + super(new IESEngine(new DHBasicAgreement(), + new KDF2BytesGenerator(new SHA1Digest()), + new HMac(new SHA1Digest()))); } } @@ -485,21 +487,21 @@ public class IESCipher public IESwithDESede() { super(new IESEngine(new DHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - new PaddedBufferedBlockCipher(new DESedeEngine()))); + new KDF2BytesGenerator(new SHA1Digest()), + new HMac(new SHA1Digest()), + new PaddedBufferedBlockCipher(new DESedeEngine()))); } } static public class IESwithAES - extends IESCipher + extends IESCipher { public IESwithAES() { - super(new IESEngine(new DHBasicAgreement(), - new KDF2BytesGenerator(new SHA1Digest()), - new HMac(new SHA1Digest()), - new PaddedBufferedBlockCipher(new AESEngine()))); + super(new IESEngine(new DHBasicAgreement(), + new KDF2BytesGenerator(new SHA1Digest()), + new HMac(new SHA1Digest()), + new PaddedBufferedBlockCipher(new AESEngine()))); } } } diff --git a/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dsa/AlgorithmParametersSpi.java b/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dsa/AlgorithmParametersSpi.java index 1ddb8157..61fa33c6 100644 --- a/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dsa/AlgorithmParametersSpi.java +++ b/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/dsa/AlgorithmParametersSpi.java @@ -7,7 +7,6 @@ import java.security.spec.InvalidParameterSpecException; import org.bouncycastle.asn1.ASN1Encoding; import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.x509.DSAParameter; public class AlgorithmParametersSpi diff --git a/src/main/java/org/bouncycastle/jcajce/provider/digest/SHA256.java b/src/main/java/org/bouncycastle/jcajce/provider/digest/SHA256.java index 00eae136..785cf655 100644 --- a/src/main/java/org/bouncycastle/jcajce/provider/digest/SHA256.java +++ b/src/main/java/org/bouncycastle/jcajce/provider/digest/SHA256.java @@ -1,7 +1,6 @@ package org.bouncycastle.jcajce.provider.digest; import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; -import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.crypto.CipherKeyGenerator; import org.bouncycastle.crypto.digests.SHA256Digest; diff --git a/src/main/java/org/bouncycastle/pkcs/PKCS12PfxPdu.java b/src/main/java/org/bouncycastle/pkcs/PKCS12PfxPdu.java index 81fdb7f5..e39025be 100644 --- a/src/main/java/org/bouncycastle/pkcs/PKCS12PfxPdu.java +++ b/src/main/java/org/bouncycastle/pkcs/PKCS12PfxPdu.java @@ -2,7 +2,6 @@ package org.bouncycastle.pkcs; import java.io.IOException; -import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.ASN1Sequence; diff --git a/src/main/java/org/bouncycastle/pkcs/bc/BcPKCS12MacCalculatorBuilderProvider.java b/src/main/java/org/bouncycastle/pkcs/bc/BcPKCS12MacCalculatorBuilderProvider.java index 2d07cd1e..d6f92306 100644 --- a/src/main/java/org/bouncycastle/pkcs/bc/BcPKCS12MacCalculatorBuilderProvider.java +++ b/src/main/java/org/bouncycastle/pkcs/bc/BcPKCS12MacCalculatorBuilderProvider.java @@ -1,12 +1,8 @@ package org.bouncycastle.pkcs.bc; import org.bouncycastle.asn1.DERNull; -import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.crypto.ExtendedDigest; -import org.bouncycastle.crypto.digests.SHA1Digest; -import org.bouncycastle.operator.DigestCalculatorProvider; import org.bouncycastle.operator.MacCalculator; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.bc.BcDigestProvider; diff --git a/src/main/java/org/bouncycastle/pkcs/jcajce/JcePKCSPBEInputDecryptorProviderBuilder.java b/src/main/java/org/bouncycastle/pkcs/jcajce/JcePKCSPBEInputDecryptorProviderBuilder.java index 0210e8cc..79ab492f 100644 --- a/src/main/java/org/bouncycastle/pkcs/jcajce/JcePKCSPBEInputDecryptorProviderBuilder.java +++ b/src/main/java/org/bouncycastle/pkcs/jcajce/JcePKCSPBEInputDecryptorProviderBuilder.java @@ -2,7 +2,6 @@ package org.bouncycastle.pkcs.jcajce; import java.io.InputStream; import java.security.Provider; -import java.util.Map; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; diff --git a/src/main/java/org/bouncycastle/pqc/asn1/GMSSPrivateKey.java b/src/main/java/org/bouncycastle/pqc/asn1/GMSSPrivateKey.java index f317dc75..4e182c59 100644 --- a/src/main/java/org/bouncycastle/pqc/asn1/GMSSPrivateKey.java +++ b/src/main/java/org/bouncycastle/pqc/asn1/GMSSPrivateKey.java @@ -9,11 +9,9 @@ import org.bouncycastle.asn1.ASN1Integer; import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.ASN1Sequence; -import org.bouncycastle.asn1.DERIA5String; import org.bouncycastle.asn1.DEROctetString; import org.bouncycastle.asn1.DERSequence; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.crypto.Digest; import org.bouncycastle.pqc.crypto.gmss.GMSSLeaf; import org.bouncycastle.pqc.crypto.gmss.GMSSParameters; import org.bouncycastle.pqc.crypto.gmss.GMSSRootCalc; diff --git a/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java b/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java index 79113e4a..77ed63a2 100644 --- a/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java +++ b/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java @@ -7,31 +7,37 @@ import org.bouncycastle.crypto.Digest; /** * An implementation of the deterministic pseudo-random generator in EESS section 3.7.3.1 */ -public class NTRUSignerPrng { +public class NTRUSignerPrng +{ private int counter; private byte[] seed; private Digest hashAlg; - + /** * Constructs a new PRNG and seeds it with a byte array. - * @param seed a seed + * + * @param seed a seed * @param hashAlg the hash algorithm to use */ - NTRUSignerPrng(byte[] seed, Digest hashAlg) { + NTRUSignerPrng(byte[] seed, Digest hashAlg) + { counter = 0; this.seed = seed; this.hashAlg = hashAlg; } - + /** * Returns <code>n</code> random bytes + * * @param n number of bytes to return * @return the next <code>n</code> random bytes */ - byte[] nextBytes(int n) { + byte[] nextBytes(int n) + { ByteBuffer buf = ByteBuffer.allocate(n); - - while (buf.hasRemaining()) { + + while (buf.hasRemaining()) + { ByteBuffer cbuf = ByteBuffer.allocate(seed.length + 4); cbuf.put(seed); cbuf.putInt(counter); @@ -43,12 +49,16 @@ public class NTRUSignerPrng { hashAlg.doFinal(hash, 0); if (buf.remaining() < hash.length) + { buf.put(hash, 0, buf.remaining()); + } else + { buf.put(hash); + } counter++; } - + return buf.array(); } }
\ No newline at end of file diff --git a/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSigningPublicKeyParameters.java b/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSigningPublicKeyParameters.java index 70722cd8..be51d0af 100644 --- a/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSigningPublicKeyParameters.java +++ b/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSigningPublicKeyParameters.java @@ -18,58 +18,70 @@ public class NTRUSigningPublicKeyParameters /** * Constructs a new public key from a polynomial - * @param h the polynomial <code>h</code> which determines the key + * + * @param h the polynomial <code>h</code> which determines the key * @param params the NtruSign parameters to use */ - public NTRUSigningPublicKeyParameters(IntegerPolynomial h, NTRUSigningParameters params) { + public NTRUSigningPublicKeyParameters(IntegerPolynomial h, NTRUSigningParameters params) + { super(false); this.h = h; this.params = params; } - + /** * Converts a byte array to a polynomial <code>h</code> and constructs a new public key - * @param b an encoded polynomial + * + * @param b an encoded polynomial * @param params the NtruSign parameters to use */ - public NTRUSigningPublicKeyParameters(byte[] b, NTRUSigningParameters params) { + public NTRUSigningPublicKeyParameters(byte[] b, NTRUSigningParameters params) + { super(false); h = IntegerPolynomial.fromBinary(b, params.N, params.q); this.params = params; } - + /** * Reads a polynomial <code>h</code> from an input stream and constructs a new public key - * @param is an input stream + * + * @param is an input stream * @param params the NtruSign parameters to use */ - public NTRUSigningPublicKeyParameters(InputStream is, NTRUSigningParameters params) throws IOException { + public NTRUSigningPublicKeyParameters(InputStream is, NTRUSigningParameters params) + throws IOException + { super(false); h = IntegerPolynomial.fromBinary(is, params.N, params.q); this.params = params; } - /** * Converts the key to a byte array + * * @return the encoded key */ - public byte[] getEncoded() { + public byte[] getEncoded() + { return h.toBinary(params.q); } - + /** * Writes the key to an output stream + * * @param os an output stream * @throws IOException */ - public void writeTo(OutputStream os) throws IOException { + public void writeTo(OutputStream os) + throws IOException + { os.write(getEncoded()); } @Override - public int hashCode() { + public int hashCode() + { final int prime = 31; int result = 1; result = prime * result + ((h == null) ? 0 : h.hashCode()); @@ -78,24 +90,43 @@ public class NTRUSigningPublicKeyParameters } @Override - public boolean equals(Object obj) { + public boolean equals(Object obj) + { if (this == obj) + { return true; + } if (obj == null) + { return false; + } if (getClass() != obj.getClass()) + { return false; - NTRUSigningPublicKeyParameters other = (NTRUSigningPublicKeyParameters) obj; - if (h == null) { + } + NTRUSigningPublicKeyParameters other = (NTRUSigningPublicKeyParameters)obj; + if (h == null) + { if (other.h != null) + { return false; - } else if (!h.equals(other.h)) + } + } + else if (!h.equals(other.h)) + { return false; - if (params == null) { + } + if (params == null) + { if (other.params != null) + { return false; - } else if (!params.equals(other.params)) + } + } + else if (!params.equals(other.params)) + { return false; + } return true; } }
\ No newline at end of file |